fix code quality issues

This commit is contained in:
まっちゃとーにゅ 2024-02-22 08:06:07 +09:00
parent 50caa3fd5c
commit 1dce84dfe3
No known key found for this signature in database
GPG key ID: 6AFBBF529601C1DB
3 changed files with 10 additions and 24 deletions

View file

@ -14,7 +14,6 @@ import FFmpeg from 'fluent-ffmpeg';
import isSvg from 'is-svg';
import probeImageSize from 'probe-image-size';
import { type predictionType } from 'nsfwjs';
import sharp from 'sharp';
import { sharpBmp } from '@misskey-dev/sharp-read-bmp';
import { encode } from 'blurhash';
import { createTempDir } from '@/misc/create-temp.js';
@ -408,25 +407,14 @@ export class FileInfoService {
* Calculate average color of image
*/
@bindThis
private getBlurhash(path: string, type: string): Promise<string> {
return new Promise(async (resolve, reject) => {
(await sharpBmp(path, type))
.raw()
.ensureAlpha()
.resize(64, 64, { fit: 'inside' })
.toBuffer((err, buffer, info) => {
if (err) return reject(err);
private async getBlurhash(path: string, type: string): Promise<string> {
const sharp = await sharpBmp(path, type);
const { data, info } = await sharp
.raw()
.ensureAlpha()
.resize(64, 64, { fit: 'inside' })
.toBuffer({ resolveWithObject: true });
let hash;
try {
hash = encode(new Uint8ClampedArray(buffer), info.width, info.height, 5, 5);
} catch (e) {
return reject(e);
}
resolve(hash);
});
});
return encode(new Uint8ClampedArray(data), info.width, info.height, 5, 5);
}
}