From dc2d283d04a1ee3418d5851d93b10d79d6175cbc Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 24 Sep 2022 15:20:34 +0200 Subject: Upload and delete uploads --- store/models.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'store') diff --git a/store/models.js b/store/models.js index 44dbb56..04717f2 100644 --- a/store/models.js +++ b/store/models.js @@ -147,6 +147,58 @@ export const actions = { commit("loadingStatus", false, { root: true }); + return res; + }, + // Create a model upload + async upload({ commit, rootGetters }, payload) { + commit("loadingStatus", true, { root: true }); + let status = 400; + let api = this.$config.api; + + const form = new FormData(); + form.append("file", payload.file); + + await fetch(`${api}/v1/models/${payload.id}/upload`, { + method: "POST", + headers: { + Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, + }, + body: form, + }) + .then(async (response) => { + status = response.status; + }) + .catch((e) => { + status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + + return status; + }, + // Delete a model upload + async deleteUpload({ commit, rootGetters }, data) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/models/${data.id}/upload/${data.uid}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, + }, + }) + .then(async (response) => { + res.status = response.status; + res.data = await response.text(); + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + return res; }, }; -- cgit v1.2.3-18-g5258