Can upload new gong
This commit is contained in:
parent
f0967f3b9d
commit
cc301da971
4 changed files with 121 additions and 4 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue