pin file-type to non-esm version, fix a few warnings

This commit is contained in:
Michael Peters 2022-10-02 23:29:22 -07:00
parent e6139625ce
commit 97b3d3d4e1
12 changed files with 80 additions and 60 deletions

93
package-lock.json generated
View File

@ -16,7 +16,7 @@
"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": "^18.0.0", "file-type": "^16.5.4",
"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",
@ -36,6 +36,7 @@
"devDependencies": { "devDependencies": {
"@types/jest": "^29.1.1", "@types/jest": "^29.1.1",
"@types/pg": "^8.6.1", "@types/pg": "^8.6.1",
"@types/sharp": "^0.31.0",
"@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",
@ -1485,6 +1486,15 @@
"resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz",
"integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew=="
}, },
"node_modules/@types/sharp": {
"version": "0.31.0",
"resolved": "https://registry.npmjs.org/@types/sharp/-/sharp-0.31.0.tgz",
"integrity": "sha512-nwivOU101fYInCwdDcH/0/Ru6yIRXOpORx25ynEOc6/IakuCmjOAGpaO5VfUl4QkDtUC6hj+Z2eCQvgXOioknw==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/stack-utils": { "node_modules/@types/stack-utils": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz",
@ -3430,16 +3440,16 @@
} }
}, },
"node_modules/file-type": { "node_modules/file-type": {
"version": "18.0.0", "version": "16.5.4",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-18.0.0.tgz", "resolved": "https://registry.npmjs.org/file-type/-/file-type-16.5.4.tgz",
"integrity": "sha512-jjMwFpnW8PKofLE/4ohlhqwDk5k0NC6iy0UHAJFKoY1fQeGMN0GDdLgHQrvCbSpMwbqzoCZhRI5dETCZna5qVA==", "integrity": "sha512-/yFHK0aGjFEgDJjEKP0pWCplsPFPhwyfwevf/pVxiN0tmE4L9LmwWxWukdJSHdoCli4VgQLehjJtwQBnqmsKcw==",
"dependencies": { "dependencies": {
"readable-web-to-node-stream": "^3.0.2", "readable-web-to-node-stream": "^3.0.0",
"strtok3": "^7.0.0", "strtok3": "^6.2.4",
"token-types": "^5.0.1" "token-types": "^4.1.1"
}, },
"engines": { "engines": {
"node": ">=14.16" "node": ">=10"
}, },
"funding": { "funding": {
"url": "https://github.com/sindresorhus/file-type?sponsor=1" "url": "https://github.com/sindresorhus/file-type?sponsor=1"
@ -5943,11 +5953,11 @@
} }
}, },
"node_modules/peek-readable": { "node_modules/peek-readable": {
"version": "5.0.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-5.0.0.tgz", "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-4.1.0.tgz",
"integrity": "sha512-YtCKvLUOvwtMGmrniQPdO7MwPjgkFBtFIrmfSbYmYuq3tKDV/mcfAhBth1+C3ru7uXIZasc/pHnb+YDYNkkj4A==", "integrity": "sha512-ZI3LnwUv5nOGbQzD9c2iDG6toheuXSZP5esSHBjopsXH4dg19soufvpUGA3uohi5anFtGb2lhAVdHzH6R/Evvg==",
"engines": { "engines": {
"node": ">=14.16" "node": ">=8"
}, },
"funding": { "funding": {
"type": "github", "type": "github",
@ -7225,15 +7235,15 @@
} }
}, },
"node_modules/strtok3": { "node_modules/strtok3": {
"version": "7.0.0", "version": "6.3.0",
"resolved": "https://registry.npmjs.org/strtok3/-/strtok3-7.0.0.tgz", "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.3.0.tgz",
"integrity": "sha512-pQ+V+nYQdC5H3Q7qBZAz/MO6lwGhoC2gOAjuouGf/VO0m7vQRh8QNMl2Uf6SwAtzZ9bOw3UIeBukEGNJl5dtXQ==", "integrity": "sha512-fZtbhtvI9I48xDSywd/somNqgUHl2L2cstmXCCif0itOf96jeW18MBSyrLuNicYQVkvpOxkZtkzujiTJ9LW5Jw==",
"dependencies": { "dependencies": {
"@tokenizer/token": "^0.3.0", "@tokenizer/token": "^0.3.0",
"peek-readable": "^5.0.0" "peek-readable": "^4.1.0"
}, },
"engines": { "engines": {
"node": ">=14.16" "node": ">=10"
}, },
"funding": { "funding": {
"type": "github", "type": "github",
@ -7404,15 +7414,15 @@
} }
}, },
"node_modules/token-types": { "node_modules/token-types": {
"version": "5.0.1", "version": "4.2.1",
"resolved": "https://registry.npmjs.org/token-types/-/token-types-5.0.1.tgz", "resolved": "https://registry.npmjs.org/token-types/-/token-types-4.2.1.tgz",
"integrity": "sha512-Y2fmSnZjQdDb9W4w4r1tswlMHylzWIeOKpx0aZH9BgGtACHhrk3OkT52AzwcuqTRBZtvvnTjDBh8eynMulu8Vg==", "integrity": "sha512-6udB24Q737UD/SDsKAHI9FCRP7Bqc9D/MQUV02ORQg5iskjtLJlZJNdN4kKtcdtwCeWIwIHDGaUsTsCCAa8sFQ==",
"dependencies": { "dependencies": {
"@tokenizer/token": "^0.3.0", "@tokenizer/token": "^0.3.0",
"ieee754": "^1.2.1" "ieee754": "^1.2.1"
}, },
"engines": { "engines": {
"node": ">=14.16" "node": ">=10"
}, },
"funding": { "funding": {
"type": "github", "type": "github",
@ -9013,6 +9023,15 @@
"resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz",
"integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew=="
}, },
"@types/sharp": {
"version": "0.31.0",
"resolved": "https://registry.npmjs.org/@types/sharp/-/sharp-0.31.0.tgz",
"integrity": "sha512-nwivOU101fYInCwdDcH/0/Ru6yIRXOpORx25ynEOc6/IakuCmjOAGpaO5VfUl4QkDtUC6hj+Z2eCQvgXOioknw==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/stack-utils": { "@types/stack-utils": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz",
@ -10398,13 +10417,13 @@
} }
}, },
"file-type": { "file-type": {
"version": "18.0.0", "version": "16.5.4",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-18.0.0.tgz", "resolved": "https://registry.npmjs.org/file-type/-/file-type-16.5.4.tgz",
"integrity": "sha512-jjMwFpnW8PKofLE/4ohlhqwDk5k0NC6iy0UHAJFKoY1fQeGMN0GDdLgHQrvCbSpMwbqzoCZhRI5dETCZna5qVA==", "integrity": "sha512-/yFHK0aGjFEgDJjEKP0pWCplsPFPhwyfwevf/pVxiN0tmE4L9LmwWxWukdJSHdoCli4VgQLehjJtwQBnqmsKcw==",
"requires": { "requires": {
"readable-web-to-node-stream": "^3.0.2", "readable-web-to-node-stream": "^3.0.0",
"strtok3": "^7.0.0", "strtok3": "^6.2.4",
"token-types": "^5.0.1" "token-types": "^4.1.1"
} }
}, },
"fill-range": { "fill-range": {
@ -12251,9 +12270,9 @@
"integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==" "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw=="
}, },
"peek-readable": { "peek-readable": {
"version": "5.0.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-5.0.0.tgz", "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-4.1.0.tgz",
"integrity": "sha512-YtCKvLUOvwtMGmrniQPdO7MwPjgkFBtFIrmfSbYmYuq3tKDV/mcfAhBth1+C3ru7uXIZasc/pHnb+YDYNkkj4A==" "integrity": "sha512-ZI3LnwUv5nOGbQzD9c2iDG6toheuXSZP5esSHBjopsXH4dg19soufvpUGA3uohi5anFtGb2lhAVdHzH6R/Evvg=="
}, },
"pend": { "pend": {
"version": "1.2.0", "version": "1.2.0",
@ -13161,12 +13180,12 @@
"integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig=="
}, },
"strtok3": { "strtok3": {
"version": "7.0.0", "version": "6.3.0",
"resolved": "https://registry.npmjs.org/strtok3/-/strtok3-7.0.0.tgz", "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.3.0.tgz",
"integrity": "sha512-pQ+V+nYQdC5H3Q7qBZAz/MO6lwGhoC2gOAjuouGf/VO0m7vQRh8QNMl2Uf6SwAtzZ9bOw3UIeBukEGNJl5dtXQ==", "integrity": "sha512-fZtbhtvI9I48xDSywd/somNqgUHl2L2cstmXCCif0itOf96jeW18MBSyrLuNicYQVkvpOxkZtkzujiTJ9LW5Jw==",
"requires": { "requires": {
"@tokenizer/token": "^0.3.0", "@tokenizer/token": "^0.3.0",
"peek-readable": "^5.0.0" "peek-readable": "^4.1.0"
} }
}, },
"sumchecker": { "sumchecker": {
@ -13296,9 +13315,9 @@
} }
}, },
"token-types": { "token-types": {
"version": "5.0.1", "version": "4.2.1",
"resolved": "https://registry.npmjs.org/token-types/-/token-types-5.0.1.tgz", "resolved": "https://registry.npmjs.org/token-types/-/token-types-4.2.1.tgz",
"integrity": "sha512-Y2fmSnZjQdDb9W4w4r1tswlMHylzWIeOKpx0aZH9BgGtACHhrk3OkT52AzwcuqTRBZtvvnTjDBh8eynMulu8Vg==", "integrity": "sha512-6udB24Q737UD/SDsKAHI9FCRP7Bqc9D/MQUV02ORQg5iskjtLJlZJNdN4kKtcdtwCeWIwIHDGaUsTsCCAa8sFQ==",
"requires": { "requires": {
"@tokenizer/token": "^0.3.0", "@tokenizer/token": "^0.3.0",
"ieee754": "^1.2.1" "ieee754": "^1.2.1"

View File

@ -13,7 +13,7 @@
"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": "^18.0.0", "file-type": "^16.5.4",
"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",
@ -33,6 +33,7 @@
"devDependencies": { "devDependencies": {
"@types/jest": "^29.1.1", "@types/jest": "^29.1.1",
"@types/pg": "^8.6.1", "@types/pg": "^8.6.1",
"@types/sharp": "^0.31.0",
"@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",

View File

@ -6,7 +6,7 @@ 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 { fromBuffer as 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

@ -7,8 +7,8 @@ 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 sharp from 'sharp'; import sharp from 'sharp';
import { fromBuffer as fileTypeFromBuffer } from 'file-type';
export interface ImageContextMenuProps { export interface ImageContextMenuProps {
relativeToPos: { x: number; y: number }; relativeToPos: { x: number; y: number };
@ -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

@ -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

@ -3,7 +3,7 @@ const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger'; import Logger from '../../../../logger/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

@ -6,7 +6,7 @@ const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger'; import Logger from '../../../../logger/logger';
const LOG = Logger.create(__filename, electronConsole); const LOG = Logger.create(__filename, electronConsole);
import * as FileType from 'file-type'; import { fromBuffer as 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

@ -18,7 +18,7 @@ import {
useIsMountedRef, useIsMountedRef,
useOneTimeAsyncAction, useOneTimeAsyncAction,
} from '../require/react-helper'; } from '../require/react-helper';
import * as FileType from 'file-type'; import { fromBuffer as 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

@ -106,7 +106,7 @@ export default class GuildsManager extends EventEmitter<{
}); });
try { try {
// create a new Public/Private key pair to identify ourselves with this guild // create a new Public/Private key pair to identify ourselves with this guild
const { publicKey, privateKey } = await new Promise((resolve, reject) => { const { publicKey, privateKey } = await new Promise<{ publicKey: crypto.KeyObject, privateKey: crypto.KeyObject }>((resolve, reject) => {
crypto.generateKeyPair('rsa', { modulusLength: 4096 }, (err, publicKey, privateKey) => { crypto.generateKeyPair('rsa', { modulusLength: 4096 }, (err, publicKey, privateKey) => {
if (err) { if (err) {
reject(err); reject(err);

View File

@ -106,15 +106,15 @@ 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 // xx eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore Typescript is missing this function... Probably because it is static // xx @ts-ignore Typescript is missing this function... Probably because it is static
SourceMapConsumer.initialize({ 'lib/mappings.wasm': URL.createObjectURL(mappingsWasmBlob) }); // xx 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

@ -1,7 +1,7 @@
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 { fromBuffer as fileTypeFromBuffer } from 'file-type';
import { ExitCodes, ExitCode } from '../../exit-codes/exit-codes'; import { ExitCodes, ExitCode } from '../../exit-codes/exit-codes';
import Logger from '../../logger/logger'; import Logger from '../../logger/logger';
@ -21,7 +21,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

@ -6,7 +6,7 @@ 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 { fromBuffer as fileTypeFromBuffer } from 'file-type';
import sharp from 'sharp'; import sharp from 'sharp';
import * as socketio from 'socket.io'; import * as socketio from 'socket.io';
@ -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');
} }