aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/Network.ts20
-rw-r--r--src/client/documents/Documents.ts8
-rw-r--r--src/client/views/nodes/LoadingBox.tsx4
-rw-r--r--src/server/DashUploadUtils.ts3
4 files changed, 22 insertions, 13 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',
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 515a870b5..75998ac40 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -2,7 +2,7 @@ import { IconProp } from '@fortawesome/fontawesome-svg-core';
import { action, runInAction } from 'mobx';
import { basename } from 'path';
import { DateField } from '../../fields/DateField';
-import { Doc, DocListCast, Field, Initializing, Opt, updateCachedAcls } from '../../fields/Doc';
+import { DataSym, Doc, DocListCast, Field, FieldsSym, Initializing, Opt, updateCachedAcls } from '../../fields/Doc';
import { Id } from '../../fields/FieldSymbols';
import { HtmlField } from '../../fields/HtmlField';
import { InkField, PointData } from '../../fields/InkField';
@@ -1843,7 +1843,9 @@ export namespace DocUtils {
export async function uploadFilesToDocs(files: File[], options: DocumentOptions) {
const generatedDocuments: Doc[] = [];
- const upfiles = await Networking.UploadFilesToServer(files);
+ const fileNoGuidPairs: Networking.FileGuidPair[] = [];
+ files.map(file => fileNoGuidPairs.push({file : file}));
+ const upfiles = await Networking.UploadFilesToServer(fileNoGuidPairs);
for (const {
source: { name, type },
result,
@@ -1855,7 +1857,7 @@ export namespace DocUtils {
export function uploadFileToDoc(file: File, options: DocumentOptions, overwriteDoc: Doc) {
const generatedDocuments: Doc[] = [];
- Networking.UploadFilesToServer([file]).then(upfiles => {
+ Networking.UploadFilesToServer([{file: file, guid: overwriteDoc[Id]}]).then(upfiles => {
const {
source: { name, type },
result,
diff --git a/src/client/views/nodes/LoadingBox.tsx b/src/client/views/nodes/LoadingBox.tsx
index 8c5255f80..843da69b3 100644
--- a/src/client/views/nodes/LoadingBox.tsx
+++ b/src/client/views/nodes/LoadingBox.tsx
@@ -8,6 +8,7 @@ import { Networking } from '../../Network';
import { ViewBoxAnnotatableComponent } from '../DocComponent';
import { FieldView, FieldViewProps } from './FieldView';
import './LoadingBox.scss';
+import { Id } from '../../../fields/FieldSymbols';
/**
* LoadingBox Class represents a placeholder doc for documents that are currently
@@ -39,11 +40,12 @@ export class LoadingBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
_timer: any;
@observable progress = '';
componentDidMount() {
+ console.log(StrCast(this.rootDoc[Id]));
if (!Doc.CurrentlyLoading?.includes(this.rootDoc)) {
this.rootDoc.loadingError = 'Upload interrupted, please try again';
} else {
const updateFunc = async () => {
- const result = await Networking.QueryYoutubeProgress(StrCast(this.rootDoc.title));
+ const result = await Networking.QueryYoutubeProgress(StrCast(this.rootDoc[Id]));
runInAction(() => (this.progress = result.progress));
this._timer = setTimeout(updateFunc, 1000);
};
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts
index 11523a9d8..971fefb5a 100644
--- a/src/server/DashUploadUtils.ts
+++ b/src/server/DashUploadUtils.ts
@@ -181,9 +181,10 @@ export namespace DashUploadUtils {
});
}
- export async function upload(file: File): Promise<Upload.FileResponse> {
+ export async function upload(file: File, overwriteGuid?: string): Promise<Upload.FileResponse> {
const { type, path, name } = file;
const types = type?.split('/') ?? [];
+ uploadProgress.set(overwriteGuid ?? name, 'uploading');
const category = types[0];
let format = `.${types[1]}`;