Skip to content
This repository was archived by the owner on Apr 7, 2021. It is now read-only.

Commit 28cd0c9

Browse files
committed
add new request
1 parent 10e9422 commit 28cd0c9

File tree

22 files changed

+271
-186
lines changed

22 files changed

+271
-186
lines changed

demo/main.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
33
import FileManager from '@/init'
4-
import request from './request'
4+
import buildRequest from './request'
55
import App from './App'
66
import setBrowserHelpers from './browser.helpers'
77

@@ -14,9 +14,14 @@ const store = new Vuex.Store({
1414

1515
Vue.config.productionTip = process.env.NODE_ENV === 'production'
1616

17-
Vue.prototype.$request = request(store)
17+
const request = buildRequest(store, 'api')
18+
request.baseLayerForFM = 'api'
1819

19-
Vue.use(FileManager, { store })
20+
// Vue.prototype.$request = request(store, 'api')
21+
// Vue.prototype.$request.baseLayerForFM = 'api'
22+
// console.log(Vue.prototype.$request)
23+
24+
Vue.use(FileManager, { store, request })
2025
setBrowserHelpers()
2126

2227
new Vue({

demo/request/index.js

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
1-
import buildBaseRequest from '@feugene/request'
2-
import { isObject } from '@feugene/mu/src/is'
1+
import buildRequest from '@feugene/layer-request'
2+
import WrapperInterceptor from '@feugene/request-interceptors/src/response/WrapperInterceptor'
3+
import { ActionInterceptorBuild } from '@feugene/request-interceptors/src/response/ActionInterceptor'
34

4-
const baseHost = process.env.VUE_APP_HOST
5-
const apiPrefix = process.env.VUE_APP_API_PREFIX
5+
const apiHost = process.env.VUE_APP_API_PREFIX || '/api'
66

7-
function initHeaders() {
8-
return {
9-
'X-Requested-With': 'XMLHttpRequest',
10-
}
11-
}
12-
13-
const request = store => (config = {}) => {
14-
const headers = {
15-
...initHeaders(),
16-
...(isObject(config.headers) ? config.headers : {}),
17-
}
18-
19-
const mergedConfig = {
20-
baseURL: `${baseHost}${apiPrefix}`,
21-
...config,
22-
headers,
23-
}
7+
export const createRequest = (store, nameLayer) => {
8+
const request = buildRequest({ extra: { store } })
249

25-
mergedConfig.store = store
10+
request.manager.addLayer(cm => {
11+
return cm.new({
12+
requestConfig: {
13+
headers: {
14+
'X-Requested-With': 'XMLHttpRequest',
15+
},
16+
baseURL: apiHost,
17+
},
18+
interceptors: {
19+
request: [
20+
// eslint-disable-next-line unicorn/consistent-function-scoping
21+
() => rConfig => {
22+
console.info(`\t🌐 ${rConfig.baseURL}${rConfig.url}`)
23+
return rConfig
24+
},
25+
],
26+
response: [
27+
// eslint-disable-next-line unicorn/consistent-function-scoping
28+
() => response => {
29+
console.info(`\t✅ ${response.request.responseURL}`)
30+
return response
31+
},
32+
WrapperInterceptor(),
33+
ActionInterceptorBuild({
34+
actionAttributeName: 'status',
35+
}),
36+
],
37+
},
38+
})
39+
}, nameLayer)
2640

27-
return buildBaseRequest(mergedConfig)
41+
return request
2842
}
2943

30-
export default request
44+
export default createRequest

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,29 @@
2424
"vue-codemirror": "^4.0.6"
2525
},
2626
"peerDependencies": {
27-
"@feugene/mu": "^2.20.1",
28-
"@feugene/request": "^0.1.2",
27+
"@feugene/mu": "^2.21.0",
28+
"@feugene/layer-request": "^0.1.3",
29+
"@feugene/request-interceptors": "^0.0.6",
2930
"axios": "^0.21.1",
30-
"core-js": "^3.9.0",
31+
"core-js": "^3.10.0",
3132
"element-ui": "^2.15.1",
3233
"vue": "^2.6.12",
3334
"vuex": "^3.6.2"
3435
},
3536
"devDependencies": {
3637
"@babel/plugin-proposal-optional-chaining": "^7.13.0",
3738
"@babel/plugin-transform-runtime": "^7.13.5",
38-
"@feugene/mu": "^2.20.4",
39-
"@feugene/request": "^0.1.2",
39+
"@feugene/mu": "^2.21.0",
40+
"@feugene/layer-request": "^0.1.3",
41+
"@feugene/request-interceptors": "^0.0.6",
4042
"@vue/cli-plugin-babel": "~4.5.11",
4143
"@vue/cli-plugin-eslint": "~4.5.11",
4244
"@vue/cli-service": "~4.5.11",
4345
"@vue/eslint-config-airbnb": "^5.3.0",
4446
"axios": "^0.21.1",
4547
"babel-eslint": "^10.1.0",
4648
"babel-plugin-component": "^1.1.1",
47-
"core-js": "^3.9.0",
49+
"core-js": "^3.10.0",
4850
"element-ui": "^2.15.1",
4951
"eslint": "7.20.0",
5052
"eslint-config-prettier": "^8.0.0",
@@ -61,10 +63,10 @@
6163
"vue-template-compiler": "^2.6.12",
6264
"vuex": "^3.6.2",
6365

64-
"@rollup/plugin-commonjs": "^17.1.0",
65-
"@rollup/plugin-node-resolve": "^11.2.0",
66-
"@rollup/plugin-replace": "^2.4.1",
67-
"rollup": "^2.41.0",
66+
"@rollup/plugin-commonjs": "^18.0.0",
67+
"@rollup/plugin-node-resolve": "^11.2.1",
68+
"@rollup/plugin-replace": "^2.4.2",
69+
"rollup": "^2.44.0",
6870
"rollup-plugin-vue": "^6.0.0"
6971
}
7072
}

src/FileManager.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
</template>
3535

3636
<script>
37-
import './plugins'
37+
// import './plugins'
3838
/* eslint-disable import/no-duplicates, no-param-reassign */
3939
import { mapState } from 'vuex'
40-
// import {request} from './utils/request'
40+
4141
import EventBus from './eventBus'
4242
// Components
4343
import Navbar from './components/blocks/Navbar.vue'
@@ -107,7 +107,7 @@ export default {
107107
this.$store.dispatch('fm/resetState')
108108
109109
// delete events
110-
EventBus.$off(['contextMenu', 'addNotification'])
110+
EventBus().$off(['contextMenu', 'addNotification'])
111111
},
112112
computed: {
113113
...mapState('fm', {

src/components/blocks/ContextMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default {
4646
* Listen events
4747
* 'contextMenu'
4848
*/
49-
EventBus.$on('contextMenu', event => this.showMenu(event))
49+
EventBus().$on('contextMenu', event => this.showMenu(event))
5050
},
5151
computed: {
5252
/**

src/components/blocks/Navbar.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ export default {
236236
237237
// show notification
238238
if (type === 'cut') {
239-
EventBus.$emit('addNotification', {
239+
EventBus().$emit('addNotification', {
240240
status: 'success',
241241
message: this.lang.notifications.cutToClipboard,
242242
})
243243
} else if (type === 'copy') {
244-
EventBus.$emit('addNotification', {
244+
EventBus().$emit('addNotification', {
245245
status: 'success',
246246
message: this.lang.notifications.copyToClipboard,
247247
})

src/components/blocks/Notification.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
/**
2929
* Listen 'addNotification' events
3030
*/
31-
EventBus.$on('addNotification', ({ status, message }) => this.addNotification(status, message))
31+
EventBus().$on('addNotification', ({ status, message }) => this.addNotification(status, message))
3232
},
3333
methods: {
3434
/**

src/components/manager/mixins/manager.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export default {
136136
}
137137

138138
// create event
139-
EventBus.$emit('contextMenu', event)
139+
EventBus().$emit('contextMenu', event)
140140
},
141141

142142
/**
@@ -147,14 +147,16 @@ export default {
147147
selectAction(path, extension) {
148148
// if is set fileCallback
149149
if (this.$store.state.fm.fileCallback) {
150-
this.$store.dispatch('fm/url', {
151-
disk: this.selectedDisk,
152-
path,
153-
}).then((response) => {
154-
if (response.data.result.status === 'success') {
155-
this.$store.state.fm.fileCallback(response.data.url)
156-
}
157-
})
150+
this.$store
151+
.dispatch('fm/url', {
152+
disk: this.selectedDisk,
153+
path,
154+
})
155+
.then(response => {
156+
if (response.data.result.status === 'success') {
157+
this.$store.state.fm.fileCallback(response.data.url)
158+
}
159+
})
158160

159161
return
160162
}
@@ -165,29 +167,25 @@ export default {
165167
}
166168

167169
// show, play..
168-
if (this.$store.state.fm.settings.imageExtensions
169-
.includes(extension.toLowerCase())) {
170+
if (this.$store.state.fm.settings.imageExtensions.includes(extension.toLowerCase())) {
170171
// show image
171172
this.$store.commit('fm/modal/setModalState', {
172173
modalName: 'Preview',
173174
show: true,
174175
})
175-
} else if (Object.keys(this.$store.state.fm.settings.textExtensions)
176-
.includes(extension.toLowerCase())) {
176+
} else if (Object.keys(this.$store.state.fm.settings.textExtensions).includes(extension.toLowerCase())) {
177177
// show text file
178178
this.$store.commit('fm/modal/setModalState', {
179179
modalName: 'TextEdit',
180180
show: true,
181181
})
182-
} else if (this.$store.state.fm.settings.audioExtensions
183-
.includes(extension.toLowerCase())) {
182+
} else if (this.$store.state.fm.settings.audioExtensions.includes(extension.toLowerCase())) {
184183
// show player modal
185184
this.$store.commit('fm/modal/setModalState', {
186185
modalName: 'AudioPlayer',
187186
show: true,
188187
})
189-
} else if (this.$store.state.fm.settings.videoExtensions
190-
.includes(extension.toLowerCase())) {
188+
} else if (this.$store.state.fm.settings.videoExtensions.includes(extension.toLowerCase())) {
191189
// show player modal
192190
this.$store.commit('fm/modal/setModalState', {
193191
modalName: 'VideoPlayer',

src/components/modals/views/Properties.vue

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,51 @@
1111
<div class="col-2">{{ lang.modal.properties.disk }}:</div>
1212
<div class="col-9">{{ selectedDisk }}</div>
1313
<div class="col-1 text-right">
14-
<i v-on:click="copyToClipboard(selectedDisk)"
15-
v-bind:title="lang.clipboard.copy"
16-
class="far fa-copy"/>
14+
<i v-on:click="copyToClipboard(selectedDisk)" v-bind:title="lang.clipboard.copy" class="far fa-copy" />
1715
</div>
1816
</div>
1917
<div class="row">
2018
<div class="col-2">{{ lang.modal.properties.name }}:</div>
2119
<div class="col-9">{{ selectedItem.basename }}</div>
2220
<div class="col-1 text-right">
23-
<i v-on:click="copyToClipboard(selectedItem.basename)"
24-
v-bind:title="lang.clipboard.copy"
25-
class="far fa-copy"/>
21+
<i
22+
v-on:click="copyToClipboard(selectedItem.basename)"
23+
v-bind:title="lang.clipboard.copy"
24+
class="far fa-copy"
25+
/>
2626
</div>
2727
</div>
2828
<div class="row">
2929
<div class="col-2">{{ lang.modal.properties.path }}:</div>
3030
<div class="col-9">{{ selectedItem.path }}</div>
3131
<div class="col-1 text-right">
32-
<i v-on:click="copyToClipboard(selectedItem.path)"
33-
v-bind:title="lang.clipboard.copy"
34-
class="far fa-copy"/>
32+
<i v-on:click="copyToClipboard(selectedItem.path)" v-bind:title="lang.clipboard.copy" class="far fa-copy" />
3533
</div>
3634
</div>
3735
<template v-if="selectedItem.type === 'file'">
3836
<div class="row">
3937
<div class="col-2">{{ lang.modal.properties.size }}:</div>
4038
<div class="col-9">{{ bytesToHuman(selectedItem.size) }}</div>
4139
<div class="col-1 text-right">
42-
<i v-on:click="copyToClipboard(bytesToHuman(selectedItem.size))"
43-
v-bind:title="lang.clipboard.copy"
44-
class="far fa-copy"/>
40+
<i
41+
v-on:click="copyToClipboard(bytesToHuman(selectedItem.size))"
42+
v-bind:title="lang.clipboard.copy"
43+
class="far fa-copy"
44+
/>
4545
</div>
4646
</div>
4747
<div class="row">
4848
<div class="col-2">{{ lang.modal.properties.url }}:</div>
4949
<div class="col-9">
5050
<span v-if="url">{{ url }}</span>
5151
<span v-else>
52-
<button v-on:click="getUrl" type="button"
53-
class="btn btn-sm btn-light">
54-
<i class="fas fa-sm fa-link"/> Get URL
55-
</button>
56-
</span>
52+
<button v-on:click="getUrl" type="button" class="btn btn-sm btn-light">
53+
<i class="fas fa-sm fa-link" /> Get URL
54+
</button>
55+
</span>
5756
</div>
5857
<div v-if="url" class="col-1 text-right">
59-
<i v-on:click="copyToClipboard(url)"
60-
v-bind:title="lang.clipboard.copy"
61-
class="far fa-copy"/>
58+
<i v-on:click="copyToClipboard(url)" v-bind:title="lang.clipboard.copy" class="far fa-copy" />
6259
</div>
6360
</div>
6461
</template>
@@ -67,9 +64,11 @@
6764
<div class="col-2">{{ lang.modal.properties.modified }}:</div>
6865
<div class="col-9">{{ timestampToDate(selectedItem.timestamp) }}</div>
6966
<div class="col-1 text-right">
70-
<i v-on:click="copyToClipboard(timestampToDate(selectedItem.timestamp))"
71-
v-bind:title="lang.clipboard.copy"
72-
class="far fa-copy"/>
67+
<i
68+
v-on:click="copyToClipboard(timestampToDate(selectedItem.timestamp))"
69+
v-bind:title="lang.clipboard.copy"
70+
class="far fa-copy"
71+
/>
7372
</div>
7473
</div>
7574
</template>
@@ -119,12 +118,14 @@ export default {
119118
* Get URL
120119
*/
121120
getUrl() {
122-
this.$store.dispatch('fm/url', {
123-
disk: this.selectedDisk,
124-
path: this.selectedItem.path,
125-
}).then((response) => {
126-
this.url = response.data('url')
127-
})
121+
this.$store
122+
.dispatch('fm/url', {
123+
disk: this.selectedDisk,
124+
path: this.selectedItem.path,
125+
})
126+
.then(response => {
127+
this.url = response.data('url')
128+
})
128129
},
129130
130131
/**
@@ -145,7 +146,7 @@ export default {
145146
document.body.removeChild(copyInputHelper)
146147
147148
// Notification
148-
EventBus.$emit('addNotification', {
149+
EventBus().$emit('addNotification', {
149150
status: 'success',
150151
message: this.lang.notifications.copyToClipboard,
151152
})

0 commit comments

Comments
 (0)