mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-22 13:26:17 +01: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 { readFile } from 'fs/promises';
|
||||||
import { join } from 'path';
|
|
||||||
import satori from 'satori';
|
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_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;
|
const fonts = Promise.all(
|
||||||
let robotoBold: Buffer;
|
FONT_FILES.map(({ path, weight }) =>
|
||||||
let robotoBlack: Buffer;
|
readFile(path).then((data) => ({
|
||||||
|
data: Buffer.from(data.buffer),
|
||||||
Promise.all(
|
name: FONT_NAME,
|
||||||
FONT_FILES.map(
|
weight,
|
||||||
(file) =>
|
})),
|
||||||
new Promise<Buffer>((resolve, reject) => {
|
|
||||||
const path = join(__dirname, file);
|
|
||||||
|
|
||||||
readFile(path, (error, data) => {
|
|
||||||
if (error) reject(error);
|
|
||||||
resolve(data);
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
).then((data) => {
|
);
|
||||||
[roboto, robotoBold, robotoBlack] = data;
|
|
||||||
});
|
|
||||||
|
|
||||||
export default async function jsxToSvg(jsx: JSX.Element) {
|
export default async function jsxToSvg(jsx: JSX.Element) {
|
||||||
return await satori(jsx, {
|
return await satori(jsx, {
|
||||||
width: 480,
|
width: 480,
|
||||||
fonts: [
|
fonts: await fonts,
|
||||||
{ data: roboto, name: FONT_NAME, weight: 400 },
|
|
||||||
{ data: robotoBold, name: FONT_NAME, weight: 700 },
|
|
||||||
{ data: robotoBlack, name: FONT_NAME, weight: 900 },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ import { decompress } from 'lz4js';
|
|||||||
import { CdonReadStream } from '../streams/cdon';
|
import { CdonReadStream } from '../streams/cdon';
|
||||||
|
|
||||||
export function superDecompress<Type>(buffer: Buffer) {
|
export function superDecompress<Type>(buffer: Buffer) {
|
||||||
const decompressed = Buffer.from(decompress(buffer));
|
const decompressed = decompress(buffer).buffer;
|
||||||
const read = new CdonReadStream(decompressed);
|
const read = new CdonReadStream(decompressed);
|
||||||
return read.cdon() as Type;
|
return read.cdon() as Type;
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ import { Worker } from 'worker_threads';
|
|||||||
const MAX_WORKERS = 2;
|
const MAX_WORKERS = 2;
|
||||||
|
|
||||||
const workers = [...Array(MAX_WORKERS)].map(() => {
|
const workers = [...Array(MAX_WORKERS)].map(() => {
|
||||||
|
// const worker = new Worker('src/workers/render.ts');
|
||||||
const worker = new Worker(`${__dirname}/workers/render.cjs`);
|
const worker = new Worker(`${__dirname}/workers/render.cjs`);
|
||||||
console.log(`🟡 Launching render worker ${worker.threadId}`);
|
console.log(`🟡 Launching render worker ${worker.threadId}`);
|
||||||
return worker;
|
return worker;
|
||||||
|
|||||||
Reference in new issue
Block a user