mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: future proof
This commit is contained in:
1 parent
cb2846a256
commit
84300389f9
3 files changed
+17
-30
No files matched your search
@@ -1,40 +1,26 @@
|
||||
import { readFile } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { readFile } from 'fs/promises';
|
||||
import satori from 'satori';
|
||||
import robotoBlackFile from '../../assets/fonts/Roboto-Black.ttf';
|
||||
import robotoBoldFile from '../../assets/fonts/Roboto-Bold.ttf';
|
||||
import robotoFile from '../../assets/fonts/Roboto.ttf';
|
||||
|
||||
const FONT_NAME = 'Roboto';
|
||||
const FONT_FILES = [robotoFile, robotoBoldFile, robotoBlackFile];
|
||||
const FONT_FILES = [
|
||||
{ weight: 400 as const, path: 'src/assets/fonts/Roboto.ttf' },
|
||||
{ weight: 700 as const, path: 'src/assets/fonts/Roboto-Bold.ttf' },
|
||||
{ weight: 900 as const, path: 'src/assets/fonts/Roboto-Black.ttf' },
|
||||
];
|
||||
|
||||
let roboto: Buffer;
|
||||
let robotoBold: Buffer;
|
||||
let robotoBlack: Buffer;
|
||||
|
||||
Promise.all(
|
||||
FONT_FILES.map(
|
||||
(file) =>
|
||||
new Promise<Buffer>((resolve, reject) => {
|
||||
const path = join(__dirname, file);
|
||||
|
||||
readFile(path, (error, data) => {
|
||||
if (error) reject(error);
|
||||
resolve(data);
|
||||
});
|
||||
}),
|
||||
const fonts = Promise.all(
|
||||
FONT_FILES.map(({ path, weight }) =>
|
||||
readFile(path).then((data) => ({
|
||||
data: Buffer.from(data.buffer),
|
||||
name: FONT_NAME,
|
||||
weight,
|
||||
})),
|
||||
),
|
||||
).then((data) => {
|
||||
[roboto, robotoBold, robotoBlack] = data;
|
||||
});
|
||||
);
|
||||
|
||||
export default async function jsxToSvg(jsx: JSX.Element) {
|
||||
return await satori(jsx, {
|
||||
width: 480,
|
||||
fonts: [
|
||||
{ data: roboto, name: FONT_NAME, weight: 400 },
|
||||
{ data: robotoBold, name: FONT_NAME, weight: 700 },
|
||||
{ data: robotoBlack, name: FONT_NAME, weight: 900 },
|
||||
],
|
||||
fonts: await fonts,
|
||||
});
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { decompress } from 'lz4js';
|
||||
import { CdonReadStream } from '../streams/cdon';
|
||||
|
||||
export function superDecompress<Type>(buffer: Buffer) {
|
||||
const decompressed = Buffer.from(decompress(buffer));
|
||||
const decompressed = decompress(buffer).buffer;
|
||||
const read = new CdonReadStream(decompressed);
|
||||
return read.cdon() as Type;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { Worker } from 'worker_threads';
|
||||
const MAX_WORKERS = 2;
|
||||
|
||||
const workers = [...Array(MAX_WORKERS)].map(() => {
|
||||
// const worker = new Worker('src/workers/render.ts');
|
||||
const worker = new Worker(`${__dirname}/workers/render.cjs`);
|
||||
console.log(`🟡 Launching render worker ${worker.threadId}`);
|
||||
return worker;
|
||||
|
||||
Reference in new issue
Block a user