server is running with modules!

This commit is contained in:
Michael Peters 2022-07-05 18:46:05 -05:00
parent 3aa0866aa3
commit c0c7e18471
63 changed files with 3449 additions and 3369 deletions

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import { ReactNode } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import { Changes, GuildMetadata, Member, Message, Resource } from "../../data-types";

View File

@ -3,9 +3,9 @@ const crypto = require('crypto');
const pg = require('pg');
const ExitCodes = require('../../exit-codes/exit-codes.js');
const ExitCodes = require('../../exit-codes.js');
const LOG = require('../../logger/logger.js')('reg');
const LOG = require('../../logger.js')('reg');
// Adds a member to a server based on its public key
// (the opposite of registering with a registration file)

View File

@ -1,5 +1,5 @@
const DBCache = require('../webapp/db-cache.js');
const LOG = require('../../logger/logger.js')('init-db');
const LOG = require('../../logger.js')('init-db');
let configs = [
{

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import { useCallback, useEffect, useRef } from "react";

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, useEffect, useState } from 'react';

View File

@ -0,0 +1,27 @@
for await (const file of getAllFiles(path.join(__dirname, ".."))) {
if (!file.endsWith(".js")) continue;
if (
!(await fs
.stat(file + ".map")
.then(() => true)
.catch(() => false))
)
continue; // make sure .map file exists
const fileBuff = await fs.readFile(file + ".map");
if (URL && URL.createObjectURL) {
// only run this stuff if we are running in a browser window
const mappingsWasmBuffer = await fs.readFile(
path.join(__dirname, "../../node_modules/source-map/lib/mappings.wasm")
);
const mappingsWasmBlob = new Blob([mappingsWasmBuffer], {
type: "application/wasm",
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore Typescript is missing this function... Probably because it is static
sourceMapConsumer.initialize({
"lib/mappings.wasm": URL.createObjectURL(mappingsWasmBlob),
});
}
const sourceMapConsumer = await new SourceMapConsumer(fileBuff.toString());
sourceMaps.set(file, sourceMapConsumer);
}

6236
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
{
"name": "cordis-ts",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "index.js",
@ -8,16 +9,15 @@
"license": "ISC",
"dependencies": {
"@electron/remote": "^2.0.1",
"@types/stack-trace": "^0.0.29",
"colors": "^1.4.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-react-hooks": "^4.3.0",
"file-type": "^16.5.3",
"file-type": "^17.1.2",
"image-size": "^1.0.0",
"moment": "^2.29.1",
"pg": "^8.7.1",
"react-contenteditable": "^3.3.6",
"recoil": "^0.5.2",
"recoil": "^0.7.4",
"sass": "^1.43.4",
"sharp": "^0.30.4",
"socket.io": "^4.3.1",
@ -29,24 +29,24 @@
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/node": "^16.11.4",
"@types/jest": "^28.1.3",
"@types/node": "^18.0.0",
"@types/pg": "^8.6.1",
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"@types/sharp": "^0.29.2",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@types/sharp": "^0.30.4",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"electron": "^15.3.0",
"electron": "^19.0.6",
"eslint": "^8.4.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-unused-imports": "^2.0.0",
"jest": "^27.4.0",
"jest": "^28.1.1",
"prettier": "^2.5.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"ts-jest": "^27.0.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"ts-jest": "^28.0.5",
"typescript": "^4.4.4"
}
}

View File

@ -1,4 +1,4 @@
import Logger from '../logger/logger';
import Logger from '../logger';
const LOG = Logger.create(__filename);
LOG.silly('main begins');
@ -6,7 +6,7 @@ LOG.silly('main begins');
import * as path from 'path';
import * as electron from 'electron';
import { ExitCodes, ExitCode } from '../exit-codes/exit-codes';
import { ExitCodes, ExitCode } from '../exit-codes';
process.on('unhandledRejection', (reason: unknown, _promise: Promise<unknown>) => {
LOG.fatal('unhandled promise rejection:', reason);

View File

@ -1,6 +1,6 @@
//import * as electronRemote from '@electron/remote';
//const electronConsole = electronRemote.getGlobal('console') as Console;
//import Logger from '../../logger/logger';
//import Logger from '../../logger';
//const LOG = Logger.create(__filename, electronConsole);
import { AutoVerifier, AutoVerifierChangesType } from './auto-verifier';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import { Changes, WithEquals } from './data-types';

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import moment from 'moment';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import electron from 'electron';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, useEffect, useMemo, useState } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { Dispatch, DragEvent, FC, SetStateAction, useCallback, useRef } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, ReactNode } from 'react';

View File

@ -1,12 +1,12 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, useEffect, useRef } from 'react';
import ElementsUtil from '../require/elements-util';
import * as FileType from 'file-type';
import { fileTypeFromBuffer } from 'file-type';
import { useIsMountedRef, useOneTimeAsyncAction } from '../require/react-helper';
interface ImageEditInputProps {
@ -74,7 +74,7 @@ const ImageEditInput: FC<ImageEditInputProps> = (props: ImageEditInputProps) =>
return;
}
const buff = Buffer.from(await file.arrayBuffer());
const typeResult = await FileType.fromBuffer(buff);
const typeResult = await fileTypeFromBuffer(buff);
if (!typeResult || !acceptedExtTypes.includes(typeResult.ext)) {
e.target.value = '';
setMessage(`Invalid image type. Accepted types: ${acceptedExtTypes.join(', ')}`);

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, Ref, useEffect, useMemo } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, ReactNode, RefObject, useCallback, useEffect } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import moment from 'moment';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, ReactNode, RefObject, useCallback, useMemo } from 'react';

