曲を投稿できるようにする

This commit is contained in:
yuuki
2024-02-13 11:58:04 +09:00
parent a318a177ea
commit 1b03e5d0e7
6 changed files with 146 additions and 17 deletions

27
public/upload/upload.js Normal file
View File

@@ -0,0 +1,27 @@
function uploadFiles() {
const form = document.getElementById('upload-form');
const formData = new FormData(form);
fetch('/upload', {
method: 'POST',
body: formData,
})
.then(res => {
if (res.ok) {
return res.json();
} else {
throw new Error(res.url + " で " + res.status.toString() + " が発生しました。");
}
})
.then(data => {
if (data.success) {
alert("おめでとう!ファイルの投稿に成功しました!");
} else {
throw new Error(data.error);
}
})
.catch(error => {
console.error('エラー:', error);
document.getElementById("error-view").textContent = error;
});
}