From 786d25a4f8db1db8795f04a17fba392636e5f891 Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Tue, 7 Jan 2020 23:35:14 -0800 Subject: Various features/fixes to allow running on Linux w/o MongoDB or Solr - Added new launch config option for chromium - Changed port for TypeScript server debugger to account for worker process - Updated packages to versions that work with current node/npm - Update IDatabase interface - Updated MemoryDatabase to work properly with Dash - Added some workarounds for in memory database as they currently don't support users, so you must be guest, which means the guest needs to be able to do things it usually can't - Added environment variable to disable search. This doesn't fully disable search yet, but it is enough to not throw major errors when Solr isn't running - Added logic to support using an in memory DB instead of MongoDB --- .vscode/launch.json | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to '.vscode/launch.json') diff --git a/.vscode/launch.json b/.vscode/launch.json index d09ba3435..77e139dbd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,7 +3,8 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", - "configurations": [{ + "configurations": [ + { "type": "chrome", "request": "launch", "name": "Launch Chrome against localhost", @@ -15,6 +16,19 @@ "--experimental-modules" ] }, + { + "type": "chrome", + "request": "launch", + "name": "Launch Chromium against localhost", + "sourceMaps": true, + "breakOnLoad": true, + "url": "http://localhost:1050/login", + "webRoot": "${workspaceFolder}", + "runtimeExecutable": "/usr/bin/chromium", + "runtimeArgs": [ + "--experimental-modules" + ] + }, { "type": "firefox", "request": "launch", @@ -38,7 +52,7 @@ "request": "attach", "name": "Typescript Server", "protocol": "inspector", - "port": 9229, + "port": 9230, "localRoot": "${workspaceFolder}", "remoteRoot": "${workspaceFolder}" }, -- cgit v1.2.3-70-g09d2 From 219281533cffed08d2e0f73ee417cd18569a5419 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Thu, 23 Jan 2020 19:23:13 -0500 Subject: request image size now server-side and improved image upload routine --- .vscode/launch.json | 2 +- src/server/DashUploadUtils.ts | 68 ++++++++++++++++++++++++------------------- src/server/RouteManager.ts | 2 +- 3 files changed, 40 insertions(+), 32 deletions(-) (limited to '.vscode/launch.json') diff --git a/.vscode/launch.json b/.vscode/launch.json index 77e139dbd..829f8f492 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -52,7 +52,7 @@ "request": "attach", "name": "Typescript Server", "protocol": "inspector", - "port": 9230, + "port": 9229, "localRoot": "${workspaceFolder}", "remoteRoot": "${workspaceFolder}" }, diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index d9d985ca5..62a702a92 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -12,8 +12,9 @@ import { basename } from "path"; import { createIfNotExists } from './ActionUtilities'; import { ParsedPDF } from "../server/PdfTypes"; const parse = require('pdf-parse'); -import { Directory, serverPathToFile, clientPathToFile } from './ApiManagers/UploadManager'; +import { Directory, serverPathToFile, clientPathToFile, pathToDirectory } from './ApiManagers/UploadManager'; import { red } from 'colors'; +const requestImageSize = require("../client/util/request-image-size"); export enum SizeSuffix { Small = "_s", @@ -134,12 +135,13 @@ export namespace DashUploadUtils { }; export interface InspectionResults { - isLocal: boolean; - stream: any; - normalizedUrl: string; + source: string; + requestable: string; exifData: EnrichedExifData; - contentSize?: number; - contentType?: string; + contentSize: number; + contentType: string; + nativeWidth: number; + nativeHeight: number; } export interface EnrichedExifData { @@ -152,6 +154,12 @@ export namespace DashUploadUtils { return Promise.all(pending); } + export interface RequestedImageSize { + width: number; + height: number; + type: string; + } + /** * Based on the url's classification as local or remote, gleans * as much information as possible about the specified image @@ -159,24 +167,22 @@ export namespace DashUploadUtils { * @param source is the path or url to the image in question */ export const InspectImage = async (source: string): Promise => { - const { isLocal, stream, normalized: normalizedUrl } = classify(source); - const exifData = await parseExifData(source); + const url = convert(source); + const exifData = await parseExifData(url); const results = { exifData, - isLocal, - stream, - normalizedUrl + requestable: url }; - // stop here if local, since request.head() can't handle local paths, only urls on the web - if (isLocal) { - return results; - } const { headers } = (await new Promise((resolve, reject) => { - request.head(source, (error, res) => error ? reject(error) : resolve(res)); - })); + request.head(url, (error, res) => error ? reject(error) : resolve(res)); + }).catch(error => console.error(error))); + const { width: nativeWidth, height: nativeHeight }: RequestedImageSize = await requestImageSize(url); return { + source, contentSize: parseInt(headers[size]), contentType: headers[type], + nativeWidth, + nativeHeight, ...results }; }; @@ -192,9 +198,9 @@ export namespace DashUploadUtils { } export const UploadInspectedImage = async (metadata: InspectionResults, filename?: string, format?: string, prefix = ""): Promise => { - const { isLocal, stream, normalizedUrl, contentSize, contentType, exifData } = metadata; - const resolved = filename || generate(prefix, normalizedUrl); - const extension = format || sanitizeExtension(normalizedUrl || resolved); + const { requestable, source, contentSize, contentType, exifData } = metadata; + const resolved = filename || generate(prefix, requestable); + const extension = format || sanitizeExtension(requestable || resolved); const information: ImageUploadInformation = { clientAccessPath: clientPathToFile(Directory.images, resolved), serverAccessPaths: {}, @@ -220,27 +226,29 @@ export namespace DashUploadUtils { await new Promise(resolve => { const filename = InjectSize(resolved, suffix); information.serverAccessPaths[suffix] = serverPathToFile(Directory.images, filename); - stream(normalizedUrl).pipe(resizer).pipe(fs.createWriteStream(serverPathToFile(Directory.images, filename))) + request(requestable).pipe(resizer).pipe(fs.createWriteStream(serverPathToFile(Directory.images, filename))) .on('close', resolve) .on('error', reject); }); } - if (isLocal) { + if (source.includes("Dash-Web")) { await new Promise(resolve => { - fs.unlink(normalizedUrl, error => resolve(error === null)); + fs.unlink(source, error => resolve(error === null)); }); } resolve(information); }); }; - const classify = (url: string) => { - const isLocal = /Dash-Web(\\|\/)src(\\|\/)server(\\|\/)public(\\|\/)files/g.test(url); - return { - isLocal, - stream: isLocal ? fs.createReadStream : request, - normalized: isLocal ? path.normalize(url) : url - }; + const convert = (url: string) => { + let resolved: string; + const matches = /Dash-Web[\\\/]src[\\\/]server[\\\/]public[\\\/](.*)/.exec(url); + if (matches === null) { + resolved = url; + } else { + resolved = `http://localhost:1050/${matches[1].split("\\").join("/")}`; + } + return resolved; }; const parseExifData = async (source: string): Promise => { diff --git a/src/server/RouteManager.ts b/src/server/RouteManager.ts index 6bc75ca21..63e957cd1 100644 --- a/src/server/RouteManager.ts +++ b/src/server/RouteManager.ts @@ -180,7 +180,7 @@ export const STATUS = { }; export function _error(res: Response, message: string, error?: any) { - console.error(message); + console.error(message, error); res.statusMessage = message; res.status(STATUS.EXECUTION_ERROR).send(error); } -- cgit v1.2.3-70-g09d2