| 12 | } |
| 13 | |
| 14 | export async function handleFiles(files: Iterable<File>) { |
| 15 | const books = await db?.books.toArray() |
| 16 | const newBooks = [] |
| 17 | |
| 18 | for (const file of files) { |
| 19 | console.log(file) |
| 20 | |
| 21 | if (mapExtToMimes['.zip'].includes(file.type)) { |
| 22 | unpack(file) |
| 23 | continue |
| 24 | } |
| 25 | |
| 26 | if (!mapExtToMimes['.epub'].includes(file.type)) { |
| 27 | console.error(`Unsupported file type: ${file.type}`) |
| 28 | continue |
| 29 | } |
| 30 | |
| 31 | let book = books?.find((b) => b.name === file.name) |
| 32 | |
| 33 | if (!book) { |
| 34 | book = await addBook(file) |
| 35 | } |
| 36 | |
| 37 | newBooks.push(book) |
| 38 | } |
| 39 | |
| 40 | return newBooks |
| 41 | } |
| 42 | |
| 43 | export async function addBook(file: File) { |
| 44 | const epub = await fileToEpub(file) |