Files
crawlab/frontend/src/store/modules/file.js
yaziming aeaa4493a7 * 增加Docker开发环境
* 更新Dockerfile构建文件,升级NodeJS依赖版本。
 * 遵循ESLint重新格式化代码,修复部分警告
 * 登录Token失效增加登出提示
 * 网络请求问题增加错误错误提示
 * 升级UI依赖库
2020-06-19 16:57:00 +08:00

84 lines
2.2 KiB
Go

import request from '../../api/request'
const state = {
currentPath: '',
fileList: [],
fileContent: ''
}
const getters = {}
const mutations = {
SET_CURRENT_PATH(state, value) {
state.currentPath = value
},
SET_FILE_LIST(state, value) {
state.fileList = value
},
SET_FILE_CONTENT(state, value) {
state.fileContent = value
}
}
const actions = {
getFileList({ commit, rootState }, payload) {
const { path } = payload
const spiderId = rootState.spider.spiderForm._id
commit('SET_CURRENT_PATH', path)
return request.get(`/spiders/${spiderId}/dir`, { path })
.then(response => {
if (!response.data.data) response.data.data = []
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)
)
})
},
getFileContent({ commit, rootState }, payload) {
const { path } = payload
const spiderId = rootState.spider.spiderForm._id
return request.get(`/spiders/${spiderId}/file`, { path })
.then(response => {
commit('SET_FILE_CONTENT', response.data.data)
})
},
saveFileContent({ state, rootState }, payload) {
const { path } = payload
const spiderId = rootState.spider.spiderForm._id
return request.post(`/spiders/${spiderId}/file`,
{ path, content: state.fileContent })
},
addFile({ rootState }, payload) {
const { path } = payload
const spiderId = rootState.spider.spiderForm._id
return request.put(`/spiders/${spiderId}/file`, { path })
},
addDir({ rootState }, payload) {
const { path } = payload
const spiderId = rootState.spider.spiderForm._id
return request.put(`/spiders/${spiderId}/dir`, { path })
},
deleteFile({ rootState }, payload) {
const { path } = payload
const spiderId = rootState.spider.spiderForm._id
return request.delete(`/spiders/${spiderId}/file`, { path })
},
renameFile({ rootState }, payload) {
const { path, newPath } = payload
const spiderId = rootState.spider.spiderForm._id
return request.post(`/spiders/${spiderId}/file/rename`,
{ path, new_path: newPath })
}
}
export default {
namespaced: true,
state,
getters,
mutations,
actions
}