aboutsummaryrefslogtreecommitdiff
path: root/src/server/DashUploadUtils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/DashUploadUtils.ts')
-rw-r--r--src/server/DashUploadUtils.ts29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts
index 46d897339..8a429b81b 100644
--- a/src/server/DashUploadUtils.ts
+++ b/src/server/DashUploadUtils.ts
@@ -5,6 +5,8 @@ import * as sharp from 'sharp';
import request = require('request-promise');
import { ExifData, ExifImage } from 'exif';
import { Opt } from '../new_fields/Doc';
+import { SharedMediaTypes } from './SharedMediaTypes';
+import { filesDirectory } from '.';
const uploadDirectory = path.join(__dirname, './public/files/');
@@ -15,17 +17,22 @@ export namespace DashUploadUtils {
suffix: string;
}
+ export interface ImageFileResponse {
+ name: string;
+ path: string;
+ type: string;
+ exif: Opt<DashUploadUtils.EnrichedExifData>;
+ }
+
export const Sizes: { [size: string]: Size } = {
SMALL: { width: 100, suffix: "_s" },
MEDIUM: { width: 400, suffix: "_m" },
LARGE: { width: 900, suffix: "_l" },
};
- const gifs = [".gif"];
- const pngs = [".png"];
- const jpgs = [".jpg", ".jpeg"];
- export const imageFormats = [...pngs, ...jpgs, ...gifs];
- const videoFormats = [".mov", ".mp4"];
+ export function validateExtension(url: string) {
+ return SharedMediaTypes.imageFormats.includes(path.extname(url).toLowerCase());
+ }
const size = "content-length";
const type = "content-type";
@@ -83,6 +90,17 @@ export namespace DashUploadUtils {
error?: string;
}
+ export enum Partitions {
+ pdf_text,
+ images,
+ videos
+ }
+
+ export async function buildFilePartitions() {
+ const pending = Object.keys(Partitions).map(sub => createIfNotExists(filesDirectory + sub));
+ return Promise.all(pending);
+ }
+
/**
* Based on the url's classification as local or remote, gleans
* as much information as possible about the specified image
@@ -128,6 +146,7 @@ export namespace DashUploadUtils {
contentSize,
contentType,
};
+ const { pngs, imageFormats, jpgs, videoFormats } = SharedMediaTypes;
return new Promise<UploadInformation>(async (resolve, reject) => {
const resizers = [
{ resizer: sharp().rotate(), suffix: "_o" },