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,25 +17,23 @@ 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' }) .ensureAlpha()
.ensureAlpha() .raw()
.raw() .toBuffer({ resolveWithObject: true });
.toBuffer({ resolveWithObject: true });
const result = await encodeRGBA(info.width, info.height, data); const result = await encodeRGBA(info.width, info.height, data);
return { if (!result?.base62) {
base62: result.base62, throw new Error('encodeRGBA failed to produce a base62 skelehash');
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;
} }
return {
base62: result.base62,
width: info.width,
height: info.height,
hashLength: result.hash?.length ?? 0,
};
} }
// #endregion // #endregion

View File

@@ -18,14 +18,10 @@ 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;
skeledash = result?.base62 || null; if (file.hash && skeledash) {
if (file.hash && skeledash) { skeleCache.set(file.hash, skeledash);
skeleCache.set(file.hash, skeledash);
}
} catch {
skeledash = null;
} }
} }