This commit is contained in:
seb
2026-10-18 14:44:23 +02:00
parent d0a2ede749
commit 0463003681
2 changed files with 19 additions and 25 deletions

View File

@@ -17,7 +17,6 @@ const log = createLogger('import');
* @returns {Promise<{base62: string, width: number, height: number, hashLength: number}|null>} * @returns {Promise<{base62: string, width: number, height: number, hashLength: number}|null>}
*/ */
export async function computeSkeleHash(buffer) { export async function computeSkeleHash(buffer) {
try {
const { data, info } = await sharp(buffer) const { data, info } = await sharp(buffer)
.rotate() .rotate()
.resize({ width: 200, height: 200, fit: 'inside' }) .resize({ width: 200, height: 200, fit: 'inside' })
@@ -26,16 +25,15 @@ export async function computeSkeleHash(buffer) {
.toBuffer({ resolveWithObject: true }); .toBuffer({ resolveWithObject: true });
const result = await encodeRGBA(info.width, info.height, data); const result = await encodeRGBA(info.width, info.height, data);
if (!result?.base62) {
throw new Error('encodeRGBA failed to produce a base62 skelehash');
}
return { return {
base62: result.base62, base62: result.base62,
width: info.width, width: info.width,
height: info.height, height: info.height,
hashLength: result.hash?.length ?? 0, hashLength: result.hash?.length ?? 0,
}; };
} catch (err) {
log.warn('Failed to compute skelehash for image:', err.message);
return null;
}
} }
// #endregion // #endregion

View File

@@ -18,15 +18,11 @@ export async function formatAttachment(file) {
} }
if (!skeledash && file.thumbavif) { if (!skeledash && file.thumbavif) {
try {
const result = await computeSkeleHash(file.thumbavif); const result = await computeSkeleHash(file.thumbavif);
skeledash = result?.base62 || null; skeledash = result.base62;
if (file.hash && skeledash) { if (file.hash && skeledash) {
skeleCache.set(file.hash, skeledash); skeleCache.set(file.hash, skeledash);
} }
} catch {
skeledash = null;
}
} }
const { thumbavif: _thumbavif, ...rest } = file; const { thumbavif: _thumbavif, ...rest } = file;