(url: string)
| 87 | } |
| 88 | |
| 89 | export async function fetchBook(url: string) { |
| 90 | const filename = decodeURIComponent(/\/([^/]*\.epub)$/i.exec(url)?.[1] ?? '') |
| 91 | const books = await db?.books.toArray() |
| 92 | const book = books?.find((b) => b.name === filename) |
| 93 | |
| 94 | return ( |
| 95 | book ?? |
| 96 | fetch(url) |
| 97 | .then((res) => res.blob()) |
| 98 | .then((blob) => addBook(new File([blob], filename))) |
| 99 | ) |
| 100 | } |