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>}
|
* @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
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user