aboutsummaryrefslogtreecommitdiff
path: root/src/client/Network.ts
diff options
context:
space:
mode:
authorJames Hu <51237606+jameshu111@users.noreply.github.com>2023-06-07 11:45:20 -0400
committerJames Hu <51237606+jameshu111@users.noreply.github.com>2023-06-07 11:45:20 -0400
commit55502b8d24dbbad87af5b9059cc3a746e4db91d9 (patch)
treef89db45a778bffd1f74f746b8fbc46b8bb1e1000 /src/client/Network.ts
parent3d30bdaf6dcf4972593f10b9b0f2fabd79c7062b (diff)
logging
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r--src/client/Network.ts20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/client/Network.ts b/src/client/Network.ts
index 19eff3b3b..28825823d 100644
--- a/src/client/Network.ts
+++ b/src/client/Network.ts
@@ -17,21 +17,25 @@ export namespace Networking {
return requestPromise.post(options);
}
+ export interface FileGuidPair {
+ file: File;
+ guid?: string;
+ }
/**
* Handles uploading basic file types to server and makes the API call to "/uploadFormData" endpoint
* with the mapping of GUID to filem as parameters.
*
- * @param files the files to be uploaded to the server
+ * @param fileguidpairs the files to be uploaded to the server
* @returns the response as a json from the server
*/
- export async function UploadFilesToServer<T extends Upload.FileInformation = Upload.FileInformation>(files: File | File[]): Promise<Upload.FileResponse<T>[]> {
- const formData = new FormData();
- if (Array.isArray(files)) {
- if (!files.length) {
+ export async function UploadFilesToServer<T extends Upload.FileInformation = Upload.FileInformation>(fileguidpairs: FileGuidPair | FileGuidPair[]): Promise<Upload.FileResponse<T>[]> {
+ const formData = new FormData();
+ if (Array.isArray(fileguidpairs)) {
+ if (!fileguidpairs.length) {
return [];
}
const maxFileSize = 50000000;
- if (files.some(f => f.size > maxFileSize)) {
+ if (fileguidpairs.some(f => f.file.size > maxFileSize)) {
return new Promise<any>(res =>
res([
{
@@ -41,9 +45,9 @@ export namespace Networking {
])
);
}
- files.forEach(file => formData.append(Utils.GenerateGuid(), file));
+ fileguidpairs.forEach(fileguidpair => formData.append(fileguidpair.guid ?? Utils.GenerateGuid(), fileguidpair.file));
} else {
- formData.append(Utils.GenerateGuid(), files);
+ formData.append(fileguidpairs.guid ?? Utils.GenerateGuid(), fileguidpairs.file);
}
const parameters = {
method: 'POST',