diff --git a/frontend/src/federation.js b/frontend/src/federation.js index 5ae1291..eed4a66 100644 --- a/frontend/src/federation.js +++ b/frontend/src/federation.js @@ -247,12 +247,11 @@ class ServerSetUnion { async get(auth, target) { try { - const ret = await this.serverSets.reduce(async (acc, serverset) => { + return await this.serverSets.reduce(async (acc, serverset) => { return acc.then(async (acc) => { return acc.concat(await serverset.get(auth, target)) }) }, Promise.resolve([])) - return ret } catch (e) { throw new Error('all servers failed') } @@ -260,12 +259,11 @@ class ServerSetUnion { async post(auth, target, data) { try { - const ret = await this.serverSets.reduce(async (acc, serverset) => { + return await this.serverSets.reduce(async (acc, serverset) => { return acc.then(async (acc) => { return acc.concat(await serverset.post(auth, target, data)) }) }, Promise.resolve([])) - return ret } catch (e) { throw new Error('all servers failed') } @@ -273,12 +271,11 @@ class ServerSetUnion { async patch(auth, target, data) { try { - const ret = await this.serverSets.reduce(async (acc, serverset) => { + return await this.serverSets.reduce(async (acc, serverset) => { return acc.then(async (acc) => { return acc.concat(await serverset.patch(auth, target, data)) }) }, Promise.resolve([])) - return ret } catch (e) { throw new Error('all servers failed') } @@ -286,12 +283,11 @@ class ServerSetUnion { async put(auth, target, data) { try { - const ret = await this.serverSets.reduce(async (acc, serverset) => { + return await this.serverSets.reduce(async (acc, serverset) => { return acc.then(async (acc) => { return acc.concat(await serverset.put(auth, target, data)) }) }, Promise.resolve([])) - return ret } catch (e) { throw new Error('all servers failed') } @@ -299,12 +295,11 @@ class ServerSetUnion { async delete(auth, target) { try { - const ret = await this.serverSets.reduce(async (acc, serverset) => { + return await this.serverSets.reduce(async (acc, serverset) => { return acc.then(async (acc) => { return acc.concat(await serverset.delete(auth, target)) }) }, Promise.resolve([])) - return ret } catch (e) { throw new Error('all servers failed') } diff --git a/frontend/src/store.js b/frontend/src/store.js index 3ebc4ec..59824fa 100644 --- a/frontend/src/store.js +++ b/frontend/src/store.js @@ -78,6 +78,9 @@ export default createStore({ setDomains(state, domains) { state.domains = domains; }, + setFiles(state, files) { + state.files = files; + }, logout(state) { state.user = null; state.token = null; @@ -251,6 +254,22 @@ export default createStore({ const servers = await dispatch('getHomeServers') return await servers.delete(getters.signAuth, '/api/friends/' + id + '/') }, + async fetchFiles({state, commit, dispatch, getters}) { + if (state.last_load.files > Date.now() - 1000 * 60 * 60 * 24) { + return state.files + } + const servers = await dispatch('getHomeServers') + const data = await servers.get(getters.signAuth, '/api/files/') + commit('setFiles', data) + state.last_load.files = Date.now() + return data + }, + async pushFile({state, dispatch, getters}, {file}) { + const servers = await dispatch('getHomeServers') + const data = await servers.post(getters.signAuth, '/api/files/', file) + state.files.push(data) + return data + }, async fetchTags({state, commit, dispatch, getters}) { if (state.last_load.tags > Date.now() - 1000 * 60 * 60 * 24) { return state.tags diff --git a/frontend/src/views/InventoryEdit.vue b/frontend/src/views/InventoryEdit.vue index e715821..881eb47 100644 --- a/frontend/src/views/InventoryEdit.vue +++ b/frontend/src/views/InventoryEdit.vue @@ -58,6 +58,7 @@ import {mapActions, mapGetters, mapState} from "vuex"; import BaseLayout from "@/components/BaseLayout.vue"; import TagField from "@/components/TagField.vue"; import PropertyField from "@/components/PropertyField.vue"; +import CombinedFileField from "@/components/CombinedFileField.vue"; export default { name: "InventoryEdit", @@ -78,6 +79,7 @@ export default { BaseLayout, TagField, PropertyField, + CombinedFileField, ...BIcons }, props: { diff --git a/frontend/src/views/InventoryNew.vue b/frontend/src/views/InventoryNew.vue index 106869d..dc50a36 100644 --- a/frontend/src/views/InventoryNew.vue +++ b/frontend/src/views/InventoryNew.vue @@ -69,6 +69,7 @@ import {mapActions, mapState} from "vuex"; import BaseLayout from "@/components/BaseLayout.vue"; import TagField from "@/components/TagField.vue"; import PropertyField from "@/components/PropertyField.vue"; +import CombinedFileField from "@/components/CombinedFileField.vue"; export default { name: "InventoryNew", @@ -76,6 +77,7 @@ export default { BaseLayout, TagField, PropertyField, + CombinedFileField, ...BIcons }, data() { diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 99882a1..e16c385 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -45,6 +45,9 @@ export default defineConfig({ '^/static/': { target: "http://127.0.0.1:8000/", }, + '^/media/': { + target: "http://127.0.0.1:8000/", + }, '^/wiki/': { target: "http://127.0.0.1:8080/", rewrite: (path) => path.replace(/^\/wiki/, ''),