fix pfp uploading

This commit is contained in:
Erik 2023-05-02 02:53:53 +03:00
parent d6384af097
commit ea1f566a1c
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68
3 changed files with 10 additions and 6 deletions

View File

@ -1,6 +1,9 @@
export type ReqOptions = {
headers?: {[key: string]: string} | null
}
export type RequestOptions = { export type RequestOptions = {
headers?: { [key: string]: string }, headers?: { [key: string]: string },
} }
export type Res = { export type Res = {

View File

@ -98,10 +98,11 @@ const Profile = () => {
button.disabled = true; button.disabled = true;
const body = new FormData(); const body = new FormData();
body.set('file', file, file.name); body.append('file', file, file.name);
// body.set('name', 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'); if (!response.success) setError(response.message || 'Unknown error');
else setFile(null); else setFile(null);
button.disabled = false; button.disabled = false;

View File

@ -1,5 +1,5 @@
import { User } from "../@types/ApiStructures"; import { User } from "../@types/ApiStructures";
import { RequestOptions, ClientSettings, Res } from "../@types/Other"; import { RequestOptions, ClientSettings, Res, ReqOptions } from "../@types/Other";
type HttpOpts = { type HttpOpts = {
body?: string, body?: string,
@ -66,7 +66,7 @@ const parseResponse = async (response: Response): Promise<Res> => {
return { ...base, message: await response.text() }; 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 = { const options: HttpOpts & RequestOptions = {
method: 'post' method: 'post'