@fiduswriter/books-document 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,20 +4,31 @@
|
|
|
4
4
|
* Uses `NativeImporter` from `@fiduswriter/document/importer/native` for each
|
|
5
5
|
* chapter and delegates creation of the book record to a `BookImporterBackend`.
|
|
6
6
|
*/
|
|
7
|
-
import type { NativeImporterBackend } from "@fiduswriter/document";
|
|
7
|
+
import type { E2EEOptions, NativeImporterBackend } from "@fiduswriter/document";
|
|
8
8
|
import type { BookImporterBackend, User } from "../../types.js";
|
|
9
9
|
export { FIDUSBOOK_VERSION } from "./reader.js";
|
|
10
10
|
export { readFidusBookFile, FidusBookReader } from "./reader.js";
|
|
11
|
+
export interface E2EEOptionsResult {
|
|
12
|
+
options: E2EEOptions;
|
|
13
|
+
password: string;
|
|
14
|
+
}
|
|
15
|
+
export interface NativeBookImporterOptions {
|
|
16
|
+
path?: string;
|
|
17
|
+
getE2EEOptions?: () => Promise<E2EEOptionsResult | null>;
|
|
18
|
+
onChapterImported?: (doc: Record<string, unknown>, password: string) => Promise<void>;
|
|
19
|
+
}
|
|
11
20
|
export declare class NativeBookImporter {
|
|
12
21
|
file: Blob;
|
|
13
22
|
user: User;
|
|
14
23
|
path: string;
|
|
15
24
|
nativeBackend: NativeImporterBackend;
|
|
16
25
|
bookBackend: BookImporterBackend;
|
|
26
|
+
getE2EEOptions?: () => Promise<E2EEOptionsResult | null>;
|
|
27
|
+
onChapterImported?: (doc: Record<string, unknown>, password: string) => Promise<void>;
|
|
17
28
|
ok: boolean;
|
|
18
29
|
statusText: string;
|
|
19
30
|
bookId: number | null;
|
|
20
|
-
constructor(file: Blob, user: User, nativeBackend: NativeImporterBackend, bookBackend: BookImporterBackend,
|
|
31
|
+
constructor(file: Blob, user: User, nativeBackend: NativeImporterBackend, bookBackend: BookImporterBackend, options?: string | NativeBookImporterOptions);
|
|
21
32
|
/**
|
|
22
33
|
* Entry point. Validates the file is a ZIP, then delegates to the reader.
|
|
23
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/importer/native/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/importer/native/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,WAAW,EAAE,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;AAI7E,OAAO,KAAK,EAAC,mBAAmB,EAAW,IAAI,EAAC,MAAM,gBAAgB,CAAA;AAEtE,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAC,iBAAiB,EAAE,eAAe,EAAC,MAAM,aAAa,CAAA;AAE9D,MAAM,WAAW,iBAAiB;IAC9B,OAAO,EAAE,WAAW,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,yBAAyB;IACtC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAA;IACxD,iBAAiB,CAAC,EAAE,CAChB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,QAAQ,EAAE,MAAM,KACf,OAAO,CAAC,IAAI,CAAC,CAAA;CACrB;AAED,qBAAa,kBAAkB;IAC3B,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,qBAAqB,CAAA;IACpC,WAAW,EAAE,mBAAmB,CAAA;IAChC,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAA;IACxD,iBAAiB,CAAC,EAAE,CAChB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,QAAQ,EAAE,MAAM,KACf,OAAO,CAAC,IAAI,CAAC,CAAA;IAElB,EAAE,EAAE,OAAO,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;gBAGjB,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,qBAAqB,EACpC,WAAW,EAAE,mBAAmB,EAChC,OAAO,GAAE,MAAM,GAAG,yBAA+B;IAgBrD;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAqB7B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA6CxB,oBAAoB,CACtB,SAAS,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAC,CAAC,EACrD,WAAW,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,IAAI,CAAA;KAAC,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC;CA4HnB"}
|
|
@@ -14,15 +14,20 @@ export class NativeBookImporter {
|
|
|
14
14
|
path;
|
|
15
15
|
nativeBackend;
|
|
16
16
|
bookBackend;
|
|
17
|
+
getE2EEOptions;
|
|
18
|
+
onChapterImported;
|
|
17
19
|
ok;
|
|
18
20
|
statusText;
|
|
19
21
|
bookId;
|
|
20
|
-
constructor(file, user, nativeBackend, bookBackend,
|
|
22
|
+
constructor(file, user, nativeBackend, bookBackend, options = "/") {
|
|
23
|
+
const opts = typeof options === "string" ? { path: options } : options;
|
|
21
24
|
this.file = file;
|
|
22
25
|
this.user = user;
|
|
23
|
-
this.path = path
|
|
26
|
+
this.path = opts.path?.endsWith("/") ? opts.path : `${opts.path || "/"}/`;
|
|
24
27
|
this.nativeBackend = nativeBackend;
|
|
25
28
|
this.bookBackend = bookBackend;
|
|
29
|
+
this.getE2EEOptions = opts.getE2EEOptions;
|
|
30
|
+
this.onChapterImported = opts.onChapterImported;
|
|
26
31
|
this.ok = false;
|
|
27
32
|
this.statusText = "";
|
|
28
33
|
this.bookId = null;
|
|
@@ -76,7 +81,7 @@ export class NativeBookImporter {
|
|
|
76
81
|
}
|
|
77
82
|
}));
|
|
78
83
|
}
|
|
79
|
-
catch (
|
|
84
|
+
catch (_error) {
|
|
80
85
|
this.statusText = gettext("The uploaded file does not appear to be a Fidusbook file.");
|
|
81
86
|
return;
|
|
82
87
|
}
|
|
@@ -122,8 +127,13 @@ export class NativeBookImporter {
|
|
|
122
127
|
}));
|
|
123
128
|
const safeBookTitle = bookData.title || "Untitled";
|
|
124
129
|
const chapterPath = `${this.path}${safeBookTitle}/${docJson.title || "Untitled"}`;
|
|
130
|
+
let e2eeResult = null;
|
|
131
|
+
if (this.getE2EEOptions) {
|
|
132
|
+
e2eeResult = await this.getE2EEOptions();
|
|
133
|
+
}
|
|
125
134
|
const importer = new NativeImporter(docJson, bibJson, { db: imagesJson }, chapterOtherFiles, this.user, this.nativeBackend, {
|
|
126
|
-
requestedPath: chapterPath
|
|
135
|
+
requestedPath: chapterPath,
|
|
136
|
+
e2eeOptions: e2eeResult?.options ?? null
|
|
127
137
|
});
|
|
128
138
|
let doc;
|
|
129
139
|
try {
|
|
@@ -137,6 +147,9 @@ export class NativeBookImporter {
|
|
|
137
147
|
throw error;
|
|
138
148
|
}
|
|
139
149
|
importedDocIds[ci] = doc.id;
|
|
150
|
+
if (e2eeResult && this.onChapterImported) {
|
|
151
|
+
await this.onChapterImported(doc, e2eeResult.password);
|
|
152
|
+
}
|
|
140
153
|
}
|
|
141
154
|
const chapters = sortedChapters.map(chapter => ({
|
|
142
155
|
text: importedDocIds[chapter.chapter_index],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/importer/native/index.ts"],"names":[],"mappings":"AAAA;;;;;G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ACtB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,EAAE;SAC3B,CAAC,CAAC,CAAA;QAEH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,QAAe,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;QAChF,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,IAAI,IAAI,CAAA;QAC7B,IAAI,CAAC,EAAE,GAAG,IAAI,CAAA;QACd,IAAI,CAAC,UAAU,GAAG,IAAI,QAAQ,CAAC,KAAK,KAAK,OAAO,CAAC,wBAAwB,CAAC,EAAE,CAAA;IAChF,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,101 +1,111 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
},
|
|
9
|
-
"license": "AGPL-3.0",
|
|
10
|
-
"author": "Johannes Wilm",
|
|
11
|
-
"type": "module",
|
|
12
|
-
"main": "./dist/index.js",
|
|
13
|
-
"types": "./dist/index.d.ts",
|
|
14
|
-
"exports": {
|
|
15
|
-
".": {
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
|
-
"default": "./dist/index.js"
|
|
2
|
+
"name": "@fiduswriter/books-document",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Fidus Writer book importers and exporters",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "ssh://git@codeberg.org/fiduswriter/fiduswriter-books-document.git"
|
|
18
8
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
"license": "AGPL-3.0",
|
|
10
|
+
"author": "Johannes Wilm",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./schema": {
|
|
20
|
+
"types": "./dist/schema/index.d.ts",
|
|
21
|
+
"default": "./dist/schema/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./importer/native": {
|
|
24
|
+
"types": "./dist/importer/native/index.d.ts",
|
|
25
|
+
"default": "./dist/importer/native/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./exporter/native": {
|
|
28
|
+
"types": "./dist/exporter/native/index.d.ts",
|
|
29
|
+
"default": "./dist/exporter/native/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./exporter/html": {
|
|
32
|
+
"types": "./dist/exporter/html/index.d.ts",
|
|
33
|
+
"default": "./dist/exporter/html/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./exporter/epub": {
|
|
36
|
+
"types": "./dist/exporter/epub/index.d.ts",
|
|
37
|
+
"default": "./dist/exporter/epub/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./exporter/latex": {
|
|
40
|
+
"types": "./dist/exporter/latex/index.d.ts",
|
|
41
|
+
"default": "./dist/exporter/latex/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./exporter/docx": {
|
|
44
|
+
"types": "./dist/exporter/docx/index.d.ts",
|
|
45
|
+
"default": "./dist/exporter/docx/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./exporter/odt": {
|
|
48
|
+
"types": "./dist/exporter/odt/index.d.ts",
|
|
49
|
+
"default": "./dist/exporter/odt/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./exporter/print": {
|
|
52
|
+
"types": "./dist/exporter/print/index.d.ts",
|
|
53
|
+
"default": "./dist/exporter/print/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./exporter/bits": {
|
|
56
|
+
"types": "./dist/exporter/bits/index.d.ts",
|
|
57
|
+
"default": "./dist/exporter/bits/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./exporter/tools": {
|
|
60
|
+
"types": "./dist/exporter/tools.d.ts",
|
|
61
|
+
"default": "./dist/exporter/tools.js"
|
|
62
|
+
},
|
|
63
|
+
"./i18n": {
|
|
64
|
+
"types": "./dist/i18n.d.ts",
|
|
65
|
+
"default": "./dist/i18n.js"
|
|
66
|
+
}
|
|
22
67
|
},
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"default": "./dist/importer/native/index.js"
|
|
68
|
+
"directories": {
|
|
69
|
+
"test": "test"
|
|
26
70
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
71
|
+
"files": [
|
|
72
|
+
"dist/",
|
|
73
|
+
"src/",
|
|
74
|
+
"README.md",
|
|
75
|
+
"LICENSE"
|
|
76
|
+
],
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "tsc",
|
|
79
|
+
"prepare": "npm run build",
|
|
80
|
+
"prepublishOnly": "npm run build",
|
|
81
|
+
"typecheck": "tsc --noEmit",
|
|
82
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js",
|
|
83
|
+
"lint": "eslint src test",
|
|
84
|
+
"lint:fix": "eslint src test --fix",
|
|
85
|
+
"format": "prettier --write .",
|
|
86
|
+
"format:check": "prettier --check ."
|
|
30
87
|
},
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"@fiduswriter/document": "^0.2.0",
|
|
90
|
+
"@vivliostyle/print": "^2.42.0",
|
|
91
|
+
"biblatex-csl-converter": "^3.0.0",
|
|
92
|
+
"downloadjs": "^1.4.7",
|
|
93
|
+
"fast-deep-equal": "^3.1.3",
|
|
94
|
+
"fwtoolkit": "^0.1.3",
|
|
95
|
+
"jszip": "^3.10.1",
|
|
96
|
+
"pretty": "^2.0.0"
|
|
34
97
|
},
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"./exporter/odt": {
|
|
48
|
-
"types": "./dist/exporter/odt/index.d.ts",
|
|
49
|
-
"default": "./dist/exporter/odt/index.js"
|
|
50
|
-
},
|
|
51
|
-
"./exporter/print": {
|
|
52
|
-
"types": "./dist/exporter/print/index.d.ts",
|
|
53
|
-
"default": "./dist/exporter/print/index.js"
|
|
54
|
-
},
|
|
55
|
-
"./exporter/bits": {
|
|
56
|
-
"types": "./dist/exporter/bits/index.d.ts",
|
|
57
|
-
"default": "./dist/exporter/bits/index.js"
|
|
58
|
-
},
|
|
59
|
-
"./exporter/tools": {
|
|
60
|
-
"types": "./dist/exporter/tools.d.ts",
|
|
61
|
-
"default": "./dist/exporter/tools.js"
|
|
62
|
-
},
|
|
63
|
-
"./i18n": {
|
|
64
|
-
"types": "./dist/i18n.d.ts",
|
|
65
|
-
"default": "./dist/i18n.js"
|
|
98
|
+
"devDependencies": {
|
|
99
|
+
"@types/node": "^26.0.1",
|
|
100
|
+
"jest": "^30.4.2",
|
|
101
|
+
"ts-jest": "^29.1.2",
|
|
102
|
+
"ts-jest-resolver": "^2.0.1",
|
|
103
|
+
"typescript": "^6.0.3",
|
|
104
|
+
"@eslint/js": "^10.0.1",
|
|
105
|
+
"eslint": "^10.6.0",
|
|
106
|
+
"globals": "^15.15.0",
|
|
107
|
+
"prettier": "^3.8.5",
|
|
108
|
+
"typescript-eslint": "^8.62.0",
|
|
109
|
+
"prosemirror-model": "^1.25.0"
|
|
66
110
|
}
|
|
67
|
-
},
|
|
68
|
-
"directories": {
|
|
69
|
-
"test": "test"
|
|
70
|
-
},
|
|
71
|
-
"files": [
|
|
72
|
-
"dist/",
|
|
73
|
-
"src/",
|
|
74
|
-
"README.md",
|
|
75
|
-
"LICENSE"
|
|
76
|
-
],
|
|
77
|
-
"scripts": {
|
|
78
|
-
"build": "tsc",
|
|
79
|
-
"prepare": "npm run build",
|
|
80
|
-
"prepublishOnly": "npm run build",
|
|
81
|
-
"typecheck": "tsc --noEmit",
|
|
82
|
-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js"
|
|
83
|
-
},
|
|
84
|
-
"dependencies": {
|
|
85
|
-
"@fiduswriter/document": "^0.2.0",
|
|
86
|
-
"@vivliostyle/print": "^2.42.0",
|
|
87
|
-
"biblatex-csl-converter": "^3.0.0",
|
|
88
|
-
"downloadjs": "^1.4.7",
|
|
89
|
-
"fast-deep-equal": "^3.1.3",
|
|
90
|
-
"fwtoolkit": "^0.1.3",
|
|
91
|
-
"jszip": "^3.10.1",
|
|
92
|
-
"pretty": "^2.0.0"
|
|
93
|
-
},
|
|
94
|
-
"devDependencies": {
|
|
95
|
-
"@types/node": "^26.0.1",
|
|
96
|
-
"jest": "^30.4.2",
|
|
97
|
-
"ts-jest": "^29.1.2",
|
|
98
|
-
"ts-jest-resolver": "^2.0.1",
|
|
99
|
-
"typescript": "^6.0.3"
|
|
100
|
-
}
|
|
101
111
|
}
|
|
@@ -5,22 +5,40 @@
|
|
|
5
5
|
* chapter and delegates creation of the book record to a `BookImporterBackend`.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {NativeImporterBackend} from "@fiduswriter/document"
|
|
8
|
+
import type {E2EEOptions, NativeImporterBackend} from "@fiduswriter/document"
|
|
9
9
|
import {NativeImporter} from "@fiduswriter/document/importer/native"
|
|
10
10
|
import {addAlert} from "fwtoolkit"
|
|
11
11
|
|
|
12
12
|
import type {BookImporterBackend, Chapter, User} from "../../types.js"
|
|
13
|
-
import {readFidusBookFile} from "./reader.js"
|
|
14
13
|
|
|
15
14
|
export {FIDUSBOOK_VERSION} from "./reader.js"
|
|
16
15
|
export {readFidusBookFile, FidusBookReader} from "./reader.js"
|
|
17
16
|
|
|
17
|
+
export interface E2EEOptionsResult {
|
|
18
|
+
options: E2EEOptions
|
|
19
|
+
password: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface NativeBookImporterOptions {
|
|
23
|
+
path?: string
|
|
24
|
+
getE2EEOptions?: () => Promise<E2EEOptionsResult | null>
|
|
25
|
+
onChapterImported?: (
|
|
26
|
+
doc: Record<string, unknown>,
|
|
27
|
+
password: string
|
|
28
|
+
) => Promise<void>
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
export class NativeBookImporter {
|
|
19
32
|
file: Blob
|
|
20
33
|
user: User
|
|
21
34
|
path: string
|
|
22
35
|
nativeBackend: NativeImporterBackend
|
|
23
36
|
bookBackend: BookImporterBackend
|
|
37
|
+
getE2EEOptions?: () => Promise<E2EEOptionsResult | null>
|
|
38
|
+
onChapterImported?: (
|
|
39
|
+
doc: Record<string, unknown>,
|
|
40
|
+
password: string
|
|
41
|
+
) => Promise<void>
|
|
24
42
|
|
|
25
43
|
ok: boolean
|
|
26
44
|
statusText: string
|
|
@@ -31,13 +49,16 @@ export class NativeBookImporter {
|
|
|
31
49
|
user: User,
|
|
32
50
|
nativeBackend: NativeImporterBackend,
|
|
33
51
|
bookBackend: BookImporterBackend,
|
|
34
|
-
|
|
52
|
+
options: string | NativeBookImporterOptions = "/"
|
|
35
53
|
) {
|
|
54
|
+
const opts = typeof options === "string" ? {path: options} : options
|
|
36
55
|
this.file = file
|
|
37
56
|
this.user = user
|
|
38
|
-
this.path = path
|
|
57
|
+
this.path = opts.path?.endsWith("/") ? opts.path : `${opts.path || "/"}/`
|
|
39
58
|
this.nativeBackend = nativeBackend
|
|
40
59
|
this.bookBackend = bookBackend
|
|
60
|
+
this.getE2EEOptions = opts.getE2EEOptions
|
|
61
|
+
this.onChapterImported = opts.onChapterImported
|
|
41
62
|
|
|
42
63
|
this.ok = false
|
|
43
64
|
this.statusText = ""
|
|
@@ -103,7 +124,7 @@ export class NativeBookImporter {
|
|
|
103
124
|
}
|
|
104
125
|
})
|
|
105
126
|
)
|
|
106
|
-
} catch (
|
|
127
|
+
} catch (_error) {
|
|
107
128
|
this.statusText = gettext(
|
|
108
129
|
"The uploaded file does not appear to be a Fidusbook file."
|
|
109
130
|
)
|
|
@@ -191,6 +212,11 @@ export class NativeBookImporter {
|
|
|
191
212
|
const safeBookTitle = (bookData.title as string) || "Untitled"
|
|
192
213
|
const chapterPath = `${this.path}${safeBookTitle}/${(docJson.title as string) || "Untitled"}`
|
|
193
214
|
|
|
215
|
+
let e2eeResult: E2EEOptionsResult | null = null
|
|
216
|
+
if (this.getE2EEOptions) {
|
|
217
|
+
e2eeResult = await this.getE2EEOptions()
|
|
218
|
+
}
|
|
219
|
+
|
|
194
220
|
const importer = new NativeImporter(
|
|
195
221
|
docJson,
|
|
196
222
|
bibJson,
|
|
@@ -199,7 +225,8 @@ export class NativeBookImporter {
|
|
|
199
225
|
this.user,
|
|
200
226
|
this.nativeBackend,
|
|
201
227
|
{
|
|
202
|
-
requestedPath: chapterPath
|
|
228
|
+
requestedPath: chapterPath,
|
|
229
|
+
e2eeOptions: e2eeResult?.options ?? null
|
|
203
230
|
}
|
|
204
231
|
)
|
|
205
232
|
|
|
@@ -217,6 +244,10 @@ export class NativeBookImporter {
|
|
|
217
244
|
}
|
|
218
245
|
|
|
219
246
|
importedDocIds[ci] = doc.id as number
|
|
247
|
+
|
|
248
|
+
if (e2eeResult && this.onChapterImported) {
|
|
249
|
+
await this.onChapterImported(doc, e2eeResult.password)
|
|
250
|
+
}
|
|
220
251
|
}
|
|
221
252
|
|
|
222
253
|
const chapters: Chapter[] = sortedChapters.map(chapter => ({
|