fix: Return POST resposne to the page
This commit is contained in:
parent
24257fea8c
commit
88558579d7
@ -7,10 +7,8 @@
|
|||||||
async function submit(e: SubmitEvent) {
|
async function submit(e: SubmitEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (files.length === 0) return;
|
if (files.length === 0) return;
|
||||||
const success = await generateStream(files[0]);
|
const res = await generateStream(files[0]);
|
||||||
if (success) {
|
console.log(res);
|
||||||
// success feedback
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
export async function generateStream(file: File): Promise<boolean> {
|
export async function generateStream(file: File): Promise<Response> {
|
||||||
try {
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
|
||||||
await fetch(`/api/set-profile-photo/`, {
|
const res = await fetch(`/api/set-profile-photo/`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return res;
|
||||||
} catch (e) {
|
|
||||||
console.error(`Error sending stream: ${(e as Error).message}`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user