View File

@ -1,13 +1,13 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, useMemo } from 'react';
import * as electron from 'electron';
import { useAsyncSubmitButton, useDownloadButton } from '../require/react-helper';
import ContextMenu from './components/context-menu';
import * as FileType from 'file-type';
import { fileTypeFromBuffer } from 'file-type';
import sharp from 'sharp';
export interface ImageContextMenuProps {
@ -27,7 +27,7 @@ const ImageContextMenu: FC<ImageContextMenuProps> = (props: ImageContextMenuProp
const [copyCallable, copyText, copyShaking] = useAsyncSubmitButton(
async () => {
const type = await FileType.fromBuffer(resourceBuff);
const type = await fileTypeFromBuffer(resourceBuff);
if (!type) {
return { result: null, errorMessage: 'Unable to get file type' };
}

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, useEffect, useMemo, useState } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { Dispatch, FC, SetStateAction, useCallback, useEffect, useMemo, useState } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../../logger/logger';
import Logger from '../../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, MouseEvent, ReactNode, useCallback, useRef } from 'react';

View File

@ -13,7 +13,7 @@ import {
} from '../../require/atoms';
import ElementsUtil, { IAlignment } from '../../require/elements-util';
import { isLoaded } from '../../require/loadables';
import { useContextClickContextMenu, useDownloadButton, useOneTimeAsyncAction } from '../../require/react-helper';
import { useContextClickContextMenu, useDownloadButton } from '../../require/react-helper';
interface ResourceElementProps {
guild: CombinedGuild;

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, useMemo } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, useEffect, useMemo, useRef } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, ReactNode, useEffect, useMemo, useRef, useState } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, ReactNode, useEffect, useMemo, useRef, useState } from 'react';

View File

@ -1,9 +1,9 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, useCallback, useMemo, useRef } from 'react';
import React, { FC, useMemo, useRef } from 'react';
import CombinedGuild from '../../guild-combined';
import ElementsUtil, { IAlignment } from '../require/elements-util';
import DownloadButton from '../components/button-download';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { createRef, FC, MutableRefObject, ReactNode, useEffect, useMemo, useRef, useState } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import { AtomEffect, Loadable, RecoilValue, useRecoilValueLoadable } from 'recoil';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import { ReactNode, useEffect } from 'react';

