diff options
author | James Hu <51237606+jameshu111@users.noreply.github.com> | 2023-07-06 11:22:44 -0400 |
---|---|---|
committer | James Hu <51237606+jameshu111@users.noreply.github.com> | 2023-07-06 11:22:44 -0400 |
commit | 5a1c452941032c8a5c468e54674450f452d8bda9 (patch) | |
tree | 09b54a85705024083d379369156c89dbb519c538 | |
parent | 5379662bdc9279e43d35166ce8bafe042d0d7fb6 (diff) |
flag with comments
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/client/documents/Documents.ts | 3 | ||||
-rw-r--r-- | src/server/DashUploadUtils.ts | 24 |
3 files changed, 21 insertions, 8 deletions
diff --git a/package.json b/package.json index 3a3d17517..2b37d5171 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "start-release": "cross-env RELEASE=true NODE_OPTIONS=--max_old_space_size=4096 ts-node-dev -- src/server/index.ts", "start": "cross-env NODE_OPTIONS=--max_old_space_size=4096 ts-node-dev --debug --transpile-only -- src/server/index.ts", "oldstart": "cross-env NODE_OPTIONS=--max_old_space_size=4096 ts-node-dev --debug -- src/server/index.ts", - "debug": "cross-env NODE_OPTIONS=--max_old_space_size=8192 ts-node-dev --transpile-only --inspect -- src/server/index.ts", + "debug": "cross-env USE_AZURE=true NODE_OPTIONS=--max_old_space_size=8192 ts-node-dev --transpile-only --inspect -- src/server/index.ts", "monitor": "cross-env MONITORED=true NODE_OPTIONS=--max_old_space_size=4096 ts-node src/server/index.ts", "build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 webpack --env production", "test": "mocha -r ts-node/register test/**/*.ts", diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 93043e517..43c9d2e7a 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -1737,7 +1737,8 @@ export namespace DocUtils { } const full = { ...options, _width: 400, title: name }; // const pathname = Utils.prepend(result.accessPaths.agnostic.client); - const pathname = result.accessPaths.azure.client; + const pathname = result.accessPaths.agnostic.client; + // const pathname = result.accessPaths.azure.client; const doc = await DocUtils.DocumentFromType(type, pathname, full, overwriteDoc); if (doc) { const proto = Doc.GetProto(doc); diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index 7abefed8a..74c4786b6 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -43,6 +43,10 @@ function isLocal() { return /Dash-Web[0-9]*[\\\/]src[\\\/]server[\\\/]public[\\\/](.*)/; } +function usingAzure(){ + return process.env.USE_AZURE === 'true'; +} + export namespace DashUploadUtils { export interface Size { width: number; @@ -183,6 +187,8 @@ export namespace DashUploadUtils { } export async function upload(file: File, overwriteGuid?: string): Promise<Upload.FileResponse> { + const isAzureOn = usingAzure(); + console.log("Azure usage: ", isAzureOn); const { type, path, name } = file; const types = type?.split('/') ?? []; uploadProgress.set(overwriteGuid ?? name, 'uploading'); // If the client sent a guid it uses to track upload progress, use that guid. Otherwise, use the file's name. @@ -486,11 +492,15 @@ export namespace DashUploadUtils { const { images } = Directory; const information: Upload.ImageInformation = { accessPaths: { - agnostic: getAccessPaths(images, resolved), - azure: { + // agnostic: getAccessPaths(images, resolved), + // azure: { + // client: `https://dashblobstore.blob.core.windows.net/dashmedia/${filename}`, + // server: `https://dashblobstore.blob.core.windows.net/dashmedia/${filename}` + // } + agnostic: usingAzure() ? { client: `https://dashblobstore.blob.core.windows.net/dashmedia/${filename}`, server: `https://dashblobstore.blob.core.windows.net/dashmedia/${filename}` - } + } : getAccessPaths(images, resolved) }, ...metadata, }; @@ -540,7 +550,7 @@ export namespace DashUploadUtils { }; export async function outputResizedImages(streamProvider: () => Stream | Promise<Stream>, outputFileName: string, outputDirectory: string, originalFilename?: string, contentType?: string) { - console.log("resized original filename: ", originalFilename); + const start = Date.now(); const writtenFiles: { [suffix: string]: string } = {}; for (const { resizer, suffix } of resizers(path.extname(outputFileName))) { const outputPath = path.resolve(outputDirectory, (writtenFiles[suffix] = InjectSize(outputFileName, suffix))); @@ -552,13 +562,15 @@ export namespace DashUploadUtils { if (resizer) { readStream = readStream.pipe(resizer.withMetadata()); } - if(originalFilename && contentType) { - AzureManager.UploadBlobStream(readStream as Readable, InjectSize(originalFilename, suffix), contentType); + if(contentType && usingAzure()) { + // AzureManager.UploadBlobStream(readStream as Readable, InjectSize(originalFilename, suffix), contentType); AzureManager.UploadBlobStream(readStream as Readable, InjectSize(outputFileName, suffix), contentType); } readStream.pipe(createWriteStream(outputPath)).on('close', resolve).on('error', reject); }); } + const end = Date.now(); + console.log(`Time taken: ${end - start}ms`); return writtenFiles; } |