diff --git a/lib/routes/bilibili/manga-update.ts b/lib/routes/bilibili/manga-update.ts index 672f816ab933c3b..92102a2070a85e7 100644 --- a/lib/routes/bilibili/manga-update.ts +++ b/lib/routes/bilibili/manga-update.ts @@ -1,4 +1,5 @@ import { Route } from '@/types'; +import cache from '@/utils/cache'; import got from '@/utils/got'; import { Go } from './wasm-exec.js'; @@ -27,12 +28,18 @@ export const route: Route = { // Based on https://github.com/SocialSisterYi/bilibili-API-collect/issues/1168#issuecomment-2620749895 async function genReqSign(query, body) { - const wasm_resp = await got('https://s1.hdslb.com/bfs/manga-static/manga-pc/6732b1bf426cfc634293.wasm', { - responseType: 'arrayBuffer', + // Cache the wasm binary as it's quite large (~2MB) + // Here the binary is saved as base64 as the cache stores strings + const wasm_buffer_base64 = await cache.tryGet('bilibili-manga-wasm-20250208', async () => { + const wasm_resp = await got('https://s1.hdslb.com/bfs/manga-static/manga-pc/6732b1bf426cfc634293.wasm', { + responseType: 'arrayBuffer', + }); + return Buffer.from(wasm_resp.data).toString('base64'); }); + const wasm_buffer = Buffer.from(wasm_buffer_base64, 'base64'); const go = new Go(); - const { instance } = await WebAssembly.instantiate(wasm_resp.data, go.importObject); + const { instance } = await WebAssembly.instantiate(wasm_buffer, go.importObject); go.run(instance); if (void 0 === globalThis.genReqSign) { throw new Error('WASM function not available');