summaryrefslogtreecommitdiff
path: root/store
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-09-24 15:20:34 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-09-24 15:20:34 +0200
commitdc2d283d04a1ee3418d5851d93b10d79d6175cbc (patch)
tree7713456f8dbae7d0f625171a68a9e640f59a7c04 /store
parentaad983ec7b198d1f5fb81dd82d75912926a05ca2 (diff)
Upload and delete uploads
Diffstat (limited to 'store')
-rw-r--r--store/models.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/store/models.js b/store/models.js
index 44dbb56..04717f2 100644
--- a/store/models.js
+++ b/store/models.js
@@ -149,4 +149,56 @@ export const actions = {
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;
+ },
};