aboutsummaryrefslogtreecommitdiff
path: root/src/client/Network.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-08-08 12:27:40 -0400
committerbobzel <zzzman@gmail.com>2024-08-08 12:27:40 -0400
commit4574b7f03ccc85c4bebdbfd9475788456086704f (patch)
treed23d30343541b9af029ef418492d629d3cc710d7 /src/client/Network.ts
parente1db06d59d580aa640212a0d3a6aeecb9122bdf0 (diff)
many changes to add typing in place of 'any's etc
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r--src/client/Network.ts27
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>[]> {