Skip to content

Commit

Permalink
optimize render
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Aug 26, 2024
1 parent d1c452f commit de9dbb2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions utils/puppeteer.render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class YukiPuppeteerRender extends Puppeteer {
let numSun = 0;
let start = Date.now();
const ret = new Array<Buffer>();
let buff: string | false | Buffer;
let buff: string | false | Uint8Array;

for (let i = 1; i <= num; i++) {
if (i > 1) {
Expand Down Expand Up @@ -134,15 +134,13 @@ export class YukiPuppeteerRender extends Puppeteer {
numSun++; // 增加截图次数

if (buff !== false) {
if (!Buffer.isBuffer(buff)) {
buff = Buffer.from(buff)
}
let imgBuff: Buffer = !Buffer.isBuffer(buff) ? Buffer.from(buff) : buff;
/** 计算图片大小 */
const kb = (buff?.length / 1024).toFixed(2) + "kb"; // 计算图片大小
const kb = (imgBuff?.length / 1024).toFixed(2) + "kb"; // 计算图片大小

logger.mark(`[图片生成][${name}][${numSun}次] ${kb} ${logger.green(`${Date.now() - start}ms`)}`); // 记录日志

ret.push(buff); // 将截图结果添加到数组中
ret.push(imgBuff); // 将截图结果添加到数组中
} else {
logger.error(`[puppeteer]`, '截图失败');
}
Expand Down

0 comments on commit de9dbb2

Please sign in to comment.