From ea1f566a1c36ab1b6239104ae186890fc5d7adf9 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 2 May 2023 02:53:53 +0300 Subject: [PATCH] fix pfp uploading --- src/@types/Other.ts | 5 ++++- src/pages/home/Profile.tsx | 7 ++++--- src/util/Util.ts | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/@types/Other.ts b/src/@types/Other.ts index 7b19551..4bcc4f4 100644 --- a/src/@types/Other.ts +++ b/src/@types/Other.ts @@ -1,6 +1,9 @@ +export type ReqOptions = { + headers?: {[key: string]: string} | null +} + export type RequestOptions = { headers?: { [key: string]: string }, - } export type Res = { diff --git a/src/pages/home/Profile.tsx b/src/pages/home/Profile.tsx index 385fdf4..2daa92e 100644 --- a/src/pages/home/Profile.tsx +++ b/src/pages/home/Profile.tsx @@ -98,10 +98,11 @@ const Profile = () => { button.disabled = true; const body = new FormData(); - body.set('file', file, file.name); - // body.set('name', file.name); + body.append('file', file, file.name); - const response = await post('/api/user/avatar', body, { headers: {} }); + const response = await post('/api/user/avatar', body, { + headers: null + }); if (!response.success) setError(response.message || 'Unknown error'); else setFile(null); button.disabled = false; diff --git a/src/util/Util.ts b/src/util/Util.ts index d3fbd01..8d2a9ff 100644 --- a/src/util/Util.ts +++ b/src/util/Util.ts @@ -1,5 +1,5 @@ import { User } from "../@types/ApiStructures"; -import { RequestOptions, ClientSettings, Res } from "../@types/Other"; +import { RequestOptions, ClientSettings, Res, ReqOptions } from "../@types/Other"; type HttpOpts = { body?: string, @@ -66,7 +66,7 @@ const parseResponse = async (response: Response): Promise => { return { ...base, message: await response.text() }; }; -export const post = async (url: string, body?: object | string, opts: RequestOptions = {}) => { +export const post = async (url: string, body?: object | string, opts: ReqOptions = {}) => { const options: HttpOpts & RequestOptions = { method: 'post'