diff options
author | bobzel <zzzman@gmail.com> | 2024-08-20 19:11:00 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-08-20 19:11:00 -0400 |
commit | 5196009ec6bcb673fd2a4519c54442df218841f7 (patch) | |
tree | 79f4b1d559c20a6bfd9b4759a5cbe9d8f8c00fe1 /src/client/Network.ts | |
parent | 0e975569e5686138e52bdc554b3f0391f42aeead (diff) | |
parent | e57584a1be9d428fb40fc789494a7ac0ac14fb84 (diff) |
fixed up a bunch of things in face recognition
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r-- | src/client/Network.ts | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/client/Network.ts b/src/client/Network.ts index 968c407b2..8876d8190 100644 --- a/src/client/Network.ts +++ b/src/client/Network.ts @@ -8,12 +8,13 @@ import { Upload } from '../server/SharedMediaTypes'; * mainly provides methods that the client can use to begin the process of * interacting with the server, such as fetching or uploading files. */ +// eslint-disable-next-line @typescript-eslint/no-namespace export namespace Networking { export async function FetchFromServer(relativeRoute: string) { return (await fetch(relativeRoute)).text(); } - export async function PostToServer(relativeRoute: string, body?: any) { + export async function PostToServer(relativeRoute: string, body?: unknown) { const options = { uri: ClientUtils.prepend(relativeRoute), method: 'POST', @@ -31,7 +32,7 @@ export namespace Networking { * used as the guid. Otherwise, a new guid is generated. */ export interface FileGuidPair { - file: File; + file: File | Blob; guid?: string; } /** @@ -48,15 +49,14 @@ export namespace Networking { if (!fileguidpairs.length) { return []; } - const maxFileSize = 50000000; + const maxFileSize = 5000000; if (fileguidpairs.some(f => f.file.size > maxFileSize)) { - return new Promise<any>(res => { - res([ - { - source: { name: '', type: '', size: 0, toJson: () => ({ name: '', type: '' }) }, - result: { name: '', message: `max file size (${maxFileSize / 1000000}MB) exceeded` }, - }, - ]); + return new Promise<Upload.FileResponse<T>[]>(res => { + res([{ + source: { size: 0, filepath: '', mimetype: '', originalFilename: '', newFilename: '',hashAlgorithm: false, + toJSON: () => ({ size: 0, filepath: '', mimetype: '', originalFilename: '', newFilename: '',name: '', length: 0, mtime: new Date(), type: '' }) }, + result: { name: '', message: `max file size (${maxFileSize / 1000000}MB) exceeded` } + }]) // prettier-ignore }); } formData.set('fileguids', fileguidpairs.map(pair => pair.guid).join(';')); @@ -77,7 +77,12 @@ export namespace Networking { const endpoint = browndash ? '[insert endpoint allowing local => browndash]' : '/uploadFormData'; const response = await fetch(endpoint, parameters); - return response.json(); + return response.json().then((json: Upload.FileResponse<T>[]) => + json.map(fileresponse => { + if ('message' in fileresponse.result) fileresponse.result = new Error(fileresponse.result.message); + return fileresponse; + }) + ); } export async function UploadYoutubeToServer<T extends Upload.FileInformation = Upload.FileInformation>(videoId: string, overwriteId?: string): Promise<Upload.FileResponse<T>[]> { |