Switched to using Sharp to fix JPEG uploads failing (remove Jimp)

pull/125/head
tycrek 2 years ago
parent c1a5d77f0f
commit b44172d999
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

1525
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -58,7 +58,6 @@
"ffmpeg-static": "^4.4.0", "ffmpeg-static": "^4.4.0",
"fs-extra": "^10.0.0", "fs-extra": "^10.0.0",
"helmet": "^4.6.0", "helmet": "^4.6.0",
"jimp": "^0.16.1",
"luxon": "^2.0.2", "luxon": "^2.0.2",
"node-fetch": "^2.6.7", "node-fetch": "^2.6.7",
"node-vibrant": "^3.1.6", "node-vibrant": "^3.1.6",
@ -66,6 +65,7 @@
"prompt": "^1.2.0", "prompt": "^1.2.0",
"pug": "^3.0.2", "pug": "^3.0.2",
"sanitize-filename": "^1.6.3", "sanitize-filename": "^1.6.3",
"sharp": "^0.30.3",
"stream-to-array": "^2.3.0", "stream-to-array": "^2.3.0",
"submodule": "^1.2.1", "submodule": "^1.2.1",
"tailwindcss": "^3.0.23", "tailwindcss": "^3.0.23",
@ -82,6 +82,7 @@
"@types/marked": "^3.0.0", "@types/marked": "^3.0.0",
"@types/node": "^16.9.0", "@types/node": "^16.9.0",
"@types/node-fetch": "^2.5.12", "@types/node-fetch": "^2.5.12",
"@types/sharp": "^0.30.2",
"@types/stream-to-array": "^2.3.0", "@types/stream-to-array": "^2.3.0",
"@types/tailwindcss": "^3.0.9", "@types/tailwindcss": "^3.0.9",
"@types/uuid": "^8.3.1", "@types/uuid": "^8.3.1",

@ -2,7 +2,8 @@ import { FileData } from './types/definitions';
import { Config } from 'ass-json'; import { Config } from 'ass-json';
import fs from 'fs-extra'; import fs from 'fs-extra';
import ffmpeg from 'ffmpeg-static'; import ffmpeg from 'ffmpeg-static';
import Jimp from 'jimp'; import sharp from 'sharp';
// @ts-ignore // @ts-ignore
import shell from 'any-shell-escape'; import shell from 'any-shell-escape';
import { exec } from 'child_process'; import { exec } from 'child_process';
@ -70,11 +71,10 @@ function getVideoThumbnail(file: FileData) {
*/ */
function getImageThumbnail(file: FileData) { function getImageThumbnail(file: FileData) {
return new Promise((resolve, reject) => return new Promise((resolve, reject) =>
Jimp.read(file.path) sharp(file.path)
.then((image) => image .resize(THUMBNAIL.WIDTH, THUMBNAIL.HEIGHT, { kernel: 'cubic' })
.quality(THUMBNAIL.QUALITY) .jpeg({ quality: THUMBNAIL.QUALITY })
.resize(THUMBNAIL.WIDTH, THUMBNAIL.HEIGHT, Jimp.RESIZE_BICUBIC) .toFile(getNewNamePath(file.randomId))
.write(getNewNamePath(file.randomId)))
.then(resolve) .then(resolve)
.catch(reject)); .catch(reject));
} }

@ -1,5 +1,6 @@
import { FileData } from './types/definitions'; import { FileData } from './types/definitions';
import Vibrant from 'node-vibrant'; import Vibrant from 'node-vibrant';
import sharp from 'sharp';
import { randomHexColour } from './utils'; import { randomHexColour } from './utils';
// Vibrant parameters // Vibrant parameters
@ -13,10 +14,11 @@ const QUALITY = 3;
* @param {*} reject Runs if Promise failed * @param {*} reject Runs if Promise failed
*/ */
function getVibrant(file: FileData, resolve: Function, reject: Function) { function getVibrant(file: FileData, resolve: Function, reject: Function) {
Vibrant.from(file.path) sharp(file.path).png().toBuffer()
.maxColorCount(COLOR_COUNT) .then((data) => Vibrant.from(data)
.quality(QUALITY) .maxColorCount(COLOR_COUNT)
.getPalette() .quality(QUALITY)
.getPalette())
.then((palettes) => resolve(palettes[Object.keys(palettes).sort((a, b) => palettes[b]!.population - palettes[a]!.population)[0]]!.hex)) .then((palettes) => resolve(palettes[Object.keys(palettes).sort((a, b) => palettes[b]!.population - palettes[a]!.population)[0]]!.hex))
.catch((err) => reject(err)); .catch((err) => reject(err));
} }

Loading…
Cancel
Save