* Cleanup file handler from indexdb database when * it is no longer needed.
()
| 12 | * it is no longer needed. |
| 13 | */ |
| 14 | async function cleanupFileHandler() { |
| 15 | const validHandlerIds = new Set( |
| 16 | (await localDb.connection.toCollection().toArray()) |
| 17 | .map((c) => c.content.file_handler) |
| 18 | .filter(Boolean) as string[] |
| 19 | ); |
| 20 | |
| 21 | const fileHandlerList = (await localDb.file_handler.toArray()).map( |
| 22 | (r) => r.id |
| 23 | ); |
| 24 | |
| 25 | for (const id of fileHandlerList) { |
| 26 | if (!validHandlerIds.has(id)) { |
| 27 | await localDb.file_handler.delete(id); |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | async function openFileHandler() { |
| 33 | const [newFileHandler] = await window.showOpenFilePicker({ |