aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2020-02-16 16:00:29 -0500
committerSam Wilkins <samwilkins333@gmail.com>2020-02-16 16:00:29 -0500
commitae4b072bb8f360c60cd61bcd1e49a075010e20b4 (patch)
tree131a9d7c18dd7ea3e86861e78f9ae881d82e7483 /src
parentb42e1e1e2da941955d7751b6003f18fecd5f2f8d (diff)
clean up
Diffstat (limited to 'src')
-rw-r--r--src/scraping/buxton/final/BuxtonImporter.ts6
-rw-r--r--src/server/DashUploadUtils.ts14
2 files changed, 8 insertions, 12 deletions
diff --git a/src/scraping/buxton/final/BuxtonImporter.ts b/src/scraping/buxton/final/BuxtonImporter.ts
index 8041343fd..ae5d7237d 100644
--- a/src/scraping/buxton/final/BuxtonImporter.ts
+++ b/src/scraping/buxton/final/BuxtonImporter.ts
@@ -310,10 +310,8 @@ async function writeImages(zip: any): Promise<ImageData[]> {
continue;
}
- const ext = `.${type}`.toLowerCase();
- const generatedFileName = `upload_${Utils.GenerateGuid()}${ext}`;
-
- await DashUploadUtils.outputResizedImages(streamImage, imageDir, generatedFileName, ext);
+ const generatedFileName = `upload_${Utils.GenerateGuid()}.${type.toLowerCase()}`;
+ await DashUploadUtils.outputResizedImages(streamImage, generatedFileName, imageDir);
imageUrls.push({
url: `/files/images/buxton/${generatedFileName}`,
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts
index d4bcd22ae..8f31f990f 100644
--- a/src/server/DashUploadUtils.ts
+++ b/src/server/DashUploadUtils.ts
@@ -208,8 +208,7 @@ export namespace DashUploadUtils {
export const UploadInspectedImage = async (metadata: Upload.InspectionResults, filename?: string, prefix = "", cleanUp = true): Promise<Upload.ImageInformation> => {
const { requestable, source, ...remaining } = metadata;
- const extension = `.${remaining.contentType.split("/")[1].toLowerCase()}`;
- const resolved = filename || `${prefix}upload_${Utils.GenerateGuid()}${extension}`;
+ const resolved = filename || `${prefix}upload_${Utils.GenerateGuid()}.${remaining.contentType.split("/")[1].toLowerCase()}`;
const { images } = Directory;
const information: Upload.ImageInformation = {
accessPaths: {
@@ -217,8 +216,7 @@ export namespace DashUploadUtils {
},
...metadata
};
- const outputPath = pathToDirectory(Directory.images);
- const writtenFiles = await outputResizedImages(() => request(requestable), outputPath, resolved, extension);
+ const writtenFiles = await outputResizedImages(() => request(requestable), resolved, pathToDirectory(Directory.images));
for (const suffix of Object.keys(writtenFiles)) {
information.accessPaths[suffix] = getAccessPaths(images, writtenFiles[suffix]);
}
@@ -248,10 +246,10 @@ export namespace DashUploadUtils {
force: true
};
- export async function outputResizedImages(streamProvider: () => Stream | Promise<Stream>, outputPath: string, fileName: string, ext: string) {
+ export async function outputResizedImages(streamProvider: () => Stream | Promise<Stream>, outputFileName: string, outputDirectory: string) {
const writtenFiles: { [suffix: string]: string } = {};
- for (const { resizer, suffix } of resizers(ext)) {
- const resolvedOutputPath = path.resolve(outputPath, writtenFiles[suffix] = InjectSize(fileName, suffix));
+ for (const { resizer, suffix } of resizers(path.extname(outputFileName))) {
+ const outputPath = path.resolve(outputDirectory, writtenFiles[suffix] = InjectSize(outputFileName, suffix));
await new Promise<void>(async (resolve, reject) => {
const source = streamProvider();
let readStream: Stream;
@@ -263,7 +261,7 @@ export namespace DashUploadUtils {
if (resizer) {
readStream = readStream.pipe(resizer.withMetadata());
}
- readStream.pipe(createWriteStream(resolvedOutputPath)).on("close", resolve).on("error", reject);
+ readStream.pipe(createWriteStream(outputPath)).on("close", resolve).on("error", reject);
});
}
return writtenFiles;