| 200 | }; |
| 201 | |
| 202 | const restoreFileFromFileHandle = async () => { |
| 203 | try { |
| 204 | performance.mark('start-file-handle-restore'); |
| 205 | const handle = await get('model.bin.handle'); |
| 206 | if (!handle) { |
| 207 | throw new Error('File model.bin.handle not found in OPFS.'); |
| 208 | } |
| 209 | if ((await handle.queryPermission()) !== 'granted') { |
| 210 | const decision = await handle.requestPermission(); |
| 211 | if (decision === 'denied' || decision === 'prompt') { |
| 212 | return Promise.reject(); |
| 213 | } |
| 214 | } |
| 215 | const file = await handle.getFile(); |
| 216 | performance.mark('end-file-handle-restore'); |
| 217 | const mark = performance.measure( |
| 218 | 'file-handle-restore', |
| 219 | 'start-file-handle-restore', |
| 220 | 'end-file-handle-restore' |
| 221 | ); |
| 222 | console.log( |
| 223 | 'Cached model file handle found in IDB.', |
| 224 | mark.name, |
| 225 | mark.duration.toFixed(2) |
| 226 | ); |
| 227 | modelBlobURL = URL.createObjectURL(file); |
| 228 | return 'FileSystemFileHandle'; |
| 229 | } catch (err) { |
| 230 | throw err; |
| 231 | } |
| 232 | }; |
| 233 | |
| 234 | const init = async () => { |
| 235 | if (initRan) { |