mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +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';
|
||||
|
||||
const cache: Record<string, string> = {};
|
||||
const cache: Record<string, Buffer> = {};
|
||||
|
||||
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);
|
||||
const imageBufferWEBP = await imageResponse.arrayBuffer();
|
||||
const imageBufferPNG = await sharp(imageBufferWEBP).png().toBuffer();
|
||||
cache[url] = `data:image/png;base64,${imageBufferPNG.toString('base64')}`;
|
||||
|
||||
return cache[url];
|
||||
return `data:image/png;base64,${cache[url].toString('base64')}`;
|
||||
}
|
||||
Reference in new issue
Block a user