u
This commit is contained in:
@@ -17,25 +17,23 @@ const log = createLogger('import');
|
||||
* @returns {Promise<{base62: string, width: number, height: number, hashLength: number}|null>}
|
||||
*/
|
||||
export async function computeSkeleHash(buffer) {
|
||||
try {
|
||||
const { data, info } = await sharp(buffer)
|
||||
.rotate()
|
||||
.resize({ width: 200, height: 200, fit: 'inside' })
|
||||
.ensureAlpha()
|
||||
.raw()
|
||||
.toBuffer({ resolveWithObject: true });
|
||||
const { data, info } = await sharp(buffer)
|
||||
.rotate()
|
||||
.resize({ width: 200, height: 200, fit: 'inside' })
|
||||
.ensureAlpha()
|
||||
.raw()
|
||||
.toBuffer({ resolveWithObject: true });
|
||||
|
||||
const result = await encodeRGBA(info.width, info.height, data);
|
||||
return {
|
||||
base62: result.base62,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
hashLength: result.hash?.length ?? 0,
|
||||
};
|
||||
} catch (err) {
|
||||
log.warn('Failed to compute skelehash for image:', err.message);
|
||||
return null;
|
||||
const result = await encodeRGBA(info.width, info.height, data);
|
||||
if (!result?.base62) {
|
||||
throw new Error('encodeRGBA failed to produce a base62 skelehash');
|
||||
}
|
||||
return {
|
||||
base62: result.base62,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
hashLength: result.hash?.length ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
@@ -18,14 +18,10 @@ export async function formatAttachment(file) {
|
||||
}
|
||||
|
||||
if (!skeledash && file.thumbavif) {
|
||||
try {
|
||||
const result = await computeSkeleHash(file.thumbavif);
|
||||
skeledash = result?.base62 || null;
|
||||
if (file.hash && skeledash) {
|
||||
skeleCache.set(file.hash, skeledash);
|
||||
}
|
||||
} catch {
|
||||
skeledash = null;
|
||||
const result = await computeSkeleHash(file.thumbavif);
|
||||
skeledash = result.base62;
|
||||
if (file.hash && skeledash) {
|
||||
skeleCache.set(file.hash, skeledash);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user