refactor: store thumbhash as stirng

This commit is contained in:
max_richter 2023-08-11 17:33:06 +02:00
parent 0f3f64d118
commit d4db8430e4
2 changed files with 5 additions and 5 deletions

7
lib/cache/image.ts vendored
View File

@ -54,7 +54,9 @@ export function createThumbhash(
);
if (!bytes) return;
const hash = generateThumbhash(bytes, _image.width, _image.height);
if (hash) {
const b64 = btoa(String.fromCharCode(...hash));
cache.set(
getCacheKey({
url,
@ -62,9 +64,9 @@ export function createThumbhash(
width: _image.width,
height: _image.height,
}),
hash,
b64,
);
res(hash);
res(b64);
}
});
});
@ -96,7 +98,6 @@ export function getThumbhash({ url }: { url: string }) {
width: 200,
height: 200,
}),
true,
);
}

View File

@ -24,12 +24,11 @@ export async function addThumbnailToResource<T = Resource>(
if (!imageUrl) return res;
const thumbhash = await getThumbhash({ url: imageUrl });
if (!thumbhash) return res;
const base64String = btoa(String.fromCharCode(...thumbhash));
return {
...res,
meta: {
...res?.meta,
thumbnail: base64String,
thumbnail: thumbhash,
},
};
}