fix: Return POST resposne to the page

This commit is contained in:
April Hall 2025-02-22 02:44:16 -05:00
parent 24257fea8c
commit 88558579d7
Signed by: arithefirst
GPG Key ID: 4508A15C4DB91C5B
2 changed files with 10 additions and 17 deletions

View File

@ -7,10 +7,8 @@
async function submit(e: SubmitEvent) {
e.preventDefault();
if (files.length === 0) return;
const success = await generateStream(files[0]);
if (success) {
// success feedback
}
const res = await generateStream(files[0]);
console.log(res);
}
</script>

View File

@ -1,16 +1,11 @@
export async function generateStream(file: File): Promise<boolean> {
try {
export async function generateStream(file: File): Promise<Response> {
const formData = new FormData();
formData.append('file', file);
await fetch(`/api/set-profile-photo/`, {
const res = await fetch(`/api/set-profile-photo/`, {
method: 'POST',
body: formData,
});
return true;
} catch (e) {
console.error(`Error sending stream: ${(e as Error).message}`);
return false;
}
return res;
}