ffplayout/store/media.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-01-31 13:45:56 +01: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 = {
2022-07-06 16:22:27 +02:00
async getTree ({ commit, dispatch, state, rootState }, { path }) {
2020-04-20 18:07:12 +02:00
const crumbs = []
let root = '/'
const channel = rootState.config.configGui[rootState.config.configID].id
2022-06-30 18:39:01 +02:00
const response = await this.$axios.post(
`api/file/${channel}/browse/`, { source: path })
2020-01-31 13:45:56 +01:00
2022-06-30 18:39:01 +02:00
if (response.data) {
2022-07-03 21:23:34 +02:00
const pathStr = 'Home/' + response.data.source
const pathArr = pathStr.split('/')
2020-01-31 13:45:56 +01:00
2020-04-20 18:07:12 +02:00
if (path) {
for (const crumb of pathArr) {
2022-07-03 21:23:34 +02:00
if (crumb === 'Home') {
crumbs.push({ text: crumb, path: root })
} else if (crumb) {
2020-04-20 18:07:12 +02:00
root += crumb + '/'
crumbs.push({ text: crumb, path: root })
2020-01-31 13:45:56 +01:00
}
}
2020-04-20 18:07:12 +02:00
} else {
2022-07-03 21:23:34 +02:00
crumbs.push({ text: 'Home', path: '' })
2020-01-31 13:45:56 +01:00
}
2020-04-20 18:07:12 +02:00
commit('UPDATE_CURRENT_PATH', path)
commit('UPDATE_CRUMBS', crumbs)
commit('UPDATE_FOLDER_TREE', response.data)
2020-01-31 13:45:56 +01:00
}
}
}