added file management

This commit is contained in:
Marvin Zhang
2019-07-24 13:37:03 +08:00
parent 0a47f3cc0c
commit b01d265060
13 changed files with 293 additions and 64 deletions

View File

@@ -2,7 +2,8 @@ import request from '../../api/request'
const state = {
currentPath: '',
fileList: []
fileList: [],
fileContent: ''
}
const getters = {}
@@ -13,33 +14,34 @@ const mutations = {
},
SET_FILE_LIST (state, value) {
state.fileList = value
},
SET_FILE_CONTENT (state, value) {
state.fileContent = value
}
}
const actions = {
getFileList ({ commit }, path) {
getFileList ({ commit, rootState }, payload) {
const { path } = payload
const spiderId = rootState.spider.spiderForm._id
commit('SET_CURRENT_PATH', path)
request.get('/files', { path })
request.get(`/spiders/${spiderId}/dir`, { path })
.then(response => {
let list = []
list = list.concat(response.data.folders.map(d => {
return { path: d, type: 2 }
}))
list = list.concat(response.data.files.map(d => {
return { path: d, type: 1 }
}))
commit('SET_FILE_LIST', list)
commit(
'SET_FILE_LIST',
response.data.data
.sort((a, b) => a.name > b.name ? -1 : 1)
.sort((a, b) => a.is_dir > b.is_dir ? -1 : 1)
)
})
},
getDefaultPath ({ commit }) {
return new Promise((resolve, reject) => {
request.get('/files/getDefaultPath')
.then(response => {
commit('SET_CURRENT_PATH', response.data.defaultPath)
resolve(response.data.defaultPath)
})
.catch(reject)
})
getFileContent ({ commit, rootState }, payload) {
const { path } = payload
const spiderId = rootState.spider.spiderForm._id
request.get(`/spiders/${spiderId}/file`, { path })
.then(response => {
commit('SET_FILE_CONTENT', response.data.data)
})
}
}

View File

@@ -117,6 +117,13 @@ const actions = {
{ root: true })
})
},
getDir ({ state, commit }, path) {
const id = state.spiderForm._id
return request.get(`/spiders/${id}/dir`)
.then(response => {
commit('')
})
},
importGithub ({ state }) {
const url = state.importForm.url
return request.post('/spiders/import/github', { url })