Skip to content

Commit df2fbc6

Browse files
authored
fix(smart-tools): Fix model loading if cache is full (#1459)
1 parent 78c72a4 commit df2fbc6

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

web_ui/packages/smart-tools/src/utils/tool-utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,19 @@ export const loadSource = async (source: string, cacheKey = 'general'): Promise<
121121
}
122122

123123
const cache = await caches.open(cacheKey);
124-
125-
if (!(await cache.match(source))) {
126-
await cache.put(source, await self.fetch(source));
124+
const match = await cache.match(source);
125+
if (match !== undefined) {
126+
return match;
127127
}
128128

129-
return cache.match(source);
129+
const response = await self.fetch(source);
130+
131+
// Putting the model in cache might fail if the user does not have enough storage
132+
try {
133+
await cache.put(source, response.clone());
134+
} finally {
135+
return response;
136+
}
130137
};
131138

132139
export const getPointsFromMat = (mat: OpenCVTypes.Mat, offset = { x: 0, y: 0 }): Point[] => {

web_ui/rsbuild.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,16 @@ export default defineConfig({
8686
},
8787
server: {
8888
proxy: devProxy,
89+
headers: {
90+
'Cross-Origin-Embedder-Policy': 'credentialless',
91+
'Cross-Origin-Opener-Policy': 'same-origin',
92+
'Content-Security-Policy':
93+
"default-src 'self'; " +
94+
"script-src 'self' 'unsafe-eval' blob:; " +
95+
"worker-src 'self' blob:; " +
96+
"connect-src 'self' data:; " +
97+
"img-src 'self' data: blob:; " +
98+
"style-src 'self' 'unsafe-inline';",
99+
},
89100
},
90101
});

0 commit comments

Comments
 (0)