mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
feat: optimized png cache
This commit is contained in:
1 parent
146d36234e
commit
bd3f5dea05
1 file changed
+8
-8
@@ -1,14 +1,14 @@
|
|||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
|
|
||||||
const cache: Record<string, string> = {};
|
const cache: Record<string, Buffer> = {};
|
||||||
|
|
||||||
export async function iconPng(url: string) {
|
export async function iconPng(url: string) {
|
||||||
if (cache[url]) return cache[url];
|
if (!cache[url]) {
|
||||||
|
const imageResponse = await fetch(url);
|
||||||
|
const imageBufferWEBP = await imageResponse.arrayBuffer();
|
||||||
|
const imageBufferPNG = await sharp(imageBufferWEBP).png().toBuffer();
|
||||||
|
cache[url] = imageBufferPNG;
|
||||||
|
}
|
||||||
|
|
||||||
const imageResponse = await fetch(url);
|
return `data:image/png;base64,${cache[url].toString('base64')}`;
|
||||||
const imageBufferWEBP = await imageResponse.arrayBuffer();
|
|
||||||
const imageBufferPNG = await sharp(imageBufferWEBP).png().toBuffer();
|
|
||||||
cache[url] = `data:image/png;base64,${imageBufferPNG.toString('base64')}`;
|
|
||||||
|
|
||||||
return cache[url];
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user