aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/ApiManagers/GooglePhotosManager.ts6
-rw-r--r--src/server/ApiManagers/UploadManager.ts14
-rw-r--r--src/server/DashStats.ts1
-rw-r--r--src/server/DashUploadUtils.ts65
-rw-r--r--src/server/SharedMediaTypes.ts4
-rw-r--r--src/server/index.ts1
-rw-r--r--src/server/websocket.ts5
7 files changed, 52 insertions, 44 deletions
diff --git a/src/server/ApiManagers/GooglePhotosManager.ts b/src/server/ApiManagers/GooglePhotosManager.ts
index 5feb25fd4..0970dee81 100644
--- a/src/server/ApiManagers/GooglePhotosManager.ts
+++ b/src/server/ApiManagers/GooglePhotosManager.ts
@@ -139,13 +139,13 @@
// const completed: Opt<Upload.ImageInformation>[] = [];
// for (const { baseUrl } of mediaItems) {
// // start by getting the content size of the remote image
-// const results = await DashUploadUtils.InspectImage(baseUrl);
-// if (results instanceof Error) {
+// const result = await DashUploadUtils.InspectImage(baseUrl);
+// if (result instanceof Error) {
// // if something went wrong here, we can't hope to upload it, so just move on to the next
// failed++;
// continue;
// }
-// const { contentSize, ...attributes } = results;
+// const { contentSize, ...attributes } = result;
// // check to see if we have uploaded a Google user content image *specifically via this route* already
// // that has this exact content size
// const found: Opt<Upload.ImageInformation> = await Database.Auxiliary.QueryUploadHistory(contentSize);
diff --git a/src/server/ApiManagers/UploadManager.ts b/src/server/ApiManagers/UploadManager.ts
index 4cb3d8baf..b2624f654 100644
--- a/src/server/ApiManagers/UploadManager.ts
+++ b/src/server/ApiManagers/UploadManager.ts
@@ -144,7 +144,7 @@ export default class UploadManager extends ApiManager {
ids[id] = uuid.v4();
return ids[id];
};
- const mapFn = (docIn: any) => {
+ const mapFn = (docIn: { id: string; fields: any[] }) => {
const doc = docIn;
if (doc.id) {
doc.id = getId(doc.id);
@@ -170,10 +170,10 @@ export default class UploadManager extends ApiManager {
mapFn(field);
} else if (typeof field === 'string') {
const re = /("(?:dataD|d)ocumentId"\s*:\s*")([\w-]*)"/g;
- doc.fields[key] = (field as any).replace(re, (match: any, p1: string, p2: string) => `${p1}${getId(p2)}"`);
+ doc.fields[key] = field.replace(re, (match: string, p1: string, p2: string) => `${p1}${getId(p2)}"`);
} else if (field.__type === 'RichTextField') {
const re = /("href"\s*:\s*")(.*?)"/g;
- field.Data = field.Data.replace(re, (match: any, p1: string, p2: string) => `${p1}${getId(p2)}"`);
+ field.Data = field.Data.replace(re, (match: string, p1: string, p2: string) => `${p1}${getId(p2)}"`);
}
}
};
@@ -192,7 +192,7 @@ export default class UploadManager extends ApiManager {
if (!f) continue;
const path2 = f[0]; // what about the rest of the array? are we guaranteed only one value is set?
const zip = new AdmZip(path2.filepath);
- zip.getEntries().forEach((entry: any) => {
+ zip.getEntries().forEach(entry => {
const entryName = entry.entryName.replace(/%%%/g, '/');
if (!entryName.startsWith('files/')) {
return;
@@ -245,7 +245,7 @@ export default class UploadManager extends ApiManager {
}
}
SolrManager.update();
- res.send(JSON.stringify({ id, docids, linkids } || 'error'));
+ res.send(JSON.stringify({ id, docids, linkids }) || 'error');
} catch (e) {
console.log(e);
}
@@ -282,8 +282,8 @@ export default class UploadManager extends ApiManager {
const serverPath = serverPathToFile(Directory.images, '');
const regex = new RegExp(`${deleteFiles}.*`);
fs.readdirSync(serverPath)
- .filter((f: any) => regex.test(f))
- .map((f: any) => fs.unlinkSync(serverPath + f));
+ .filter(f => regex.test(f))
+ .map(f => fs.unlinkSync(serverPath + f));
}
imageDataUri.outputFile(uri, serverPathToFile(Directory.images, InjectSize(filename, origSuffix))).then((savedName: string) => {
const ext = path.extname(savedName).toLowerCase();
diff --git a/src/server/DashStats.ts b/src/server/DashStats.ts
index 808d2c6f2..6b9fb8971 100644
--- a/src/server/DashStats.ts
+++ b/src/server/DashStats.ts
@@ -9,6 +9,7 @@ import { socketMap, timeMap, userOperations } from './SocketData';
* This includes time connected, number of operations, and
* the rate of their operations
*/
+// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace DashStats {
export const SAMPLING_INTERVAL = 1000; // in milliseconds (ms) - Time interval to update the frontend.
export const RATE_INTERVAL = 10; // in seconds (s) - Used to calculate rate
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts
index 08cea1de5..5e58db103 100644
--- a/src/server/DashUploadUtils.ts
+++ b/src/server/DashUploadUtils.ts
@@ -1,6 +1,7 @@
import axios from 'axios';
+import { spawn, exec } from 'child_process';
import { green, red } from 'colors';
-import { ExifImage } from 'exif';
+import { ExifData, ExifImage } from 'exif';
import * as exifr from 'exifr';
import * as ffmpeg from 'fluent-ffmpeg';
import * as formidable from 'formidable';
@@ -18,13 +19,11 @@ import { Duplex, Stream } from 'stream';
import { Utils } from '../Utils';
import { createIfNotExists } from './ActionUtilities';
import { AzureManager } from './ApiManagers/AzureManager';
-import { ParsedPDF } from './PdfTypes';
import { AcceptableMedia, Upload } from './SharedMediaTypes';
import { Directory, clientPathToFile, filesDirectory, pathToDirectory, publicDirectory, serverPathToFile } from './SocketData';
import { resolvedServerUrl } from './server_Initialization';
-const { spawn } = require('child_process');
-const { exec } = require('child_process');
+// eslint-disable-next-line @typescript-eslint/no-var-requires
const requestImageSize = require('../client/util/request-image-size');
export enum SizeSuffix {
@@ -48,6 +47,7 @@ function usingAzure() {
return process.env.USE_AZURE === 'true';
}
+// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace DashUploadUtils {
export interface Size {
width: number;
@@ -111,7 +111,7 @@ export namespace DashUploadUtils {
// .outputOptions('-c copy')
// .videoCodec("copy")
.save(outputFilePath)
- .on('error', (err: any) => {
+ .on('error', err => {
console.log(err);
reject();
})
@@ -130,8 +130,8 @@ export namespace DashUploadUtils {
}
function resolveExistingFile(name: string, pat: string, directory: Directory, mimetype?: string | null, duration?: number, rawText?: string): Upload.FileResponse<Upload.FileInformation> {
- const data = { size: 0, filepath: pat, name, type: mimetype ?? '', originalFilename: name, newFilename: path.basename(pat), mimetype: mimetype || null, hashAlgorithm: false as any };
- const file = { ...data, toJSON: () => ({ ...data, length: 0, filename: data.filepath.replace(/.*\//, ''), mtime: new Date(), mimetype: mimetype || null, toJson: () => undefined as any }) };
+ const data = { size: 0, filepath: pat, name, type: mimetype ?? '', originalFilename: name, newFilename: path.basename(pat), mimetype: mimetype || null, hashAlgorithm: false as falsetype };
+ const file = { ...data, toJSON: () => ({ ...data, length: 0, filename: data.filepath.replace(/.*\//, ''), mtime: new Date(), mimetype: mimetype || null }) };
return {
source: file || null,
result: {
@@ -184,11 +184,10 @@ export namespace DashUploadUtils {
const parseExifData = async (source: string) => {
const image = await request.get(source, { encoding: null });
- const { /* data, */ error } = await new Promise<{ data: any; error: any }>(resolve => {
+ const { /* data, */ error } = await new Promise<{ data: ExifData; error: string | undefined }>(resolve => {
// eslint-disable-next-line no-new
new ExifImage({ image }, (exifError, data) => {
- const reason = (exifError as any)?.code;
- resolve({ data, error: reason });
+ resolve({ data, error: exifError?.message });
});
});
return error ? { data: undefined, error } : { data: await exifr.parse(image), error };
@@ -252,11 +251,12 @@ export namespace DashUploadUtils {
};
// Use the request library to parse out file level image information in the headers
- const { headers } = await new Promise<any>((resolve, reject) => {
- request.head(resolvedUrl, (error, res) => (error ? reject(error) : resolve(res)));
+ const headerResult = await new Promise<{ headers: { [key: string]: string } }>((resolve, reject) => {
+ request.head(resolvedUrl, (error, res) => (error ? reject(error) : resolve(res as { headers: { [key: string]: string } })));
}).catch(e => {
console.log('Error processing headers: ', e);
});
+ const { headers } = headerResult !== null && typeof headerResult === 'object' ? headerResult : { headers: {} as { [key: string]: string } };
try {
// Compute the native width and height ofthe image with an npm module
@@ -272,9 +272,9 @@ export namespace DashUploadUtils {
filename,
...results,
};
- } catch (e: any) {
+ } catch (e: unknown) {
console.log(e);
- return e;
+ return new Error(e ? e.toString?.() : 'unkown error');
}
};
@@ -331,7 +331,7 @@ export namespace DashUploadUtils {
)); // prettier-ignore
return Jimp.read(imgBuffer)
- .then(async (imgIn: any) => {
+ .then(async imgIn => {
let img = imgIn;
await Promise.all( sizes.filter(({ width }) => width).map(({ width, suffix }) => {
img = img.resize(width, Jimp.AUTO).write(outputPath(suffix));
@@ -339,7 +339,7 @@ export namespace DashUploadUtils {
} )); // prettier-ignore
return writtenFiles;
})
- .catch((e: any) => {
+ .catch(e => {
console.log('ERROR' + e);
return writtenFiles;
});
@@ -432,15 +432,17 @@ export namespace DashUploadUtils {
* 4) the content type of the image, i.e. image/(jpeg | png | ...)
*/
export const UploadImage = async (source: string, filename?: string, prefix: string = ''): Promise<Upload.ImageInformation | Error> => {
- const metadata = await InspectImage(source);
- if (metadata instanceof Error) {
- return { name: metadata.name, message: metadata.message };
+ const result = await InspectImage(source);
+ if (result instanceof Error) {
+ return { name: result.name, message: result.message };
}
- const outputFile = filename || metadata.filename || '';
+ const outputFile = filename || result.filename || '';
- return UploadInspectedImage(metadata, outputFile, prefix);
+ return UploadInspectedImage(result, outputFile, prefix);
};
+ type md5 = 'md5';
+ type falsetype = false;
export function uploadYoutube(videoId: string, overwriteId: string): Promise<Upload.FileResponse> {
return new Promise<Upload.FileResponse<Upload.FileInformation>>(res => {
const name = videoId;
@@ -448,6 +450,7 @@ export namespace DashUploadUtils {
const finalPath = serverPathToFile(Directory.videos, filepath);
if (existsSync(finalPath)) {
uploadProgress.set(overwriteId, 'computing duration');
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
exec(`yt-dlp -o ${finalPath} "https://www.youtube.com/watch?v=${videoId}" --get-duration`, (error: any, stdout: any /* , stderr: any */) => {
const time = Array.from(stdout.trim().split(':')).reverse();
const duration = (time.length > 2 ? Number(time[2]) * 1000 * 60 : 0) + (time.length > 1 ? Number(time[1]) * 60 : 0) + (time.length > 0 ? Number(time[0]) : 0);
@@ -457,14 +460,17 @@ export namespace DashUploadUtils {
uploadProgress.set(overwriteId, 'starting download');
const ytdlp = spawn(`yt-dlp`, ['-o', filepath, `https://www.youtube.com/watch?v=${videoId}`, '--max-filesize', '100M', '-f', 'mp4']);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
ytdlp.stdout.on('data', (data: any) => uploadProgress.set(overwriteId, data.toString()));
let errors = '';
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
ytdlp.stderr.on('data', (data: any) => {
uploadProgress.set(overwriteId, 'error:' + data.toString());
errors = data.toString();
});
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
ytdlp.on('exit', (code: any) => {
if (code) {
res({
@@ -484,8 +490,8 @@ export namespace DashUploadUtils {
exec(`yt-dlp-o ${filepath} "https://www.youtube.com/watch?v=${videoId}" --get-duration`, (/* error: any, stdout: any, stderr: any */) => {
// const time = Array.from(stdout.trim().split(':')).reverse();
// const duration = (time.length > 2 ? Number(time[2]) * 1000 * 60 : 0) + (time.length > 1 ? Number(time[1]) * 60 : 0) + (time.length > 0 ? Number(time[0]) : 0);
- const data = { size: 0, filepath, name, mimetype: 'video', originalFilename: name, newFilename: name, hashAlgorithm: 'md5' as 'md5', type: 'video/mp4' };
- const file = { ...data, toJSON: () => ({ ...data, length: 0, filename: data.filepath.replace(/.*\//, ''), mtime: new Date(), toJson: () => undefined as any }) };
+ const data = { size: 0, filepath, name, mimetype: 'video', originalFilename: name, newFilename: name, hashAlgorithm: 'md5' as md5, type: 'video/mp4' };
+ const file = { ...data, toJSON: () => ({ ...data, length: 0, filename: data.filepath.replace(/.*\//, ''), mtime: new Date() }) };
MoveParsedFile(file, Directory.videos).then(output => res(output));
});
}
@@ -517,15 +523,15 @@ export namespace DashUploadUtils {
});
}
const dataBuffer = readFileSync(file.filepath);
- const result: ParsedPDF | any = await parse(dataBuffer).catch((e: any) => e);
- if (!result.code) {
+ const result: parse.Result = await parse(dataBuffer).catch(e => e);
+ if (result) {
await new Promise<void>((resolve, reject) => {
const writeStream = createWriteStream(serverPathToFile(Directory.text, textFilename));
writeStream.write(result?.text, error => (error ? reject(error) : resolve()));
});
return MoveParsedFile(file, Directory.pdfs, undefined, result?.text, undefined, fileKey);
}
- return { source: file, result: { name: 'faile pdf pupload', message: `Could not upload (${file.originalFilename}).${result.message}` } };
+ return { source: file, result: { name: 'faile pdf pupload', message: `Could not upload (${file.originalFilename}).${result}` } };
}
async function UploadCsv(file: File) {
@@ -563,7 +569,7 @@ export namespace DashUploadUtils {
.videoCodec('copy') // this will copy the data instead of reencode it
.save(vidFile.filepath.replace('.mkv', '.mp4'))
.on('end', res)
- .on('error', (e: any) => console.log(e));
+ .on('error', console.log);
});
vidFile.filepath = vidFile.filepath.replace('.mkv', '.mp4');
format = '.mp4';
@@ -571,8 +577,9 @@ export namespace DashUploadUtils {
if (format.includes('quicktime')) {
let abort = false;
await new Promise<void>(res => {
- ffmpeg.ffprobe(vidFile.filepath, (err: any, metadata: any) => {
- if (metadata.streams.some((stream: any) => stream.codec_name === 'hevc')) {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ ffmpeg.ffprobe(vidFile.filepath, (err: any, metadata: ffmpeg.FfprobeData) => {
+ if (metadata.streams.some(stream => stream.codec_name === 'hevc')) {
abort = true;
}
res();
diff --git a/src/server/SharedMediaTypes.ts b/src/server/SharedMediaTypes.ts
index 8ae13454e..680db9cd0 100644
--- a/src/server/SharedMediaTypes.ts
+++ b/src/server/SharedMediaTypes.ts
@@ -1,6 +1,7 @@
import { ExifData } from 'exif';
import { File } from 'formidable';
+// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace AcceptableMedia {
export const gifs = ['.gif'];
export const pngs = ['.png'];
@@ -18,6 +19,7 @@ export enum AudioAnnoState {
playing = 'playing',
}
+// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Upload {
export function isImageInformation(uploadResponse: Upload.FileInformation): uploadResponse is Upload.ImageInformation {
return 'nativeWidth' in uploadResponse;
@@ -36,7 +38,7 @@ export namespace Upload {
duration?: number;
}
export interface EnrichedExifData {
- data: ExifData & ExifData['gps'];
+ data: ExifData & ExifData['gps'] & { Orientation?: string };
error?: string;
}
export interface InspectionResults {
diff --git a/src/server/index.ts b/src/server/index.ts
index 3151c2975..3e0d86814 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -29,7 +29,6 @@ import initializeServer from './server_Initialization';
dotenv.config();
export const onWindows = process.platform === 'win32';
-// eslint-disable-next-line import/no-mutable-exports
export let sessionAgent: AppliedSessionAgent;
/**
diff --git a/src/server/websocket.ts b/src/server/websocket.ts
index cece8a1b7..821607df5 100644
--- a/src/server/websocket.ts
+++ b/src/server/websocket.ts
@@ -16,12 +16,11 @@ import YoutubeApi from './apis/youtube/youtubeApiSample';
import { initializeGuest } from './authentication/DashUserModel';
import { Database } from './database';
+// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace WebSocket {
let CurUser: string | undefined;
- // eslint-disable-next-line import/no-mutable-exports
export let _socket: Socket;
- // eslint-disable-next-line import/no-mutable-exports
- export let _disconnect: Function;
+ export let _disconnect: () => void;
export const clients: { [key: string]: Client } = {};
function processGesturePoints(socket: Socket, content: GestureContent) {