Image Upload

This commit is contained in:
Julian Krauser 2025-04-29 18:32:08 +02:00
parent 0771b43f56
commit 91ede95530
4 changed files with 117 additions and 34 deletions

View file

@ -54,26 +54,43 @@ export const useSettingStore = defineStore("setting", {
key: K,
value: SettingValueMapping[K]
): Promise<AxiosResponse<any, any>> {
return await http.put("/admin/setting", {
setting: key,
value: value,
});
return await http
.put("/admin/setting", {
setting: key,
value: value,
})
.then((res) => {
this.settings[key] = value;
return res;
});
},
async updateSettings<K extends SettingString>(
data: { key: K; value: SettingValueMapping[K] }[]
): Promise<AxiosResponse<any, any>> {
return await http.put("/admin/setting/multi", data);
return await http.put("/admin/setting/multi", data).then((res) => {
for (const element of data) {
this.settings[element.key] = element.value;
}
return res;
});
},
async uploadImage(data: { key: SettingString; value?: File }[]): Promise<AxiosResponse<any, any>> {
async uploadImage(data: { key: "club.logo" | "club.icon"; value?: File }[]): Promise<AxiosResponse<any, any>> {
const formData = new FormData();
for (let entry of data) {
if (entry.value) formData.append(entry.key, entry.value);
}
return await http.put("/admin/setting/images", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});
return await http
.put("/admin/setting/images", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
.then((res) => {
for (const element of data) {
this.settings[element.key] = element.value ? "configured" : "";
}
return res;
});
},
async resetSetting(key: SettingString): Promise<AxiosResponse<any, any>> {
return await http.delete(`/admin/setting/${key}`);