Can upload new gong

This commit is contained in:
nemunaire 2022-10-15 12:26:05 +02:00
commit cc301da971
4 changed files with 121 additions and 4 deletions

View file

@ -45,6 +45,25 @@ export class Gong {
}
}
export async function uploadGong(files, meta) {
for (const file of files) {
const formData = new FormData();
formData.append("gongfile", file);
formData.append("meta", JSON.stringify(meta));
const res = await fetch('/api/gongs', {
method: 'POST',
body: formData,
});
if (res.ok) {
const data = await res.json();
return new Gong(data)
} else {
throw new Error((await res.json()).errmsg);
}
}
}
export async function getGongs() {
const res = await fetch(`api/gongs`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {