mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-29 18:00:51 +01:00
added file management
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user