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'; import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console; const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger'; import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole); const LOG = Logger.create(__filename, electronConsole);
import { ReactNode } from 'react'; import { ReactNode } from 'react';

View File

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

View File

@ -3,9 +3,9 @@ const crypto = require('crypto');
const pg = require('pg'); 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 // Adds a member to a server based on its public key
// (the opposite of registering with a registration file) // (the opposite of registering with a registration file)

View File

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

View File

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

View File

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

6246
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,9 @@
import * as electronRemote from '@electron/remote'; import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console; const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger'; import Logger from '../../../../logger';
const LOG = Logger.create(__filename, electronConsole); 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 CombinedGuild from '../../guild-combined';
import ElementsUtil, { IAlignment } from '../require/elements-util'; import ElementsUtil, { IAlignment } from '../require/elements-util';
import DownloadButton from '../components/button-download'; import DownloadButton from '../components/button-download';

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,10 +3,10 @@
import * as electronRemote from '@electron/remote'; import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console; const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger'; import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole); 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'; 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 // see also client-controller.js
const socketArgs = args.slice(0, args.length - 1); const socketArgs = args.slice(0, args.length - 1);
const respond = args[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; const { name, url, cert, token } = guildConfig;
LOG.debug('Adding new server', { name, url, cert, token, displayName, avatarBuff }); LOG.debug('Adding new server', { name, url, cert, token, displayName, avatarBuff });
const socket = await new Promise<socketio.Socket>((resolve, reject) => { const socket = await new Promise<Socket>((resolve, reject) => {
const socket = socketio.connect(url, { const socket = io(url, {
forceNew: true, forceNew: true,
ca: cert, // verifies the server's identity ca: cert, // verifies the server's identity
reconnection: false, // a bit stricter for registration reconnection: false, // a bit stricter for registration

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
import * as electronRemote from '@electron/remote'; import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console; const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../logger/logger'; import Logger from '../../logger';
const LOG = Logger.create(__filename, electronConsole); const LOG = Logger.create(__filename, electronConsole);
import * as fs from 'fs/promises'; 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'); const LOG = Logger.create('exit');
export enum ExitCode { export enum ExitCode {

View File

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

View File

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

View File

@ -4,14 +4,17 @@ import * as path from 'path';
import * as fs from 'fs'; import * as fs from 'fs';
import * as socketio from 'socket.io'; import * as socketio from 'socket.io';
import { ExitCodes, ExitCode } from '../exit-codes/exit-codes'; import { ExitCodes, ExitCode } from '../exit-codes/index.js';
import Logger from '../logger/logger'; import Logger from '../logger/index.js';
import * as controller from './server-controller'; import * as controller from './server-controller.js';
import DB from './db'; import DB from './db.js';
const LOG = Logger.create('app'); const LOG = Logger.create('app');
const __filename = new URL(import.meta.url).pathname;
const __dirname = path.dirname(__filename);
const server = https.createServer({ const server = https.createServer({
cert: fs.readFileSync(path.join(__dirname, 'ssl/cert.pem')).toString(), cert: fs.readFileSync(path.join(__dirname, 'ssl/cert.pem')).toString(),
key: fs.readFileSync(path.join(__dirname, 'ssl/key.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 */ /* eslint-disable @typescript-eslint/no-explicit-any */
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import * as pg from 'pg'; import pg from 'pg';
import * as uuid from 'uuid'; import * as uuid from 'uuid';
import ConcurrentQueue from '../concurrent-queue/concurrent-queue'; import ConcurrentQueue from '../concurrent-queue/index.js';
import Logger from '../logger/logger'; import Logger from '../logger/index.js';
const LOG = Logger.create('db'); const LOG = Logger.create('db');

View File

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

View File

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

View File

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

View File

@ -1,12 +1,17 @@
import * as fs from 'fs/promises'; import * as fs from 'fs/promises';
import * as path from 'path'; import * as path from 'path';
import * as pg from 'pg'; import pg from 'pg';
import { ExitCodes, ExitCode } from '../../exit-codes/exit-codes'; import { ExitCodes, ExitCode } from '../../exit-codes/index.js';
import Logger from '../../logger/logger'; 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 // TODO: remove db in favor of DB.js
const db = new pg.Client({ const db = new pg.Client({
@ -16,15 +21,24 @@ const db = new pg.Client({
database: 'cordis', database: 'cordis',
}); });
process.on('unhandledRejection', async (reason, promise) => { process.on('unhandledRejection', (reason, promise) => {
LOG.error('unhandled promise rejection:', reason); LOG.error('unhandled promise rejection:', reason);
LOG.error('promise:', promise);
ExitCodes.exit(ExitCode.GENERAL_ERROR); ExitCodes.exit(ExitCode.GENERAL_ERROR);
}); });
(async () => { LOG.debug('connecting...');
try {
await db.connect(); await db.connect();
try { } catch (e: unknown) {
LOG.fatal('unable to connect to database');
ExitCodes.exit(ExitCode.GENERAL_ERROR);
}
LOG.debug('db.connect is done');
try {
await db.query('BEGIN'); await db.query('BEGIN');
LOG.debug('begun transaction');
// note: Order matters // note: Order matters
await db.query('DELETE FROM "messages"'); await db.query('DELETE FROM "messages"');
@ -34,47 +48,149 @@ process.on('unhandledRejection', async (reason, promise) => {
await db.query('DELETE FROM "resources"'); await db.query('DELETE FROM "resources"');
await db.query('DELETE FROM "guilds"'); await db.query('DELETE FROM "guilds"');
LOG.debug('getting icon buffers...');
const icon1Buff = await fs.readFile(path.join(__dirname, 'resources/icon-no-chicoms.png')); 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')); const icon2Buff = await fs.readFile(path.join(__dirname, 'resources/icon-literally-heaven.png'));
LOG.debug('got icon buffers');
const server1Result = await db.query('INSERT INTO "guilds" ("id") VALUES (DEFAULT) RETURNING "id"'); const server1Result = await db.query('INSERT INTO "guilds" ("id") VALUES (DEFAULT) RETURNING "id"');
const server1Id = server1Result.rows[0].id; 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 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 icon1ResourceId = icon1Result.rows[0].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 "guilds_meta" ("id", "name", "icon_resource_id") VALUES ($1, $2, $3)', [
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 1, 'general', 'Some testing flavor text']); server1Id,
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 2, 'vocabulary', null]); 'no chicoms',
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 3, 'gear', null]); icon1ResourceId,
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)', [
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 6, 'wisdom', null]); server1Id,
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 7, 'footage', null]); 1,
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 8, 'burger-chicken', null]); 'general',
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 9, 'handles', null]); 'Some testing flavor text',
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)', [
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 12, 'montage', null]); server1Id,
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 13, 'epic-gamers', null]); 2,
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 14, 'scams', null]); 'vocabulary',
await db.query('INSERT INTO "channels" ("guild_id", "index", "name", "flavor_text") VALUES ($1, $2, $3, $4)', [server1Id, 15, 'bot-commands', null]); 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,
]);
// some dummy members // some dummy members
const avatar1Buff = await fs.readFile(path.join(__dirname, '/resources/avatar-1.png')); 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 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; 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 "members" ("guild_id", "public_key", "display_name", "avatar_resource_id") VALUES ($1, $2, $3, $4)',
[server1Id, 'dummy public key 1', 'AndrewSfeir', avatar1Id],
);
const avatar2Buff = await fs.readFile(path.join(__dirname, '/resources/avatar-2.png')); 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 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; 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]); 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],
);
const avatar3Buff = await fs.readFile(path.join(__dirname, '/resources/avatar-3.png')); 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 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; 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]); 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],
);
// an admin role // an admin role
await db.query("INSERT INTO roles (guild_id, name, color) VALUES ($1, 'admin', '#ff0000')", [server1Id]); await db.query("INSERT INTO roles (guild_id, name, color) VALUES ($1, 'admin', '#ff0000')", [server1Id]);
@ -89,24 +205,65 @@ process.on('unhandledRejection', async (reason, promise) => {
const server2Result = await db.query('INSERT INTO "guilds" ("id") VALUES (DEFAULT) RETURNING "id"'); const server2Result = await db.query('INSERT INTO "guilds" ("id") VALUES (DEFAULT) RETURNING "id"');
const server2Id = server2Result.rows[0].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 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; 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 "guilds_meta" ("id", "name", "icon_resource_id") VALUES ($1, $2, $3)', [
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.']); server2Id,
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.']); 'Literally Heaven',
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.']); icon2ResourceId,
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)', [
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.']); server2Id,
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."]); 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.",
]);
await db.query('COMMIT'); await db.query('COMMIT');
LOG.info(`server 1 initialized as g#${server1Id}`); LOG.info(`server 1 initialized as g#${server1Id}`);
LOG.info(`server 2 initialized as g#${server2Id}`); LOG.info(`server 2 initialized as g#${server2Id}`);
} catch (e) { } catch (e) {
await db.query('ROLLBACK'); await db.query('ROLLBACK');
LOG.error('error setting up test database', e); LOG.error('error setting up test database', e);
} }
await db.end(); await db.end();
})();

View File

@ -6,13 +6,13 @@ import * as crypto from 'crypto';
import moment from 'moment'; import moment from 'moment';
import sizeOf from 'image-size'; import sizeOf from 'image-size';
import * as FileType from 'file-type'; import { fileTypeFromBuffer } from 'file-type';
import sharp from 'sharp'; import sharp from 'sharp';
import * as socketio from 'socket.io'; 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'); const LOG = Logger.create('db');
@ -184,7 +184,7 @@ function bindRegistrationEvents(io: socketio.Server, client: socketio.Socket): v
throw new EventError('invalid avatar'); 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) { if (!typeResult || ['image/png', 'image/jpeg', 'image/jpg'].indexOf(typeResult.mime) === -1) {
throw new EventError('invalid avatar mime type'); 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`); 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)) { if (!typeResult || !['image/png', 'image/jpeg', 'image/jpg'].includes(typeResult.mime)) {
throw new EventError('detected invalid mime type'); 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 // 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 }; 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; 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) { if ((['image/png', 'image/jpeg', 'image/jpg'] as (string | null)[]).indexOf(typeResult.mime) === -1) {
throw new EventError('invalid avatar buffer'); throw new EventError('invalid avatar buffer');
} }

View File

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