@@ -43,7 +43,6 @@ import {
43
43
import { db } from './../../db'
44
44
import _ from 'lodash'
45
45
import sqliteUrl from '../../assets/sql-wasm.wasm?url'
46
- import { toastFatal , toastImpossible , toastInfo } from '../../components/toasts'
47
46
import { C } from '../../topLevelAwait'
48
47
49
48
export async function importAnki (
@@ -55,14 +54,14 @@ export async function importAnki(
55
54
const ankiExport =
56
55
// My mental static analysis says to use `currentTarget`, but it seems to randomly be null, hence `target`. I'm confused but whatever.
57
56
( event . target as HTMLInputElement ) . files ?. item ( 0 ) ??
58
- toastImpossible ( 'There should be a file selected' )
57
+ C . toastImpossible ( 'There should be a file selected' )
59
58
const ankiEntries = await new ZipReader (
60
59
new BlobReader ( ankiExport ) ,
61
60
) . getEntries ( )
62
61
const sqlite =
63
62
ankiEntries . find ( ( e ) => e . filename === 'collection.anki21' ) ??
64
63
ankiEntries . find ( ( e ) => e . filename === 'collection.anki2' ) ??
65
- toastFatal (
64
+ C . toastFatal (
66
65
'`collection.anki21` or `collection.anki2` not found. When exporting from Anki, ensure that `Support older Anki versions` in the `Export` window is checked.' ,
67
66
)
68
67
await importAnkiDb ( sqlite )
@@ -72,21 +71,21 @@ export async function importAnki(
72
71
async function importAnkiMedia ( ankiEntries : Entry [ ] ) : Promise < void > {
73
72
const media =
74
73
ankiEntries . find ( ( e ) => e . filename === 'media' ) ??
75
- toastImpossible (
74
+ C . toastImpossible (
76
75
`'media' not found in the provided file. Did Anki change their export format?` ,
77
76
)
78
77
const mediaText =
79
78
( await media . getData ?.( new TextWriter ( ) ) ) ??
80
- toastImpossible (
79
+ C . toastImpossible (
81
80
"Impossible since we're using `getEntries` https://github.com/gildas-lormeau/zip.js/issues/371" ,
82
81
)
83
82
const parsed = checkMedia ( JSON . parse ( mediaText ) )
84
83
const entryChunks = _ . chunk ( ankiEntries , 1000 )
85
84
for ( let i = 0 ; i < entryChunks . length ; i ++ ) {
86
- toastInfo ( `Media ${ i } /${ entryChunks . length } ` )
85
+ C . toastInfo ( `Media ${ i } /${ entryChunks . length } ` )
87
86
await addMediaBatch ( entryChunks [ i ] ! , parsed )
88
87
}
89
- toastInfo ( 'Anki media import done!' )
88
+ C . toastInfo ( 'Anki media import done!' )
90
89
}
91
90
92
91
async function addMediaBatch (
@@ -97,7 +96,7 @@ async function addMediaBatch(
97
96
entries . map ( async ( entry ) => {
98
97
const array =
99
98
( await entry . getData ?.( new Uint8ArrayWriter ( ) ) ) ??
100
- toastImpossible (
99
+ C . toastImpossible (
101
100
"Impossible since we're using `getEntries` https://github.com/gildas-lormeau/zip.js/issues/371" ,
102
101
)
103
102
const name = nameByI [ entry . filename ]
@@ -164,7 +163,7 @@ async function importAnkiDb(sqlite: Entry): Promise<void> {
164
163
} finally {
165
164
ankiDb . close ( )
166
165
}
167
- toastInfo ( 'AnkiDB import done!' )
166
+ C . toastInfo ( 'AnkiDB import done!' )
168
167
}
169
168
170
169
async function getAnkiDb ( sqlite : Entry ) : Promise < Database > {
@@ -180,7 +179,7 @@ async function getAnkiDb(sqlite: Entry): Promise<Database> {
180
179
async function getSqliteBuffer ( sqlite : Entry ) : Promise < Uint8Array > {
181
180
const blob =
182
181
( await sqlite . getData ?.( new BlobWriter ( ) ) ) ??
183
- toastImpossible (
182
+ C . toastImpossible (
184
183
"Impossible since we're using `getEntries` https://github.com/gildas-lormeau/zip.js/issues/371" ,
185
184
)
186
185
const arrayBuffer = await blob . arrayBuffer ( )
0 commit comments