Skip to content

Commit c418596

Browse files
在非安全上下文中不使用cache API
1 parent 6044fb4 commit c418596

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/compiler/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const RequiredPreloadPackages: PackageSpec[] = [
3232

3333
const preloadedPackages = new Map<string, ArrayBuffer>();
3434

35-
const browserCache = await window.caches.open("typst-assets");
35+
const browserCache: Cache | undefined =
36+
await window.caches?.open("typst-assets");
3637

3738
async function downloadMultiData(
3839
urls: string[],
@@ -53,7 +54,7 @@ async function downloadMultiData(
5354
loaded: 0,
5455
total: undefined,
5556
async exec() {
56-
const cached = await browserCache.match(url);
57+
const cached = await browserCache?.match(url);
5758
if (cached) return await cached.arrayBuffer();
5859
const res = await axiosInstance.get<ArrayBuffer>(url, {
5960
onDownloadProgress: (e) => {
@@ -74,7 +75,7 @@ async function downloadMultiData(
7475
});
7576
},
7677
});
77-
browserCache.put(
78+
browserCache?.put(
7879
url,
7980
new Response(res.data, {
8081
headers: { "Content-Type": "application/octet-stream" },
@@ -162,7 +163,7 @@ export const typstInitInfo: {
162163
const unCachedFontUrlEntries: [string, string][] = [];
163164
await Promise.all(
164165
fontUrlEntries.map(async ([fontName, fontUrl]) => {
165-
const cached = await browserCache.match(fontUrl);
166+
const cached = await browserCache?.match(fontUrl);
166167
if (!cached) unCachedFontUrlEntries.push([fontName, fontUrl]);
167168
else
168169
localFontDatas.push({
@@ -187,7 +188,7 @@ export const typstInitInfo: {
187188
(v) => v[0] === x.postscriptName,
188189
)?.[1];
189190
if (fontUrl)
190-
browserCache.put(
191+
browserCache?.put(
191192
fontUrl,
192193
new Response(blob, {
193194
headers: { "Content-Type": "application/octet-stream" },

0 commit comments

Comments
 (0)