2020-01-31 07:45:56 -05:00
|
|
|
export const state = () => ({
|
|
|
|
currentPath: null,
|
|
|
|
crumbs: [],
|
|
|
|
folderTree: {}
|
|
|
|
})
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
UPDATE_CURRENT_PATH (state, path) {
|
|
|
|
state.currentPath = path
|
|
|
|
},
|
|
|
|
UPDATE_CRUMBS (state, crumbs) {
|
|
|
|
state.crumbs = crumbs
|
|
|
|
},
|
|
|
|
UPDATE_FOLDER_TREE (state, tree) {
|
|
|
|
state.folderTree = tree
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
2020-04-30 04:53:13 -04:00
|
|
|
async getTree ({ commit, dispatch, state }, { extensions, path }) {
|
2020-04-20 12:07:12 -04:00
|
|
|
const crumbs = []
|
|
|
|
let root = '/'
|
2020-05-03 15:11:25 -04:00
|
|
|
const response = await this.$axios.get(`api/player/media/?extensions=${extensions}&path=${path}`)
|
2020-01-31 07:45:56 -05:00
|
|
|
|
2020-04-20 12:07:12 -04:00
|
|
|
if (response.data.tree) {
|
|
|
|
const pathArr = response.data.tree[0].split('/')
|
2020-01-31 07:45:56 -05:00
|
|
|
|
2020-04-20 12:07:12 -04:00
|
|
|
if (response.data.tree[1].length === 0) {
|
|
|
|
response.data.tree[1].push(pathArr[pathArr.length - 1])
|
|
|
|
}
|
2020-01-31 07:45:56 -05:00
|
|
|
|
2020-04-20 12:07:12 -04:00
|
|
|
if (path) {
|
|
|
|
for (const crumb of pathArr) {
|
|
|
|
if (crumb) {
|
|
|
|
root += crumb + '/'
|
|
|
|
crumbs.push({ text: crumb, path: root })
|
2020-01-31 07:45:56 -05:00
|
|
|
}
|
|
|
|
}
|
2020-04-20 12:07:12 -04:00
|
|
|
} else {
|
|
|
|
crumbs.push({ text: pathArr[pathArr.length - 1], path: '' })
|
2020-01-31 07:45:56 -05:00
|
|
|
}
|
2020-04-20 12:07:12 -04:00
|
|
|
|
|
|
|
commit('UPDATE_CURRENT_PATH', path)
|
|
|
|
commit('UPDATE_CRUMBS', crumbs)
|
|
|
|
commit('UPDATE_FOLDER_TREE', response.data)
|
2020-01-31 07:45:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|