Revert "server is running with modules!"
This reverts commit c0c7e18471
.
Conflicts:
package.json
This commit is contained in:
parent
96cf2520db
commit
107d5fcb29
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { ReactNode } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { Changes, GuildMetadata, Member, Message, Resource } from "../../data-types";
|
||||
|
@ -3,9 +3,9 @@ const crypto = require('crypto');
|
||||
|
||||
const pg = require('pg');
|
||||
|
||||
const ExitCodes = require('../../exit-codes.js');
|
||||
const ExitCodes = require('../../exit-codes/exit-codes.js');
|
||||
|
||||
const LOG = require('../../logger.js')('reg');
|
||||
const LOG = require('../../logger/logger.js')('reg');
|
||||
|
||||
// Adds a member to a server based on its public key
|
||||
// (the opposite of registering with a registration file)
|
||||
|
@ -1,5 +1,5 @@
|
||||
const DBCache = require('../webapp/db-cache.js');
|
||||
const LOG = require('../../logger.js')('init-db');
|
||||
const LOG = require('../../logger/logger.js')('init-db');
|
||||
|
||||
let configs = [
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, useEffect, useState } from 'react';
|
||||
|
@ -1,27 +0,0 @@
|
||||
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);
|
||||
}
|
6262
package-lock.json
generated
6262
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
package.json
@ -1,7 +1,5 @@
|
||||
{
|
||||
"name": "cordis-ts",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"scripts": {},
|
||||
@ -9,15 +7,16 @@
|
||||
"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": "^17.1.2",
|
||||
"file-type": "^16.5.3",
|
||||
"image-size": "^1.0.0",
|
||||
"moment": "^2.29.1",
|
||||
"pg": "^8.7.1",
|
||||
"react-contenteditable": "^3.3.6",
|
||||
"recoil": "^0.7.4",
|
||||
"recoil": "^0.5.2",
|
||||
"sass": "^1.43.4",
|
||||
"sharp": "^0.30.4",
|
||||
"socket.io": "^4.3.1",
|
||||
@ -29,24 +28,24 @@
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^28.1.3",
|
||||
"@types/node": "^18.0.0",
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.11.4",
|
||||
"@types/pg": "^8.6.1",
|
||||
"@types/react": "^18.0.14",
|
||||
"@types/react-dom": "^18.0.5",
|
||||
"@types/sharp": "^0.30.4",
|
||||
"@types/react": "^17.0.37",
|
||||
"@types/react-dom": "^17.0.11",
|
||||
"@types/sharp": "^0.29.2",
|
||||
"@types/uuid": "^8.3.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
||||
"@typescript-eslint/parser": "^5.5.0",
|
||||
"electron": "^19.0.6",
|
||||
"electron": "^15.3.0",
|
||||
"eslint": "^8.4.0",
|
||||
"eslint-plugin-react": "^7.28.0",
|
||||
"eslint-plugin-unused-imports": "^2.0.0",
|
||||
"jest": "^28.1.1",
|
||||
"jest": "^27.4.0",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"ts-jest": "^28.0.5",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"ts-jest": "^27.0.7",
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Logger from '../logger';
|
||||
import Logger from '../logger/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';
|
||||
import { ExitCodes, ExitCode } from '../exit-codes/exit-codes';
|
||||
|
||||
process.on('unhandledRejection', (reason: unknown, _promise: Promise<unknown>) => {
|
||||
LOG.fatal('unhandled promise rejection:', reason);
|
||||
|
@ -1,6 +1,6 @@
|
||||
//import * as electronRemote from '@electron/remote';
|
||||
//const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
//import Logger from '../../logger';
|
||||
//import Logger from '../../logger/logger';
|
||||
//const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { AutoVerifier, AutoVerifierChangesType } from './auto-verifier';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { Changes, WithEquals } from './data-types';
|
||||
|
@ -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';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import moment from 'moment';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import electron from 'electron';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, useEffect, useMemo, useState } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { Dispatch, DragEvent, FC, SetStateAction, useCallback, useRef } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, ReactNode } from 'react';
|
||||
|
@ -1,12 +1,12 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, useEffect, useRef } from 'react';
|
||||
import ElementsUtil from '../require/elements-util';
|
||||
|
||||
import { fileTypeFromBuffer } from 'file-type';
|
||||
import * as FileType 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 fileTypeFromBuffer(buff);
|
||||
const typeResult = await FileType.fromBuffer(buff);
|
||||
if (!typeResult || !acceptedExtTypes.includes(typeResult.ext)) {
|
||||
e.target.value = '';
|
||||
setMessage(`Invalid image type. Accepted types: ${acceptedExtTypes.join(', ')}`);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, Ref, useEffect, useMemo } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, ReactNode, RefObject, useCallback, useEffect } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import moment from 'moment';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, ReactNode, RefObject, useCallback, useMemo } from 'react';
|
||||
|
@ -1,13 +1,13 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/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 { fileTypeFromBuffer } from 'file-type';
|
||||
import * as FileType 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 fileTypeFromBuffer(resourceBuff);
|
||||
const type = await FileType.fromBuffer(resourceBuff);
|
||||
if (!type) {
|
||||
return { result: null, errorMessage: 'Unable to get file type' };
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, useEffect, useMemo, useState } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { Dispatch, FC, SetStateAction, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../../logger';
|
||||
import Logger from '../../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, MouseEvent, ReactNode, useCallback, useRef } from 'react';
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
} from '../../require/atoms';
|
||||
import ElementsUtil, { IAlignment } from '../../require/elements-util';
|
||||
import { isLoaded } from '../../require/loadables';
|
||||
import { useContextClickContextMenu, useDownloadButton } from '../../require/react-helper';
|
||||
import { useContextClickContextMenu, useDownloadButton, useOneTimeAsyncAction } from '../../require/react-helper';
|
||||
|
||||
interface ResourceElementProps {
|
||||
guild: CombinedGuild;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, useMemo } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, useEffect, useMemo, useRef } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, ReactNode, useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, ReactNode, useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
@ -1,9 +1,9 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, useMemo, useRef } from 'react';
|
||||
import React, { FC, useCallback, useMemo, useRef } from 'react';
|
||||
import CombinedGuild from '../../guild-combined';
|
||||
import ElementsUtil, { IAlignment } from '../require/elements-util';
|
||||
import DownloadButton from '../components/button-download';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { createRef, FC, MutableRefObject, ReactNode, useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { AtomEffect, Loadable, RecoilValue, useRecoilValueLoadable } from 'recoil';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { ReactNode, useEffect } from 'react';
|
||||
|
@ -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';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { fileTypeFromBuffer } from 'file-type';
|
||||
import * as FileType 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 fileTypeFromBuffer(buffer);
|
||||
const result = await FileType.fromBuffer(buffer);
|
||||
switch (result && result.mime) {
|
||||
case 'image/png':
|
||||
case 'image/jpeg':
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, ReactNode, useRef } from 'react';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger';
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, useEffect, useState } from 'react';
|
||||
|
@ -18,7 +18,7 @@ import {
|
||||
useIsMountedRef,
|
||||
useOneTimeAsyncAction,
|
||||
} from '../require/react-helper';
|
||||
import { fileTypeFromBuffer } from 'file-type';
|
||||
import * as FileType 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 fileTypeFromBuffer(attachmentBuff);
|
||||
const type = await FileType.fromBuffer(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
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { Changes, Channel, GuildMetadata, Member, Message, Resource, Token } from './data-types';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import * as socketio from 'socket.io-client';
|
||||
|
@ -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';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import * as socketio from 'socket.io-client';
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { io, Socket } from 'socket.io-client';
|
||||
import * as socketio from 'socket.io-client';
|
||||
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
@ -66,7 +66,7 @@ export default class GuildsManager extends EventEmitter<{
|
||||
}
|
||||
}
|
||||
|
||||
static _socketEmitTimeout(socket: Socket, ms: number, name: string, ...args: any[]) {
|
||||
static _socketEmitTimeout(socket: socketio.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<Socket>((resolve, reject) => {
|
||||
const socket = io(url, {
|
||||
const socket = await new Promise<socketio.Socket>((resolve, reject) => {
|
||||
const socket = socketio.connect(url, {
|
||||
forceNew: true,
|
||||
ca: cert, // verifies the server's identity
|
||||
reconnection: false, // a bit stricter for registration
|
||||
|
@ -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';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { AutoVerifierWithArg, PartialMessageListQuery } from './auto-verifier-with-args';
|
||||
|
@ -1,11 +1,11 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
import ConcurrentQueue from '../../concurrent-queue';
|
||||
import ConcurrentQueue from '../../concurrent-queue/concurrent-queue';
|
||||
|
||||
import * as sqlite from 'sqlite';
|
||||
import * as sqlite3 from 'sqlite3';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
LOG.silly('preload begins');
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import * as crypto from 'crypto';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger';
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import * as fs from 'fs/promises';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Logger from '../logger/index.js';
|
||||
import Logger from '../logger/logger';
|
||||
const LOG = Logger.create('exit');
|
||||
|
||||
export enum ExitCode {
|
@ -1,4 +1,4 @@
|
||||
import Logger from './';
|
||||
import Logger from './logger';
|
||||
|
||||
const LOG = Logger.create(__filename);
|
||||
|
||||
|
@ -3,17 +3,14 @@ import * as path from 'path';
|
||||
import * as fs from 'fs/promises';
|
||||
|
||||
import moment from 'moment';
|
||||
import colors from 'colors/safe.js';
|
||||
import colors from 'colors/safe';
|
||||
import { SourceMapConsumer } from 'source-map';
|
||||
|
||||
import * as StackTrace from '../stack-trace/stack-trace.js';
|
||||
import * as StackTrace from '../stack-trace/stack-trace';
|
||||
|
||||
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 */
|
||||
@ -99,7 +96,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(__dirname)) {
|
||||
for await (const file of getAllFiles(path.join(__dirname, '..'))) {
|
||||
if (!file.endsWith('.js')) continue;
|
||||
if (
|
||||
!(await fs
|
||||
@ -109,16 +106,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);
|
||||
}
|
@ -4,17 +4,14 @@ import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as socketio from 'socket.io';
|
||||
|
||||
import { ExitCodes, ExitCode } from '../exit-codes/index.js';
|
||||
import Logger from '../logger/index.js';
|
||||
import { ExitCodes, ExitCode } from '../exit-codes/exit-codes';
|
||||
import Logger from '../logger/logger';
|
||||
|
||||
import * as controller from './server-controller.js';
|
||||
import DB from './db.js';
|
||||
import * as controller from './server-controller';
|
||||
import DB from './db';
|
||||
|
||||
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(),
|
||||
|
@ -1,12 +1,12 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
import pg from 'pg';
|
||||
import * as pg from 'pg';
|
||||
|
||||
import * as uuid from 'uuid';
|
||||
|
||||
import ConcurrentQueue from '../concurrent-queue/index.js';
|
||||
import Logger from '../logger/index.js';
|
||||
import ConcurrentQueue from '../concurrent-queue/concurrent-queue';
|
||||
import Logger from '../logger/logger';
|
||||
|
||||
const LOG = Logger.create('db');
|
||||
|
||||
|
@ -1,15 +1,13 @@
|
||||
import * as fs from 'fs/promises';
|
||||
import * as path from 'path';
|
||||
|
||||
import { fileTypeFromBuffer } from 'file-type';
|
||||
import * as FileType from 'file-type';
|
||||
|
||||
import { ExitCodes, ExitCode } from '../../exit-codes/index.js';
|
||||
import Logger from '../../logger/index.js';
|
||||
import { ExitCodes, ExitCode } from '../../exit-codes/exit-codes';
|
||||
import Logger from '../../logger/logger';
|
||||
|
||||
import DB from '../db.js';
|
||||
import DB from '../db';
|
||||
|
||||
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';
|
||||
@ -23,7 +21,7 @@ process.on('unhandledRejection', async (reason, _promise) => {
|
||||
|
||||
// from ElementsUtil
|
||||
async function getImageBufferSrc(buffer: Buffer) {
|
||||
const result = await fileTypeFromBuffer(buffer);
|
||||
const result = await FileType.fromBuffer(buffer);
|
||||
switch (result && result.mime) {
|
||||
case 'image/png':
|
||||
case 'image/jpeg':
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ExitCode, ExitCodes } from '../../exit-codes';
|
||||
import Logger from '../../logger';
|
||||
import { ExitCode, ExitCodes } from '../../exit-codes/exit-codes';
|
||||
import Logger from '../../logger/logger';
|
||||
import DB from '../db';
|
||||
|
||||
const LOG = Logger.create('setup-test-guild');
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ExitCode, ExitCodes } from '../../exit-codes';
|
||||
import Logger from '../../logger';
|
||||
import { ExitCode, ExitCodes } from '../../exit-codes/exit-codes';
|
||||
import Logger from '../../logger/logger';
|
||||
import DB from '../db';
|
||||
|
||||
const LOG = Logger.create('setup-test-guild');
|
||||
|
@ -1,17 +1,12 @@
|
||||
import * as fs from 'fs/promises';
|
||||
import * as path from 'path';
|
||||
|
||||
import pg from 'pg';
|
||||
import * as pg from 'pg';
|
||||
|
||||
import { ExitCodes, ExitCode } from '../../exit-codes/index.js';
|
||||
import Logger from '../../logger/index.js';
|
||||
import { ExitCodes, ExitCode } from '../../exit-codes/exit-codes';
|
||||
import Logger from '../../logger/logger';
|
||||
|
||||
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);
|
||||
const LOG = Logger.create(__filename);
|
||||
|
||||
// TODO: remove db in favor of DB.js
|
||||
const db = new pg.Client({
|
||||
@ -21,249 +16,97 @@ const db = new pg.Client({
|
||||
database: 'cordis',
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
process.on('unhandledRejection', async (reason, promise) => {
|
||||
LOG.error('unhandled promise rejection:', reason);
|
||||
LOG.error('promise:', promise);
|
||||
ExitCodes.exit(ExitCode.GENERAL_ERROR);
|
||||
});
|
||||
|
||||
LOG.debug('connecting...');
|
||||
try {
|
||||
(async () => {
|
||||
await db.connect();
|
||||
} 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');
|
||||
|
||||
try {
|
||||
await db.query('BEGIN');
|
||||
LOG.debug('begun transaction');
|
||||
// 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"');
|
||||
|
||||
// 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 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('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 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 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 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;
|
||||
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]);
|
||||
|
||||
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,
|
||||
]);
|
||||
// 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]);
|
||||
|
||||
// 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 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]);
|
||||
|
||||
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],
|
||||
);
|
||||
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 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],
|
||||
);
|
||||
// an admin role
|
||||
await db.query("INSERT INTO roles (guild_id, name, color) VALUES ($1, 'admin', '#ff0000')", [server1Id]);
|
||||
|
||||
// an admin role
|
||||
await db.query("INSERT INTO roles (guild_id, name, color) VALUES ($1, 'admin', '#ff0000')", [server1Id]);
|
||||
// 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 ]);
|
||||
// }
|
||||
|
||||
// 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 ]);
|
||||
// }
|
||||
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."]);
|
||||
|
||||
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.",
|
||||
]);
|
||||
await db.query('COMMIT');
|
||||
|
||||
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();
|
||||
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();
|
||||
})();
|
||||
|
@ -6,13 +6,13 @@ import * as crypto from 'crypto';
|
||||
import moment from 'moment';
|
||||
|
||||
import sizeOf from 'image-size';
|
||||
import { fileTypeFromBuffer } from 'file-type';
|
||||
import * as FileType from 'file-type';
|
||||
import sharp from 'sharp';
|
||||
import * as socketio from 'socket.io';
|
||||
|
||||
import Logger from '../logger/index.js';
|
||||
import Logger from '../logger/logger';
|
||||
|
||||
import DB from './db.js';
|
||||
import DB from './db';
|
||||
|
||||
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 fileTypeFromBuffer(avatarBuff);
|
||||
const typeResult = await FileType.fromBuffer(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 fileTypeFromBuffer(iconBuff);
|
||||
const typeResult = await FileType.fromBuffer(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 fileTypeFromBuffer(resource)) ?? { mime: null, ext: null };
|
||||
const fileType = (await FileType.fromBuffer(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 fileTypeFromBuffer(avatarBuff)) ?? { mime: null, ext: null };
|
||||
const typeResult = (await FileType.fromBuffer(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');
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"target": "ES2017",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true /* for react */,
|
||||
"jsx": "react" /* for react */,
|
||||
|
Loading…
Reference in New Issue
Block a user