diff options
author | Zachary Zhang <zacharyzhang7@gmail.com> | 2024-08-31 00:46:29 -0400 |
---|---|---|
committer | Zachary Zhang <zacharyzhang7@gmail.com> | 2024-08-31 00:46:29 -0400 |
commit | 196294f331496262bef256da8b8e9dbc80288bea (patch) | |
tree | 85ff27b7a8070585f9a5ef71dff63566e03232ba /src/client/Network.ts | |
parent | 0cf61501ec9be34294935f01973c1bd9cad6d267 (diff) | |
parent | c36607691e0b7f5c04f3209a64958f5e51ddd785 (diff) |
Merge branch 'master' into zach-starter
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r-- | src/client/Network.ts | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/client/Network.ts b/src/client/Network.ts index 968c407b2..204fcf0ac 100644 --- a/src/client/Network.ts +++ b/src/client/Network.ts @@ -1,3 +1,4 @@ +import formidable from 'formidable'; import * as requestPromise from 'request-promise'; import { ClientUtils } from '../ClientUtils'; import { Utils } from '../Utils'; @@ -8,12 +9,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. */ + 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 +33,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,16 +50,9 @@ export namespace Networking { if (!fileguidpairs.length) { return []; } - const maxFileSize = 50000000; + const maxFileSize = 6000000; 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: { newFilename: '', mimetype: '' } as formidable.File, result: new Error(`max file size (${maxFileSize / 1000000}MB) exceeded`) }])); } formData.set('fileguids', fileguidpairs.map(pair => pair.guid).join(';')); formData.set('filesize', fileguidpairs.reduce((sum, pair) => sum + pair.file.size, 0).toString()); @@ -77,7 +72,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>[]> { |