View File

@ -3,10 +3,10 @@ import * as fs from 'fs/promises';
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import * as FileType from 'file-type';
import { fileTypeFromBuffer } from 'file-type';
import * as uuid from 'uuid';
import Util from '../../util';
@ -62,7 +62,7 @@ export default class ElementsUtil {
/** gets a string compatible with an <img> src attribute */
static async getImageBufferSrc(buffer: Buffer): Promise<string> {
const result = await FileType.fromBuffer(buffer);
const result = await fileTypeFromBuffer(buffer);
switch (result && result.mime) {
case 'image/png':
case 'image/jpeg':

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import {

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, ReactNode, useRef } from 'react';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole);
import React, { FC, useEffect, useState } from 'react';

View File

@ -18,7 +18,7 @@ import {
useIsMountedRef,
useOneTimeAsyncAction,
} from '../require/react-helper';
import * as FileType from 'file-type';
import { fileTypeFromBuffer } from 'file-type';
import ElementsUtil from '../require/elements-util';
import FileInput from '../components/input-file';
@ -33,7 +33,7 @@ const AttachmentPreview: FC<AttachmentPreviewProps> = (props: AttachmentPreviewP
const [attachmentImgSrc] = useOneTimeAsyncAction(
async () => {
const type = await FileType.fromBuffer(attachmentBuff);
const type = await fileTypeFromBuffer(attachmentBuff);
if (!type) return './img/file-improved.svg';
if (type.mime === 'image/gif' || type.mime === 'image/jpeg' || type.mime === 'image/png') {
// show a preview of the image

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import { Changes, Channel, GuildMetadata, Member, Message, Resource, Token } from './data-types';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import * as socketio from 'socket.io-client';

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import * as socketio from 'socket.io-client';

View File

@ -3,10 +3,10 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import * as socketio from 'socket.io-client';
import { io, Socket } from 'socket.io-client';
import * as crypto from 'crypto';
@ -66,7 +66,7 @@ export default class GuildsManager extends EventEmitter<{
}
}
static _socketEmitTimeout(socket: socketio.Socket, ms: number, name: string, ...args: any[]) {
static _socketEmitTimeout(socket: Socket, ms: number, name: string, ...args: any[]) {
// see also client-controller.js
const socketArgs = args.slice(0, args.length - 1);
const respond = args[args.length - 1];
@ -90,8 +90,8 @@ export default class GuildsManager extends EventEmitter<{
const { name, url, cert, token } = guildConfig;
LOG.debug('Adding new server', { name, url, cert, token, displayName, avatarBuff });
const socket = await new Promise<socketio.Socket>((resolve, reject) => {
const socket = socketio.connect(url, {
const socket = await new Promise<Socket>((resolve, reject) => {
const socket = io(url, {
forceNew: true,
ca: cert, // verifies the server's identity
reconnection: false, // a bit stricter for registration

View File

@ -3,7 +3,7 @@ import Globals from './globals';
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import { AutoVerifierWithArg, PartialMessageListQuery } from './auto-verifier-with-args';

View File

@ -1,11 +1,11 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import * as crypto from 'crypto';
import ConcurrentQueue from '../../concurrent-queue/concurrent-queue';
import ConcurrentQueue from '../../concurrent-queue';
import * as sqlite from 'sqlite';
import * as sqlite3 from 'sqlite3';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
LOG.silly('preload begins');

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import * as crypto from 'crypto';

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger';
import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole);
import * as fs from 'fs/promises';

View File

@ -1,4 +1,4 @@
import Logger from '../logger/logger';
import Logger from '../logger/index.js';
const LOG = Logger.create('exit');
export enum ExitCode {

View File

@ -1,4 +1,4 @@
import Logger from './logger';
import Logger from './';
const LOG = Logger.create(__filename);

View File

@ -3,14 +3,17 @@ import * as path from 'path';
import * as fs from 'fs/promises';
import moment from 'moment';
import colors from 'colors/safe';
import colors from 'colors/safe.js';
import { SourceMapConsumer } from 'source-map';
import * as StackTrace from '../stack-trace/stack-trace';
import * as StackTrace from '../stack-trace/stack-trace.js';
const LINE_NUM_LENGTH = 3;
const MAX_FILE_NAME_PADDING = 22;
const __filename = new URL(import.meta.url).pathname;
const __dirname = path.dirname(__filename);
const baseDir = path.join(__dirname, '..', '..');
/** adds padding to the left of a string */
@ -96,7 +99,7 @@ async function getStaticSourceMaps(): Promise<Map<string, SourceMapConsumer>> {
} else {
STATIC_SOURCE_MAPS_LOADING = true;
const sourceMaps = new Map<string, SourceMapConsumer>();
for await (const file of getAllFiles(path.join(__dirname, '..'))) {
for await (const file of getAllFiles(__dirname)) {
if (!file.endsWith('.js')) continue;
if (
!(await fs
@ -106,16 +109,16 @@ async function getStaticSourceMaps(): Promise<Map<string, SourceMapConsumer>> {
)
continue; // make sure .map file exists
const fileBuff = await fs.readFile(file + '.map');
if (URL && URL.createObjectURL) {
// only run this stuff if we are running in a browser window
const mappingsWasmBuffer = await fs.readFile(
path.join(__dirname, '../../node_modules/source-map/lib/mappings.wasm'),
);
const mappingsWasmBlob = new Blob([mappingsWasmBuffer], { type: 'application/wasm' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore Typescript is missing this function... Probably because it is static
SourceMapConsumer.initialize({ 'lib/mappings.wasm': URL.createObjectURL(mappingsWasmBlob) });
}
// if (URL && URL.createObjectURL) {
// // only run this stuff if we are running in a browser window
// const mappingsWasmBuffer = await fs.readFile(
// path.join(__dirname, '../../node_modules/source-map/lib/mappings.wasm'),
// );
// const mappingsWasmBlob = new Blob([mappingsWasmBuffer], { type: 'application/wasm' });
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// //@ts-ignore Typescript is missing this function... Probably because it is static
// sourceMapConsumer.initialize({ 'lib/mappings.wasm': URL.createObjectURL(mappingsWasmBlob) });
// }
const sourceMapConsumer = await new SourceMapConsumer(fileBuff.toString());
sourceMaps.set(file, sourceMapConsumer);
}

View File

@ -4,14 +4,17 @@ import * as path from 'path';
import * as fs from 'fs';
import * as socketio from 'socket.io';
import { ExitCodes, ExitCode } from '../exit-codes/exit-codes';
import Logger from '../logger/logger';
import { ExitCodes, ExitCode } from '../exit-codes/index.js';
import Logger from '../logger/index.js';
import * as controller from './server-controller';
import DB from './db';
import * as controller from './server-controller.js';
import DB from './db.js';
const LOG = Logger.create('app');
const __filename = new URL(import.meta.url).pathname;
const __dirname = path.dirname(__filename);
const server = https.createServer({
cert: fs.readFileSync(path.join(__dirname, 'ssl/cert.pem')).toString(),
key: fs.readFileSync(path.join(__dirname, 'ssl/key.pem')).toString(),

View File

@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as crypto from 'crypto';
import * as pg from 'pg';
import pg from 'pg';
import * as uuid from 'uuid';
import ConcurrentQueue from '../concurrent-queue/concurrent-queue';
import Logger from '../logger/logger';
import ConcurrentQueue from '../concurrent-queue/index.js';
import Logger from '../logger/index.js';
const LOG = Logger.create('db');

View File

@ -1,13 +1,15 @@
import * as fs from 'fs/promises';
import * as path from 'path';
import * as FileType from 'file-type';
import { fileTypeFromBuffer } from 'file-type';
import { ExitCodes, ExitCode } from '../../exit-codes/exit-codes';
import Logger from '../../logger/logger';
import { ExitCodes, ExitCode } from '../../exit-codes/index.js';
import Logger from '../../logger/index.js';
import DB from '../db';
import DB from '../db.js';
const __filename = new URL(import.meta.url).pathname;
const __dirname = path.dirname(__filename);
const LOG = Logger.create(__filename);
const serverName = process.argv[2] || 'no chicoms';
@ -21,7 +23,7 @@ process.on('unhandledRejection', async (reason, _promise) => {
// from ElementsUtil
async function getImageBufferSrc(buffer: Buffer) {
const result = await FileType.fromBuffer(buffer);
const result = await fileTypeFromBuffer(buffer);
switch (result && result.mime) {
case 'image/png':
case 'image/jpeg':

View File

@ -1,5 +1,5 @@
import { ExitCode, ExitCodes } from '../../exit-codes/exit-codes';
import Logger from '../../logger/logger';
import { ExitCode, ExitCodes } from '../../exit-codes';
import Logger from '../../logger';
import DB from '../db';
const LOG = Logger.create('setup-test-guild');

View File

@ -1,5 +1,5 @@
import { ExitCode, ExitCodes } from '../../exit-codes/exit-codes';
import Logger from '../../logger/logger';
import { ExitCode, ExitCodes } from '../../exit-codes';
import Logger from '../../logger';
import DB from '../db';
const LOG = Logger.create('setup-test-guild');

View File

@ -1,12 +1,17 @@
import * as fs from 'fs/promises';
import * as path from 'path';
import * as pg from 'pg';
import pg from 'pg';
import { ExitCodes, ExitCode } from '../../exit-codes/exit-codes';
import Logger from '../../logger/logger';
import { ExitCodes, ExitCode } from '../../exit-codes/index.js';
import Logger from '../../logger/index.js';
const LOG = Logger.create(__filename);
console.log('creating log');
const LOG = Logger.create(import.meta.url);
console.log('created log');
const __filename = new URL(import.meta.url).pathname;
const __dirname = path.dirname(__filename);
// TODO: remove db in favor of DB.js
const db = new pg.Client({
@ -16,97 +21,249 @@ const db = new pg.Client({
database: 'cordis',
});
process.on('unhandledRejection', async (reason, promise) => {
process.on('unhandledRejection', (reason, promise) => {
LOG.error('unhandled promise rejection:', reason);
LOG.error('promise:', promise);
ExitCodes.exit(ExitCode.GENERAL_ERROR);
});
(async () => {
LOG.debug('connecting...');
try {
await db.connect();
try {
await db.query('BEGIN');
} catch (e: unknown) {
LOG.fatal('unable to connect to database');
ExitCodes.exit(ExitCode.GENERAL_ERROR);
}
LOG.debug('db.connect is done');
// note: Order matters
await db.query('DELETE FROM "messages"');
await db.query('DELETE FROM "channels"');
await db.query('DELETE FROM "members"');
await db.query('DELETE FROM "guilds_meta"');
await db.query('DELETE FROM "resources"');
await db.query('DELETE FROM "guilds"');
try {
await db.query('BEGIN');
LOG.debug('begun transaction');
const icon1Buff = await fs.readFile(path.join(__dirname, 'resources/icon-no-chicoms.png'));
const icon2Buff = await fs.readFile(path.join(__dirname, 'resources/icon-literally-heaven.png'));
// note: Order matters
await db.query('DELETE FROM "messages"');
await db.query('DELETE FROM "channels"');
await db.query('DELETE FROM "members"');
await db.query('DELETE FROM "guilds_meta"');
await db.query('DELETE FROM "resources"');
await db.query('DELETE FROM "guilds"');
const server1Result = await db.query('INSERT INTO "guilds" ("id") VALUES (DEFAULT) RETURNING "id"');
LOG.debug('getting icon buffers...');
const icon1Buff = await fs.readFile(path.join(__dirname, 'resources/icon-no-chicoms.png'));
const icon2Buff = await fs.readFile(path.join(__dirname, 'resources/icon-literally-heaven.png'));
LOG.debug('got icon buffers');
const server1Id = server1Result.rows[0].id;
const icon1Result = await db.query('INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"', [server1Id, icon1Buff]);
const icon1ResourceId = icon1Result.rows[0].id;
const server1Result = await db.query('INSERT INTO "guilds" ("id") VALUES (DEFAULT) RETURNING "id"');
await db.query('INSERT INTO "guilds_meta" ("id", "name", "icon_resource_id") VALUES ($1, $2, $3)', [server1Id, 'no chicoms', icon1ResourceId]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 1, 'general', 'Some testing flavor text']);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 2, 'vocabulary', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 3, 'gear', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 4, 'memes', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 5, 'apocalypse', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 6, 'wisdom', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 7, 'footage', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 8, 'burger-chicken', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 9, 'handles', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 10, 'handles-link', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 11, 'workout', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 12, 'montage', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 13, 'epic-gamers', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 14, 'scams', null]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 15, 'bot-commands', null]);
const server1Id = server1Result.rows[0].id;
const icon1Result = await db.query(
'INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"',
[server1Id, icon1Buff],
);
const icon1ResourceId = icon1Result.rows[0].id;
// some dummy members
const avatar1Buff = await fs.readFile(path.join(__dirname, '/resources/avatar-1.png'));
const avatar1Result = await db.query('INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"', [server1Id, avatar1Buff]);
const avatar1Id = avatar1Result.rows[0].id;
await db.query('INSERT INTO "members" ("guild_id", "public_key", "display_name", "avatar_resource_id") VALUES ($1, $2, $3, $4)', [server1Id, 'dummy public key 1', 'AndrewSfeir', avatar1Id]);
await db.query('INSERT INTO "guilds_meta" ("id", "name", "icon_resource_id") VALUES ($1, $2, $3)', [
server1Id,
'no chicoms',
icon1ResourceId,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
1,
'general',
'Some testing flavor text',
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
2,
'vocabulary',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
3,
'gear',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
4,
'memes',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
5,
'apocalypse',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
6,
'wisdom',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
7,
'footage',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
8,
'burger-chicken',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
9,
'handles',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
10,
'handles-link',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
11,
'workout',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
12,
'montage',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
13,
'epic-gamers',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
14,
'scams',
null,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server1Id,
15,
'bot-commands',
null,
]);
const avatar2Buff = await fs.readFile(path.join(__dirname, '/resources/avatar-2.png'));
const avatar2Result = await db.query('INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"', [server1Id, avatar2Buff]);
const avatar2Id = avatar2Result.rows[0].id;
await db.query('INSERT INTO "members" ("guild_id", "public_key", "display_name", "avatar_resource_id") VALUES ($1, $2, $3, $4)', [server1Id, 'dummy public key 2', 'Danbot', avatar2Id]);
// some dummy members
const avatar1Buff = await fs.readFile(path.join(__dirname, '/resources/avatar-1.png'));
const avatar1Result = await db.query(
'INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"',
[server1Id, avatar1Buff],
);
const avatar1Id = avatar1Result.rows[0].id;
await db.query(
'INSERT INTO "members" ("guild_id", "public_key", "display_name", "avatar_resource_id") VALUES ($1, $2, $3, $4)',
[server1Id, 'dummy public key 1', 'AndrewSfeir', avatar1Id],
);
const avatar3Buff = await fs.readFile(path.join(__dirname, '/resources/avatar-3.png'));
const avatar3Result = await db.query('INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"', [server1Id, avatar3Buff]);
const avatar3Id = avatar3Result.rows[0].id;
await db.query('INSERT INTO "members" ("guild_id", "public_key", "display_name", "avatar_resource_id") VALUES ($1, $2, $3, $4)', [server1Id, 'dummy public key 3', 'gamer321', avatar3Id]);
const avatar2Buff = await fs.readFile(path.join(__dirname, '/resources/avatar-2.png'));
const avatar2Result = await db.query(
'INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"',
[server1Id, avatar2Buff],
);
const avatar2Id = avatar2Result.rows[0].id;
await db.query(
'INSERT INTO "members" ("guild_id", "public_key", "display_name", "avatar_resource_id") VALUES ($1, $2, $3, $4)',
[server1Id, 'dummy public key 2', 'Danbot', avatar2Id],
);
// an admin role
await db.query("INSERT INTO roles (guild_id, name, color) VALUES ($1, 'admin', '#ff0000')", [server1Id]);
const avatar3Buff = await fs.readFile(path.join(__dirname, '/resources/avatar-3.png'));
const avatar3Result = await db.query(
'INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"',
[server1Id, avatar3Buff],
);
const avatar3Id = avatar3Result.rows[0].id;
await db.query(
'INSERT INTO "members" ("guild_id", "public_key", "display_name", "avatar_resource_id") VALUES ($1, $2, $3, $4)',
[server1Id, 'dummy public key 3', 'gamer321', avatar3Id],
);
// a lot of dummy members (25) with the same avatar
// let avatarDefaultBuff = await fs.readFile('./avatar-default.png');
// let avatarDefaultResult = await db.query('INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"', [ server1Id, avatarDefaultBuff ]);
// let avatarDefaultId = avatarDefaultResult.rows[0].id;
// for (let i = 0; i < 25; ++i) {
// await db.query('INSERT INTO "members" ("guild_id", "public_key", "display_name", "avatar_resource_id") VALUES ($1, $2, $3, $4)', [ server1Id, 'dummy default public key ' + i, 'Dummy Member #' + i, avatarDefaultId ]);
// }
// an admin role
await db.query("INSERT INTO roles (guild_id, name, color) VALUES ($1, 'admin', '#ff0000')", [server1Id]);
const server2Result = await db.query('INSERT INTO "guilds" ("id") VALUES (DEFAULT) RETURNING "id"');
const server2Id = server2Result.rows[0].id;
const icon2Result = await db.query('INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"', [server2Id, icon2Buff]);
const icon2ResourceId = icon2Result.rows[0].id;
await db.query('INSERT INTO "guilds_meta" ("id", "name", "icon_resource_id") VALUES ($1, $2, $3)', [server2Id, 'Literally Heaven', icon2ResourceId]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server2Id, 1, 'general', 'The Ghost of Christmas Past.']);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server2Id, 2, 'art', 'Green is not a creative color.']);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server2Id, 3, 'quote-wall', 'Like a slowly updating history book.']);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server2Id, 4, 'tbd', 'This channel is to be determined.']);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server2Id, 5, 'robbies-corner', 'The signed original.']);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server2Id, 6, 'zanes-wing', 'Still Literally, Zane the Man.']);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server2Id, 7, 'the-voiceless', "For voiceless people who can't use or don't have a mic."]);
// a lot of dummy members (25) with the same avatar
// let avatarDefaultBuff = await fs.readFile('./avatar-default.png');
// let avatarDefaultResult = await db.query('INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"', [ server1Id, avatarDefaultBuff ]);
// let avatarDefaultId = avatarDefaultResult.rows[0].id;
// for (let i = 0; i < 25; ++i) {
// await db.query('INSERT INTO "members" ("guild_id", "public_key", "display_name", "avatar_resource_id") VALUES ($1, $2, $3, $4)', [ server1Id, 'dummy default public key ' + i, 'Dummy Member #' + i, avatarDefaultId ]);
// }
await db.query('COMMIT');
const server2Result = await db.query('INSERT INTO "guilds" ("id") VALUES (DEFAULT) RETURNING "id"');
const server2Id = server2Result.rows[0].id;
const icon2Result = await db.query(
'INSERT INTO "resources" ("guild_id", "hash", "data") VALUES ($1, digest($2::bytea, \'sha256\'), $2::bytea) RETURNING "id"',
[server2Id, icon2Buff],
);
const icon2ResourceId = icon2Result.rows[0].id;
await db.query('INSERT INTO "guilds_meta" ("id", "name", "icon_resource_id") VALUES ($1, $2, $3)', [
server2Id,
'Literally Heaven',
icon2ResourceId,
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server2Id,
1,
'general',
'The Ghost of Christmas Past.',
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server2Id,
2,
'art',
'Green is not a creative color.',
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server2Id,
3,
'quote-wall',
'Like a slowly updating history book.',
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server2Id,
4,
'tbd',
'This channel is to be determined.',
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server2Id,
5,
'robbies-corner',
'The signed original.',
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server2Id,
6,
'zanes-wing',
'Still Literally, Zane the Man.',
]);
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [
server2Id,
7,
'the-voiceless',
"For voiceless people who can't use or don't have a mic.",
]);
LOG.info(`server 1 initialized as g#${server1Id}`);
LOG.info(`server 2 initialized as g#${server2Id}`);
} catch (e) {
await db.query('ROLLBACK');
LOG.error('error setting up test database', e);
}
await db.end();
})();
await db.query('COMMIT');
LOG.info(`server 1 initialized as g#${server1Id}`);
LOG.info(`server 2 initialized as g#${server2Id}`);
} catch (e) {
await db.query('ROLLBACK');
LOG.error('error setting up test database', e);
}
await db.end();

View File

@ -6,13 +6,13 @@ import * as crypto from 'crypto';
import moment from 'moment';
import sizeOf from 'image-size';
import * as FileType from 'file-type';
import { fileTypeFromBuffer } from 'file-type';
import sharp from 'sharp';
import * as socketio from 'socket.io';
import Logger from '../logger/logger';
import Logger from '../logger/index.js';
import DB from './db';
import DB from './db.js';
const LOG = Logger.create('db');
@ -184,7 +184,7 @@ function bindRegistrationEvents(io: socketio.Server, client: socketio.Socket): v
throw new EventError('invalid avatar');
}
const typeResult = await FileType.fromBuffer(avatarBuff);
const typeResult = await fileTypeFromBuffer(avatarBuff);
if (!typeResult || ['image/png', 'image/jpeg', 'image/jpg'].indexOf(typeResult.mime) === -1) {
throw new EventError('invalid avatar mime type');
}
@ -370,7 +370,7 @@ function bindAdminEvents(io: socketio.Server, client: socketio.Socket, identity:
LOG.debug(`g#${identity.guildId} u#${identity.memberId?.slice(0, 4)} set-icon`);
const typeResult = await FileType.fromBuffer(iconBuff);
const typeResult = await fileTypeFromBuffer(iconBuff);
if (!typeResult || !['image/png', 'image/jpeg', 'image/jpg'].includes(typeResult.mime)) {
throw new EventError('detected invalid mime type');
}
@ -601,7 +601,7 @@ function bindActionEvents(io: socketio.Server, client: socketio.Socket, identity
);
// try to get the dimensions of the resource if it is an image so that we can scale it down for the preview
const fileType = (await FileType.fromBuffer(resource)) ?? { mime: null, ext: null };
const fileType = (await fileTypeFromBuffer(resource)) ?? { mime: null, ext: null };
const dimensions: { width: number | null; height: number | null } = { width: null, height: null };
@ -758,7 +758,7 @@ function bindActionEvents(io: socketio.Server, client: socketio.Socket, identity
return;
}
const typeResult = (await FileType.fromBuffer(avatarBuff)) ?? { mime: null, ext: null };
const typeResult = (await fileTypeFromBuffer(avatarBuff)) ?? { mime: null, ext: null };
if ((['image/png', 'image/jpeg', 'image/jpg'] as (string | null)[]).indexOf(typeResult.mime) === -1) {
throw new EventError('invalid avatar buffer');
}

View File

@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "ES2017",
"module": "CommonJS",
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true /* for react */,
"jsx": "react" /* for react */,