shamela 1.0.2 → 1.0.4
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.
- package/README.md +36 -26
- package/dist/index.d.ts +62 -9
- package/dist/main.js +254 -214
- package/dist/main.js.map +1 -1
- package/package.json +20 -21
package/dist/main.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {createClient as $
|
|
2
|
-
import {promises as $
|
|
3
|
-
import $
|
|
4
|
-
import $
|
|
5
|
-
import {URL as $
|
|
6
|
-
import $
|
|
7
|
-
import $
|
|
8
|
-
import $
|
|
9
|
-
import $
|
|
10
|
-
import {pipeline as $
|
|
11
|
-
import $
|
|
12
|
-
import {Buffer as $
|
|
1
|
+
import {createClient as $SK0tW$createClient} from "@libsql/client";
|
|
2
|
+
import {promises as $SK0tW$promises, createWriteStream as $SK0tW$createWriteStream} from "fs";
|
|
3
|
+
import $SK0tW$path from "path";
|
|
4
|
+
import $SK0tW$process from "process";
|
|
5
|
+
import {URL as $SK0tW$URL, URLSearchParams as $SK0tW$URLSearchParams} from "url";
|
|
6
|
+
import $SK0tW$pino from "pino";
|
|
7
|
+
import $SK0tW$pinopretty from "pino-pretty";
|
|
8
|
+
import $SK0tW$https from "https";
|
|
9
|
+
import $SK0tW$os from "os";
|
|
10
|
+
import {pipeline as $SK0tW$pipeline} from "stream/promises";
|
|
11
|
+
import $SK0tW$unzipper from "unzipper";
|
|
12
|
+
import {Buffer as $SK0tW$Buffer} from "buffer";
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
@@ -19,40 +19,50 @@ import {Buffer as $5oumB$Buffer} from "buffer";
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
const $
|
|
22
|
+
const $526b48a37e8a8ec6$var$stream = (0, $SK0tW$pinopretty)({
|
|
23
23
|
colorize: true
|
|
24
24
|
});
|
|
25
|
-
const $
|
|
25
|
+
const $526b48a37e8a8ec6$var$logger = (0, $SK0tW$pino)({
|
|
26
26
|
base: {
|
|
27
27
|
pid: undefined,
|
|
28
28
|
hostname: undefined
|
|
29
29
|
},
|
|
30
|
-
level: (0, $
|
|
31
|
-
}, $
|
|
32
|
-
var $
|
|
30
|
+
level: (0, $SK0tW$process).env.LOG_LEVEL || 'info'
|
|
31
|
+
}, $526b48a37e8a8ec6$var$stream);
|
|
32
|
+
var $526b48a37e8a8ec6$export$2e2bcd8739ae039 = $526b48a37e8a8ec6$var$logger;
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
const $
|
|
35
|
+
const $26460f21c4456828$export$1d57574773c8bc58 = async (db, dbName)=>{
|
|
36
|
+
const { rows: tables } = await db.execute(`SELECT name,sql FROM ${dbName}.sqlite_master WHERE type='table'`);
|
|
37
|
+
return tables.map((row)=>{
|
|
38
|
+
const fields = row.sql.split(', ').map((field)=>field.split(' ')[0]);
|
|
39
|
+
return {
|
|
40
|
+
fields: fields,
|
|
41
|
+
name: row.name
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const $26460f21c4456828$export$3274d151f0598f1 = async (client, table)=>{
|
|
36
46
|
const { rows: rows } = await client.execute(`SELECT * FROM ${table}`);
|
|
37
47
|
return rows;
|
|
38
48
|
};
|
|
39
49
|
|
|
40
50
|
|
|
41
|
-
const $
|
|
42
|
-
const $
|
|
43
|
-
const $
|
|
51
|
+
const $746504ca27eabe49$var$MAIN_DB_ALIAS = 'main';
|
|
52
|
+
const $746504ca27eabe49$export$ee56083bb7df7ecc = (dbFile, alias)=>`ATTACH DATABASE '${dbFile}' AS ${alias}`;
|
|
53
|
+
const $746504ca27eabe49$export$1f75c01d8a920a35 = (patchAlias, tableName, aslAlias = $746504ca27eabe49$var$MAIN_DB_ALIAS)=>`
|
|
44
54
|
UPDATE ${aslAlias}.${tableName}
|
|
45
|
-
SET content = ${$
|
|
46
|
-
part = ${$
|
|
47
|
-
page = ${$
|
|
48
|
-
number = ${$
|
|
55
|
+
SET content = ${$746504ca27eabe49$var$updatePageColumn('content', aslAlias, patchAlias)},
|
|
56
|
+
part = ${$746504ca27eabe49$var$updatePageColumn('part', aslAlias, patchAlias)},
|
|
57
|
+
page = ${$746504ca27eabe49$var$updatePageColumn('page', aslAlias, patchAlias)},
|
|
58
|
+
number = ${$746504ca27eabe49$var$updatePageColumn('number', aslAlias, patchAlias)}
|
|
49
59
|
WHERE EXISTS (
|
|
50
60
|
SELECT 1
|
|
51
61
|
FROM ${patchAlias}.${tableName}
|
|
52
62
|
WHERE ${aslAlias}.${tableName}.id = ${patchAlias}.${tableName}.id
|
|
53
63
|
);
|
|
54
64
|
`;
|
|
55
|
-
const $
|
|
65
|
+
const $746504ca27eabe49$var$updateTitleColumn = (columnName, aslAlias, patchAlias)=>`
|
|
56
66
|
(SELECT CASE
|
|
57
67
|
WHEN ${patchAlias}.title.${columnName} != '#' THEN ${patchAlias}.title.${columnName}
|
|
58
68
|
ELSE ${aslAlias}.title.${columnName}
|
|
@@ -60,20 +70,20 @@ const $e6f751831b705ed8$var$updateTitleColumn = (columnName, aslAlias, patchAlia
|
|
|
60
70
|
FROM ${patchAlias}.title
|
|
61
71
|
WHERE ${aslAlias}.title.id = ${patchAlias}.title.id)
|
|
62
72
|
`;
|
|
63
|
-
const $
|
|
73
|
+
const $746504ca27eabe49$export$a38d1618b943c74f = (patchAlias, tableName, aslAlias = $746504ca27eabe49$var$MAIN_DB_ALIAS)=>`
|
|
64
74
|
UPDATE ${aslAlias}.${tableName}
|
|
65
|
-
SET content = ${$
|
|
66
|
-
page = ${$
|
|
67
|
-
parent = ${$
|
|
75
|
+
SET content = ${$746504ca27eabe49$var$updateTitleColumn('content', aslAlias, patchAlias)},
|
|
76
|
+
page = ${$746504ca27eabe49$var$updateTitleColumn('page', aslAlias, patchAlias)},
|
|
77
|
+
parent = ${$746504ca27eabe49$var$updateTitleColumn('parent', aslAlias, patchAlias)}
|
|
68
78
|
WHERE EXISTS (
|
|
69
79
|
SELECT 1
|
|
70
80
|
FROM ${patchAlias}.${tableName}
|
|
71
81
|
WHERE ${aslAlias}.${tableName}.id = ${patchAlias}.${tableName}.id
|
|
72
82
|
);
|
|
73
83
|
`;
|
|
74
|
-
const $
|
|
75
|
-
const $
|
|
76
|
-
const $
|
|
84
|
+
const $746504ca27eabe49$export$33bbb3ec7652e187 = (name, fields)=>`CREATE TABLE IF NOT EXISTS ${name} (${fields.join(', ')})`;
|
|
85
|
+
const $746504ca27eabe49$export$7fec5208c714b262 = (alias)=>`DETACH DATABASE ${alias}`;
|
|
86
|
+
const $746504ca27eabe49$var$updatePageColumn = (columnName, aslAlias, patchAlias)=>`
|
|
77
87
|
(SELECT CASE
|
|
78
88
|
WHEN ${patchAlias}.page.${columnName} != '#' THEN ${patchAlias}.page.${columnName}
|
|
79
89
|
ELSE ${aslAlias}.page.${columnName}
|
|
@@ -81,59 +91,97 @@ const $e6f751831b705ed8$var$updatePageColumn = (columnName, aslAlias, patchAlias
|
|
|
81
91
|
FROM ${patchAlias}.page
|
|
82
92
|
WHERE ${aslAlias}.page.id = ${patchAlias}.page.id)
|
|
83
93
|
`;
|
|
84
|
-
const $
|
|
94
|
+
const $746504ca27eabe49$export$3ef07b9580a45514 = (table, fieldToValue, isDeleted = false)=>{
|
|
85
95
|
const combinedRecords = {
|
|
86
96
|
...fieldToValue,
|
|
87
|
-
is_deleted: isDeleted ?
|
|
97
|
+
is_deleted: isDeleted ? '1' : '0'
|
|
88
98
|
};
|
|
89
99
|
const sortedKeys = Object.keys(combinedRecords).sort();
|
|
90
100
|
const sortedValues = sortedKeys.map((key)=>combinedRecords[key]);
|
|
91
101
|
return `INSERT INTO ${table} (${sortedKeys.toString()}) VALUES (${sortedValues.map((val)=>{
|
|
92
|
-
if (val === null) return
|
|
93
|
-
return typeof val ===
|
|
102
|
+
if (val === null) return 'NULL';
|
|
103
|
+
return typeof val === 'string' ? `'${val}'` : val;
|
|
94
104
|
}).toString()})`;
|
|
95
105
|
};
|
|
96
106
|
|
|
97
107
|
|
|
98
|
-
var $
|
|
99
|
-
(function(Tables) {
|
|
108
|
+
var $e5a23c058b2763fa$export$a17a6870a08b950e = /*#__PURE__*/ function(Tables) {
|
|
100
109
|
Tables["Authors"] = "authors";
|
|
101
110
|
Tables["Books"] = "books";
|
|
102
111
|
Tables["Categories"] = "categories";
|
|
103
112
|
Tables["Page"] = "page";
|
|
104
113
|
Tables["Title"] = "title";
|
|
105
|
-
|
|
114
|
+
return Tables;
|
|
115
|
+
}({});
|
|
106
116
|
|
|
107
117
|
|
|
108
|
-
const $
|
|
109
|
-
const $
|
|
110
|
-
const $
|
|
111
|
-
const statements = [
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
const $d7a7877f07ff6c69$var$PATCH_DB_ALIAS = 'patch';
|
|
119
|
+
const $d7a7877f07ff6c69$var$ASL_DB_ALIAS = 'asl';
|
|
120
|
+
const $d7a7877f07ff6c69$var$buildCopyStatements = (patchTables, aslTables, table, fields, patchQuery)=>{
|
|
121
|
+
const statements = [];
|
|
122
|
+
if (patchTables.find((t)=>t.name === table)) {
|
|
123
|
+
statements.push(`INSERT INTO main.${table} SELECT ${fields.join(',')} FROM ${$d7a7877f07ff6c69$var$ASL_DB_ALIAS}.${table} WHERE id IN (SELECT id FROM ${$d7a7877f07ff6c69$var$PATCH_DB_ALIAS}.${table} WHERE is_deleted='0')`);
|
|
124
|
+
statements.push(patchQuery);
|
|
125
|
+
} else {
|
|
126
|
+
let copyStatement = `INSERT INTO main.${table} SELECT ${fields.join(',')} FROM ${$d7a7877f07ff6c69$var$ASL_DB_ALIAS}.${table}`;
|
|
127
|
+
if (aslTables.find((t)=>t.name === table)?.fields.includes('is_deleted')) copyStatement += ` WHERE is_deleted='0'`;
|
|
128
|
+
statements.push(copyStatement);
|
|
129
|
+
}
|
|
130
|
+
return statements;
|
|
131
|
+
};
|
|
132
|
+
const $d7a7877f07ff6c69$export$a8b8e03e6bbe5473 = async (db, aslDB, patchDB)=>{
|
|
133
|
+
await Promise.all([
|
|
134
|
+
db.execute((0, $746504ca27eabe49$export$ee56083bb7df7ecc)(aslDB, $d7a7877f07ff6c69$var$ASL_DB_ALIAS)),
|
|
135
|
+
db.execute((0, $746504ca27eabe49$export$ee56083bb7df7ecc)(patchDB, $d7a7877f07ff6c69$var$PATCH_DB_ALIAS))
|
|
136
|
+
]);
|
|
137
|
+
const [patchTables, aslTables] = await Promise.all([
|
|
138
|
+
(0, $26460f21c4456828$export$1d57574773c8bc58)(db, $d7a7877f07ff6c69$var$PATCH_DB_ALIAS),
|
|
139
|
+
(0, $26460f21c4456828$export$1d57574773c8bc58)(db, $d7a7877f07ff6c69$var$ASL_DB_ALIAS)
|
|
140
|
+
]);
|
|
141
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).debug({
|
|
142
|
+
aslTables: aslTables,
|
|
143
|
+
patchTables: patchTables
|
|
144
|
+
}, `Applying patches for...`);
|
|
145
|
+
await db.batch([
|
|
146
|
+
...$d7a7877f07ff6c69$var$buildCopyStatements(patchTables, aslTables, (0, $e5a23c058b2763fa$export$a17a6870a08b950e).Page, [
|
|
147
|
+
'id',
|
|
148
|
+
'content',
|
|
149
|
+
'part',
|
|
150
|
+
'page',
|
|
151
|
+
'number'
|
|
152
|
+
], (0, $746504ca27eabe49$export$1f75c01d8a920a35)($d7a7877f07ff6c69$var$PATCH_DB_ALIAS, (0, $e5a23c058b2763fa$export$a17a6870a08b950e).Page)),
|
|
153
|
+
...$d7a7877f07ff6c69$var$buildCopyStatements(patchTables, aslTables, (0, $e5a23c058b2763fa$export$a17a6870a08b950e).Title, [
|
|
154
|
+
'id',
|
|
155
|
+
'content',
|
|
156
|
+
'page',
|
|
157
|
+
'parent'
|
|
158
|
+
], (0, $746504ca27eabe49$export$a38d1618b943c74f)($d7a7877f07ff6c69$var$PATCH_DB_ALIAS, (0, $e5a23c058b2763fa$export$a17a6870a08b950e).Title))
|
|
159
|
+
]);
|
|
160
|
+
return db.batch([
|
|
161
|
+
(0, $746504ca27eabe49$export$7fec5208c714b262)($d7a7877f07ff6c69$var$ASL_DB_ALIAS),
|
|
162
|
+
(0, $746504ca27eabe49$export$7fec5208c714b262)($d7a7877f07ff6c69$var$PATCH_DB_ALIAS)
|
|
163
|
+
]);
|
|
164
|
+
};
|
|
165
|
+
const $d7a7877f07ff6c69$export$61101aa23c771e7c = async (db, aslDB)=>{
|
|
166
|
+
await db.execute((0, $746504ca27eabe49$export$ee56083bb7df7ecc)(aslDB, $d7a7877f07ff6c69$var$ASL_DB_ALIAS));
|
|
167
|
+
const tables = await (0, $26460f21c4456828$export$1d57574773c8bc58)(db, $d7a7877f07ff6c69$var$ASL_DB_ALIAS);
|
|
168
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).debug({
|
|
119
169
|
tables: tables
|
|
120
170
|
}, `Applying patches for...`);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (patchDB) detachStatements.push((0, $e6f751831b705ed8$export$7fec5208c714b262)($2a3b237385dd2cff$var$PATCH_DB_ALIAS));
|
|
127
|
-
return db.batch(detachStatements);
|
|
171
|
+
await db.batch([
|
|
172
|
+
`INSERT INTO main.${(0, $e5a23c058b2763fa$export$a17a6870a08b950e).Title} SELECT id,content,page,parent FROM ${$d7a7877f07ff6c69$var$ASL_DB_ALIAS}.${(0, $e5a23c058b2763fa$export$a17a6870a08b950e).Title}`,
|
|
173
|
+
`INSERT INTO main.${(0, $e5a23c058b2763fa$export$a17a6870a08b950e).Page} SELECT id,content,part,page,number FROM ${$d7a7877f07ff6c69$var$ASL_DB_ALIAS}.${(0, $e5a23c058b2763fa$export$a17a6870a08b950e).Page}`
|
|
174
|
+
]);
|
|
175
|
+
return db.execute((0, $746504ca27eabe49$export$7fec5208c714b262)($d7a7877f07ff6c69$var$ASL_DB_ALIAS));
|
|
128
176
|
};
|
|
129
|
-
const $
|
|
177
|
+
const $d7a7877f07ff6c69$export$5d28a6b0dd65e4c4 = async (db)=>{
|
|
130
178
|
return db.batch([
|
|
131
179
|
`CREATE TABLE page (id INTEGER PRIMARY KEY, content TEXT, part INTEGER, page INTEGER, number INTEGER)`,
|
|
132
180
|
`CREATE TABLE title (id INTEGER PRIMARY KEY, content TEXT, page INTEGER, parent INTEGER)`
|
|
133
181
|
]);
|
|
134
182
|
};
|
|
135
|
-
const $
|
|
136
|
-
const rows = await (0, $
|
|
183
|
+
const $d7a7877f07ff6c69$export$3bd13330ac8e761e = async (db)=>{
|
|
184
|
+
const rows = await (0, $26460f21c4456828$export$3274d151f0598f1)(db, (0, $e5a23c058b2763fa$export$a17a6870a08b950e).Page);
|
|
137
185
|
const pages = rows.map((row)=>{
|
|
138
186
|
const { content: content, id: id, number: number, page: page, part: part } = row;
|
|
139
187
|
return {
|
|
@@ -152,8 +200,8 @@ const $2a3b237385dd2cff$export$3bd13330ac8e761e = async (db)=>{
|
|
|
152
200
|
});
|
|
153
201
|
return pages;
|
|
154
202
|
};
|
|
155
|
-
const $
|
|
156
|
-
const rows = await (0, $
|
|
203
|
+
const $d7a7877f07ff6c69$export$8987cf231214301f = async (db)=>{
|
|
204
|
+
const rows = await (0, $26460f21c4456828$export$3274d151f0598f1)(db, (0, $e5a23c058b2763fa$export$a17a6870a08b950e).Title);
|
|
157
205
|
const titles = rows.map((row)=>{
|
|
158
206
|
const r = row;
|
|
159
207
|
return {
|
|
@@ -167,70 +215,54 @@ const $2a3b237385dd2cff$export$8987cf231214301f = async (db)=>{
|
|
|
167
215
|
});
|
|
168
216
|
return titles;
|
|
169
217
|
};
|
|
170
|
-
const $
|
|
218
|
+
const $d7a7877f07ff6c69$export$7a171f172be0782e = async (db)=>{
|
|
171
219
|
const [pages, titles] = await Promise.all([
|
|
172
|
-
$
|
|
173
|
-
$
|
|
220
|
+
$d7a7877f07ff6c69$export$3bd13330ac8e761e(db),
|
|
221
|
+
$d7a7877f07ff6c69$export$8987cf231214301f(db)
|
|
174
222
|
]);
|
|
175
223
|
return {
|
|
176
224
|
pages: pages,
|
|
177
225
|
titles: titles
|
|
178
226
|
};
|
|
179
227
|
};
|
|
180
|
-
const $2a3b237385dd2cff$var$getPagesToCopy = (tables)=>{
|
|
181
|
-
const statements = [];
|
|
182
|
-
if (tables.find((t)=>t.name === (0, $167eb860ccdaab7d$export$a17a6870a08b950e).Page)) {
|
|
183
|
-
statements.push(`INSERT INTO main.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Page} SELECT id,content,part,page,number FROM ${$2a3b237385dd2cff$var$ASL_DB_ALIAS}.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Page} WHERE id IN (SELECT id FROM ${$2a3b237385dd2cff$var$PATCH_DB_ALIAS}.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Page} WHERE is_deleted='0')`);
|
|
184
|
-
statements.push((0, $e6f751831b705ed8$export$1f75c01d8a920a35)($2a3b237385dd2cff$var$PATCH_DB_ALIAS, (0, $167eb860ccdaab7d$export$a17a6870a08b950e).Page));
|
|
185
|
-
} else statements.push(`INSERT INTO main.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Page} SELECT id,content,part,page,number FROM ${$2a3b237385dd2cff$var$ASL_DB_ALIAS}.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Page} WHERE is_deleted='0'`);
|
|
186
|
-
return statements;
|
|
187
|
-
};
|
|
188
|
-
const $2a3b237385dd2cff$var$getTitlesToCopy = (tables)=>{
|
|
189
|
-
const statements = [];
|
|
190
|
-
if (tables.find((t)=>t.name === (0, $167eb860ccdaab7d$export$a17a6870a08b950e).Title)) {
|
|
191
|
-
statements.push(`INSERT INTO main.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Title} SELECT id,content,page,parent FROM ${$2a3b237385dd2cff$var$ASL_DB_ALIAS}.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Title} WHERE id IN (SELECT id FROM ${$2a3b237385dd2cff$var$PATCH_DB_ALIAS}.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Title} WHERE is_deleted='0')`);
|
|
192
|
-
statements.push((0, $e6f751831b705ed8$export$a38d1618b943c74f)($2a3b237385dd2cff$var$PATCH_DB_ALIAS, (0, $167eb860ccdaab7d$export$a17a6870a08b950e).Title));
|
|
193
|
-
} else statements.push(`INSERT INTO main.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Title} SELECT id,content,page,parent FROM ${$2a3b237385dd2cff$var$ASL_DB_ALIAS}.${(0, $167eb860ccdaab7d$export$a17a6870a08b950e).Title} WHERE is_deleted='0'`);
|
|
194
|
-
return statements;
|
|
195
|
-
};
|
|
196
228
|
|
|
197
229
|
|
|
198
230
|
|
|
199
|
-
const $
|
|
200
|
-
const $
|
|
231
|
+
const $1857efaf39b32304$export$5bc725975f47e62c = 0;
|
|
232
|
+
const $1857efaf39b32304$export$3deaf0b0365f781e = '99999';
|
|
201
233
|
|
|
202
234
|
|
|
203
235
|
|
|
204
236
|
|
|
205
237
|
|
|
206
|
-
const $
|
|
238
|
+
const $09a9521c7a529893$export$b3179f41dfd6e35b = async (db, sourceTables)=>{
|
|
207
239
|
const aliasToPath = sourceTables.reduce((acc, tablePath)=>{
|
|
208
|
-
const { name: name } = (0, $
|
|
240
|
+
const { name: name } = (0, $SK0tW$path).parse(tablePath);
|
|
209
241
|
return {
|
|
210
242
|
...acc,
|
|
211
243
|
[name]: tablePath
|
|
212
244
|
};
|
|
213
245
|
}, {});
|
|
214
|
-
const attachStatements = Object.entries(aliasToPath).map(([alias, dbPath])=>(0, $
|
|
246
|
+
const attachStatements = Object.entries(aliasToPath).map(([alias, dbPath])=>(0, $746504ca27eabe49$export$ee56083bb7df7ecc)(dbPath, alias));
|
|
215
247
|
await db.batch(attachStatements);
|
|
216
248
|
const insertStatements = [
|
|
217
|
-
`INSERT INTO ${(0, $
|
|
218
|
-
`INSERT INTO ${(0, $
|
|
219
|
-
`INSERT INTO ${(0, $
|
|
249
|
+
`INSERT INTO ${(0, $e5a23c058b2763fa$export$a17a6870a08b950e).Authors} SELECT id,name,biography,(CASE WHEN death_number = ${(0, $1857efaf39b32304$export$3deaf0b0365f781e)} THEN NULL ELSE death_number END) AS death_number FROM author WHERE is_deleted='0'`,
|
|
250
|
+
`INSERT INTO ${(0, $e5a23c058b2763fa$export$a17a6870a08b950e).Books} SELECT id,name,category,type,(CASE WHEN date = ${(0, $1857efaf39b32304$export$3deaf0b0365f781e)} THEN NULL ELSE date END) AS date,author,printed,major_release,minor_release,bibliography,hint,pdf_links,metadata FROM book WHERE is_deleted='0'`,
|
|
251
|
+
`INSERT INTO ${(0, $e5a23c058b2763fa$export$a17a6870a08b950e).Categories} SELECT id,name FROM category WHERE is_deleted='0'`
|
|
220
252
|
];
|
|
221
253
|
await db.batch(insertStatements);
|
|
222
|
-
const detachStatements = Object.keys(aliasToPath).map((0, $
|
|
254
|
+
const detachStatements = Object.keys(aliasToPath).map((0, $746504ca27eabe49$export$7fec5208c714b262));
|
|
223
255
|
await db.batch(detachStatements);
|
|
224
256
|
};
|
|
225
|
-
const $
|
|
257
|
+
const $09a9521c7a529893$export$5d28a6b0dd65e4c4 = async (db)=>{
|
|
226
258
|
return db.batch([
|
|
227
259
|
`CREATE TABLE authors (id INTEGER PRIMARY KEY, name TEXT, biography TEXT, death INTEGER)`,
|
|
228
260
|
`CREATE TABLE books (id INTEGER PRIMARY KEY, name TEXT, category INTEGER, type INTEGER, date INTEGER, author TEXT, printed INTEGER, major INTEGER, minor INTEGER, bibliography TEXT, hint TEXT, pdf_links TEXT, metadata TEXT)`,
|
|
229
261
|
`CREATE TABLE categories (id INTEGER PRIMARY KEY, name TEXT)`
|
|
230
262
|
]);
|
|
231
263
|
};
|
|
232
|
-
const $
|
|
233
|
-
const rows = await (0, $
|
|
264
|
+
const $09a9521c7a529893$export$b3b931905baa18df = async (db)=>{
|
|
265
|
+
const rows = await (0, $26460f21c4456828$export$3274d151f0598f1)(db, (0, $e5a23c058b2763fa$export$a17a6870a08b950e).Authors);
|
|
234
266
|
const authors = rows.map((r)=>({
|
|
235
267
|
...r.biography && {
|
|
236
268
|
biography: r.biography
|
|
@@ -243,12 +275,12 @@ const $e19722dabbedc0a6$export$b3b931905baa18df = async (db)=>{
|
|
|
243
275
|
}));
|
|
244
276
|
return authors;
|
|
245
277
|
};
|
|
246
|
-
const $
|
|
247
|
-
const rows = await (0, $
|
|
278
|
+
const $09a9521c7a529893$export$7111c27bf38a004f = async (db)=>{
|
|
279
|
+
const rows = await (0, $26460f21c4456828$export$3274d151f0598f1)(db, (0, $e5a23c058b2763fa$export$a17a6870a08b950e).Books);
|
|
248
280
|
const books = rows.map((row)=>{
|
|
249
281
|
const r = row;
|
|
250
282
|
return {
|
|
251
|
-
author: $
|
|
283
|
+
author: $09a9521c7a529893$var$parseAuthor(r.author),
|
|
252
284
|
bibliography: r.bibliography,
|
|
253
285
|
category: r.category,
|
|
254
286
|
id: r.id,
|
|
@@ -257,14 +289,14 @@ const $e19722dabbedc0a6$export$7111c27bf38a004f = async (db)=>{
|
|
|
257
289
|
name: r.name,
|
|
258
290
|
printed: r.printed,
|
|
259
291
|
type: r.type,
|
|
260
|
-
...r.date && r.date.toString() !== (0, $
|
|
292
|
+
...r.date && r.date.toString() !== (0, $1857efaf39b32304$export$3deaf0b0365f781e) && {
|
|
261
293
|
date: r.date
|
|
262
294
|
},
|
|
263
295
|
...r.hint && {
|
|
264
296
|
hint: r.hint
|
|
265
297
|
},
|
|
266
298
|
...r.pdf_links && {
|
|
267
|
-
pdfLinks: $
|
|
299
|
+
pdfLinks: $09a9521c7a529893$var$parsePdfLinks(r.pdf_links)
|
|
268
300
|
},
|
|
269
301
|
...r.minor && {
|
|
270
302
|
minorRelease: r.minor
|
|
@@ -273,22 +305,22 @@ const $e19722dabbedc0a6$export$7111c27bf38a004f = async (db)=>{
|
|
|
273
305
|
});
|
|
274
306
|
return books;
|
|
275
307
|
};
|
|
276
|
-
const $
|
|
277
|
-
const rows = await (0, $
|
|
308
|
+
const $09a9521c7a529893$export$36bfd9279b3a24b7 = async (db)=>{
|
|
309
|
+
const rows = await (0, $26460f21c4456828$export$3274d151f0598f1)(db, (0, $e5a23c058b2763fa$export$a17a6870a08b950e).Categories);
|
|
278
310
|
const categories = rows.map((r)=>({
|
|
279
311
|
id: r.id,
|
|
280
312
|
name: r.name
|
|
281
313
|
}));
|
|
282
314
|
return categories;
|
|
283
315
|
};
|
|
284
|
-
const $
|
|
285
|
-
const result = value.split(
|
|
316
|
+
const $09a9521c7a529893$var$parseAuthor = (value)=>{
|
|
317
|
+
const result = value.split(',\\s+').map((id)=>parseInt(id.trim()));
|
|
286
318
|
return result.length > 1 ? result : result[0];
|
|
287
319
|
};
|
|
288
|
-
const $
|
|
320
|
+
const $09a9521c7a529893$var$parsePdfLinks = (value)=>{
|
|
289
321
|
const result = JSON.parse(value);
|
|
290
322
|
if (result.files) result.files = result.files.map((f)=>{
|
|
291
|
-
const [file, id] = f.split(
|
|
323
|
+
const [file, id] = f.split('|');
|
|
292
324
|
return {
|
|
293
325
|
...id && {
|
|
294
326
|
id: id
|
|
@@ -298,11 +330,11 @@ const $e19722dabbedc0a6$var$parsePdfLinks = (value)=>{
|
|
|
298
330
|
});
|
|
299
331
|
return result;
|
|
300
332
|
};
|
|
301
|
-
const $
|
|
333
|
+
const $09a9521c7a529893$export$7a171f172be0782e = async (db)=>{
|
|
302
334
|
const [authors, books, categories] = await Promise.all([
|
|
303
|
-
$
|
|
304
|
-
$
|
|
305
|
-
$
|
|
335
|
+
$09a9521c7a529893$export$b3b931905baa18df(db),
|
|
336
|
+
$09a9521c7a529893$export$7111c27bf38a004f(db),
|
|
337
|
+
$09a9521c7a529893$export$36bfd9279b3a24b7(db)
|
|
306
338
|
]);
|
|
307
339
|
return {
|
|
308
340
|
authors: authors,
|
|
@@ -319,59 +351,59 @@ const $e19722dabbedc0a6$export$7a171f172be0782e = async (db)=>{
|
|
|
319
351
|
|
|
320
352
|
|
|
321
353
|
|
|
322
|
-
const $
|
|
323
|
-
const tempDirBase = (0, $
|
|
324
|
-
return (0, $
|
|
354
|
+
const $fd2c9bc034ddc705$export$1c500f521ad591da = async (prefix = 'shamela')=>{
|
|
355
|
+
const tempDirBase = (0, $SK0tW$path).join((0, $SK0tW$os).tmpdir(), prefix);
|
|
356
|
+
return (0, $SK0tW$promises).mkdtemp(tempDirBase);
|
|
325
357
|
};
|
|
326
|
-
const $
|
|
327
|
-
async function $
|
|
358
|
+
const $fd2c9bc034ddc705$export$ffc21166d570a16 = async (path)=>!!await (0, $SK0tW$promises).stat(path).catch(()=>false);
|
|
359
|
+
async function $fd2c9bc034ddc705$export$fb61e277af91ac0(url, outputDir) {
|
|
328
360
|
const extractedFiles = [];
|
|
329
361
|
const entryPromises = [];
|
|
330
362
|
try {
|
|
331
363
|
// Make HTTPS request and get the response stream
|
|
332
364
|
const response = await new Promise((resolve, reject)=>{
|
|
333
|
-
(0, $
|
|
365
|
+
(0, $SK0tW$https).get(url, (res)=>{
|
|
334
366
|
if (res.statusCode !== 200) reject(new Error(`Failed to download ZIP file: ${res.statusCode} ${res.statusMessage}`));
|
|
335
367
|
else resolve(res);
|
|
336
|
-
}).on(
|
|
368
|
+
}).on('error', (err)=>{
|
|
337
369
|
reject(new Error(`HTTPS request failed: ${err.message}`));
|
|
338
370
|
});
|
|
339
371
|
});
|
|
340
372
|
// Create unzip stream
|
|
341
|
-
const unzipStream = (0, $
|
|
373
|
+
const unzipStream = (0, $SK0tW$unzipper).Parse();
|
|
342
374
|
// Handle entries in the ZIP file
|
|
343
|
-
unzipStream.on(
|
|
375
|
+
unzipStream.on('entry', (entry)=>{
|
|
344
376
|
const entryPromise = (async ()=>{
|
|
345
|
-
const filePath = (0, $
|
|
346
|
-
if (entry.type ===
|
|
377
|
+
const filePath = (0, $SK0tW$path).join(outputDir, entry.path);
|
|
378
|
+
if (entry.type === 'Directory') {
|
|
347
379
|
// Ensure the directory exists
|
|
348
|
-
await (0, $
|
|
380
|
+
await (0, $SK0tW$promises).mkdir(filePath, {
|
|
349
381
|
recursive: true
|
|
350
382
|
});
|
|
351
383
|
entry.autodrain();
|
|
352
384
|
} else {
|
|
353
385
|
// Ensure the parent directory exists
|
|
354
|
-
const dir = (0, $
|
|
355
|
-
await (0, $
|
|
386
|
+
const dir = (0, $SK0tW$path).dirname(filePath);
|
|
387
|
+
await (0, $SK0tW$promises).mkdir(dir, {
|
|
356
388
|
recursive: true
|
|
357
389
|
});
|
|
358
390
|
// Pipe the entry to a file
|
|
359
|
-
await (0, $
|
|
391
|
+
await (0, $SK0tW$pipeline)(entry, (0, $SK0tW$createWriteStream)(filePath));
|
|
360
392
|
extractedFiles.push(filePath);
|
|
361
393
|
}
|
|
362
394
|
})().catch((err)=>{
|
|
363
395
|
// Emit errors to be handled by the unzipStream error handler
|
|
364
|
-
unzipStream.emit(
|
|
396
|
+
unzipStream.emit('error', err);
|
|
365
397
|
});
|
|
366
398
|
// Collect the promises
|
|
367
399
|
entryPromises.push(entryPromise);
|
|
368
400
|
});
|
|
369
401
|
// Handle errors in the unzip stream
|
|
370
|
-
unzipStream.on(
|
|
402
|
+
unzipStream.on('error', (err)=>{
|
|
371
403
|
throw new Error(`Error during extraction: ${err.message}`);
|
|
372
404
|
});
|
|
373
405
|
// Pipe the response into the unzip stream
|
|
374
|
-
await (0, $
|
|
406
|
+
await (0, $SK0tW$pipeline)(response, unzipStream);
|
|
375
407
|
// Wait for all entry promises to complete
|
|
376
408
|
await Promise.all(entryPromises);
|
|
377
409
|
return extractedFiles;
|
|
@@ -386,37 +418,37 @@ async function $e8ee15c0ce3f020d$export$fb61e277af91ac0(url, outputDir) {
|
|
|
386
418
|
|
|
387
419
|
|
|
388
420
|
|
|
389
|
-
const $
|
|
390
|
-
const url = new (0, $
|
|
421
|
+
const $59b98b7fd5edf160$export$b5cd97dee32de81d = (endpoint, params, useAuth = true)=>{
|
|
422
|
+
const url = new (0, $SK0tW$URL)(endpoint);
|
|
391
423
|
{
|
|
392
|
-
const params = new (0, $
|
|
424
|
+
const params = new (0, $SK0tW$URLSearchParams)();
|
|
393
425
|
Object.entries(params).forEach(([key, value])=>{
|
|
394
426
|
params.append(key, value.toString());
|
|
395
427
|
});
|
|
396
|
-
if (useAuth) params.append(
|
|
428
|
+
if (useAuth) params.append('api_key', (0, $SK0tW$process).env.SHAMELA_API_KEY);
|
|
397
429
|
url.search = params.toString();
|
|
398
430
|
}
|
|
399
431
|
return url;
|
|
400
432
|
};
|
|
401
|
-
const $
|
|
433
|
+
const $59b98b7fd5edf160$export$c9e6217566c54f42 = (url)=>{
|
|
402
434
|
return new Promise((resolve, reject)=>{
|
|
403
|
-
(0, $
|
|
404
|
-
const contentType = res.headers[
|
|
435
|
+
(0, $SK0tW$https).get(url, (res)=>{
|
|
436
|
+
const contentType = res.headers['content-type'] || '';
|
|
405
437
|
const dataChunks = [];
|
|
406
|
-
res.on(
|
|
438
|
+
res.on('data', (chunk)=>{
|
|
407
439
|
dataChunks.push(chunk);
|
|
408
440
|
});
|
|
409
|
-
res.on(
|
|
410
|
-
const fullData = (0, $
|
|
411
|
-
if (contentType.includes(
|
|
412
|
-
const json = JSON.parse(fullData.toString(
|
|
441
|
+
res.on('end', ()=>{
|
|
442
|
+
const fullData = (0, $SK0tW$Buffer).concat(dataChunks);
|
|
443
|
+
if (contentType.includes('application/json')) try {
|
|
444
|
+
const json = JSON.parse(fullData.toString('utf-8'));
|
|
413
445
|
resolve(json);
|
|
414
446
|
} catch (error) {
|
|
415
447
|
reject(new Error(`Failed to parse JSON: ${error.message}`));
|
|
416
448
|
}
|
|
417
449
|
else resolve(fullData);
|
|
418
450
|
});
|
|
419
|
-
}).on(
|
|
451
|
+
}).on('error', (error)=>{
|
|
420
452
|
reject(new Error(`Error making request: ${error.message}`));
|
|
421
453
|
});
|
|
422
454
|
});
|
|
@@ -425,34 +457,34 @@ const $932b4b3755196b46$export$c9e6217566c54f42 = (url)=>{
|
|
|
425
457
|
|
|
426
458
|
|
|
427
459
|
|
|
428
|
-
const $
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
460
|
+
const $6605706916cc9c29$var$SOURCE_TABLES = [
|
|
461
|
+
'author.sqlite',
|
|
462
|
+
'book.sqlite',
|
|
463
|
+
'category.sqlite'
|
|
432
464
|
];
|
|
433
|
-
const $
|
|
434
|
-
if (!(0, $
|
|
435
|
-
if (!(0, $
|
|
465
|
+
const $6605706916cc9c29$export$37467b7f8cfc50b0 = ()=>{
|
|
466
|
+
if (!(0, $SK0tW$process).env.SHAMELA_API_MASTER_PATCH_ENDPOINT) throw new Error('SHAMELA_API_MASTER_PATCH_ENDPOINT environment variable not set');
|
|
467
|
+
if (!(0, $SK0tW$process).env.SHAMELA_API_KEY) throw new Error('SHAMELA_API_KEY environment variable not set');
|
|
436
468
|
};
|
|
437
|
-
const $
|
|
438
|
-
const sourceTableNames = sourceTablePaths.map((tablePath)=>(0, $
|
|
439
|
-
return $
|
|
469
|
+
const $6605706916cc9c29$export$c7660b0cda39b7c3 = (sourceTablePaths)=>{
|
|
470
|
+
const sourceTableNames = sourceTablePaths.map((tablePath)=>(0, $SK0tW$path).parse(tablePath).base);
|
|
471
|
+
return $6605706916cc9c29$var$SOURCE_TABLES.every((table)=>sourceTableNames.includes(table));
|
|
440
472
|
};
|
|
441
473
|
|
|
442
474
|
|
|
443
|
-
const $
|
|
444
|
-
(0, $
|
|
445
|
-
const url = new (0, $
|
|
475
|
+
const $e6ba238abdbefe7a$export$4c209aa17b4b3e57 = async (id, options)=>{
|
|
476
|
+
(0, $6605706916cc9c29$export$37467b7f8cfc50b0)();
|
|
477
|
+
const url = new (0, $SK0tW$URL)(`${(0, $SK0tW$process).env.SHAMELA_API_BOOKS_ENDPOINT}/${id}`);
|
|
446
478
|
{
|
|
447
|
-
const params = new (0, $
|
|
448
|
-
params.append(
|
|
449
|
-
params.append(
|
|
450
|
-
params.append(
|
|
479
|
+
const params = new (0, $SK0tW$URLSearchParams)();
|
|
480
|
+
params.append('api_key', (0, $SK0tW$process).env.SHAMELA_API_KEY);
|
|
481
|
+
params.append('major_release', (options?.majorVersion || 0).toString());
|
|
482
|
+
params.append('minor_release', (options?.minorVersion || 0).toString());
|
|
451
483
|
url.search = params.toString();
|
|
452
484
|
}
|
|
453
|
-
(0, $
|
|
485
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`Fetching shamela.ws book link: ${url.toString()}`);
|
|
454
486
|
try {
|
|
455
|
-
const response = await (0, $
|
|
487
|
+
const response = await (0, $59b98b7fd5edf160$export$c9e6217566c54f42)(url);
|
|
456
488
|
return {
|
|
457
489
|
majorRelease: response.major_release,
|
|
458
490
|
majorReleaseUrl: response.major_release_url,
|
|
@@ -467,33 +499,38 @@ const $96cb7a03b537cb37$export$4c209aa17b4b3e57 = async (id, options)=>{
|
|
|
467
499
|
throw new Error(`Error fetching master patch: ${error.message}`);
|
|
468
500
|
}
|
|
469
501
|
};
|
|
470
|
-
const $
|
|
471
|
-
(0, $
|
|
472
|
-
const outputDir = await (0, $
|
|
473
|
-
const bookResponse = options?.bookMetadata || await $
|
|
502
|
+
const $e6ba238abdbefe7a$export$3560c45fd9de930d = async (id, options)=>{
|
|
503
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`downloadBook ${id} ${JSON.stringify(options)}`);
|
|
504
|
+
const outputDir = await (0, $fd2c9bc034ddc705$export$1c500f521ad591da)('shamela_downloadBook');
|
|
505
|
+
const bookResponse = options?.bookMetadata || await $e6ba238abdbefe7a$export$4c209aa17b4b3e57(id);
|
|
474
506
|
const [[bookDatabase], [patchDatabase] = []] = await Promise.all([
|
|
475
|
-
(0, $
|
|
507
|
+
(0, $fd2c9bc034ddc705$export$fb61e277af91ac0)(bookResponse.majorReleaseUrl, outputDir),
|
|
476
508
|
...bookResponse.minorReleaseUrl ? [
|
|
477
|
-
(0, $
|
|
509
|
+
(0, $fd2c9bc034ddc705$export$fb61e277af91ac0)(bookResponse.minorReleaseUrl, outputDir)
|
|
478
510
|
] : []
|
|
479
511
|
]);
|
|
480
|
-
const dbPath = (0, $
|
|
481
|
-
const client = (0, $
|
|
512
|
+
const dbPath = (0, $SK0tW$path).join(outputDir, 'book.db');
|
|
513
|
+
const client = (0, $SK0tW$createClient)({
|
|
482
514
|
url: `file:${dbPath}`
|
|
483
515
|
});
|
|
484
516
|
try {
|
|
485
|
-
(0, $
|
|
486
|
-
await (0, $
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
await (0, $
|
|
517
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`Creating tables`);
|
|
518
|
+
await (0, $d7a7877f07ff6c69$export$5d28a6b0dd65e4c4)(client);
|
|
519
|
+
if (patchDatabase) {
|
|
520
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`Applying patches from ${patchDatabase} to ${bookDatabase}`);
|
|
521
|
+
await (0, $d7a7877f07ff6c69$export$a8b8e03e6bbe5473)(client, bookDatabase, patchDatabase);
|
|
522
|
+
} else {
|
|
523
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`Copying table data from ${bookDatabase}`);
|
|
524
|
+
await (0, $d7a7877f07ff6c69$export$61101aa23c771e7c)(client, bookDatabase);
|
|
525
|
+
}
|
|
526
|
+
const { ext: extension } = (0, $SK0tW$path).parse(options.outputFile.path);
|
|
527
|
+
if (extension === '.json') {
|
|
528
|
+
const result = await (0, $d7a7877f07ff6c69$export$7a171f172be0782e)(client);
|
|
529
|
+
await (0, $SK0tW$promises).writeFile(options.outputFile.path, JSON.stringify(result, undefined, 2), 'utf8');
|
|
493
530
|
}
|
|
494
531
|
client.close();
|
|
495
|
-
if (extension ===
|
|
496
|
-
await (0, $
|
|
532
|
+
if (extension === '.db' || extension === '.sqlite') await (0, $SK0tW$promises).rename(dbPath, options.outputFile.path);
|
|
533
|
+
await (0, $SK0tW$promises).rm(outputDir, {
|
|
497
534
|
recursive: true
|
|
498
535
|
});
|
|
499
536
|
} finally{
|
|
@@ -501,18 +538,18 @@ const $96cb7a03b537cb37$export$3560c45fd9de930d = async (id, options)=>{
|
|
|
501
538
|
}
|
|
502
539
|
return options.outputFile.path;
|
|
503
540
|
};
|
|
504
|
-
const $
|
|
505
|
-
(0, $
|
|
506
|
-
const url = new (0, $
|
|
541
|
+
const $e6ba238abdbefe7a$export$b96de494209cdc35 = async (version = 0)=>{
|
|
542
|
+
(0, $6605706916cc9c29$export$37467b7f8cfc50b0)();
|
|
543
|
+
const url = new (0, $SK0tW$URL)((0, $SK0tW$process).env.SHAMELA_API_MASTER_PATCH_ENDPOINT);
|
|
507
544
|
{
|
|
508
|
-
const params = new (0, $
|
|
509
|
-
params.append(
|
|
510
|
-
params.append(
|
|
545
|
+
const params = new (0, $SK0tW$URLSearchParams)();
|
|
546
|
+
params.append('api_key', (0, $SK0tW$process).env.SHAMELA_API_KEY);
|
|
547
|
+
params.append('version', version.toString());
|
|
511
548
|
url.search = params.toString();
|
|
512
549
|
}
|
|
513
|
-
(0, $
|
|
550
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`Fetching shamela.ws master database patch link: ${url.toString()}`);
|
|
514
551
|
try {
|
|
515
|
-
const response = await (0, $
|
|
552
|
+
const response = await (0, $59b98b7fd5edf160$export$c9e6217566c54f42)(url);
|
|
516
553
|
return {
|
|
517
554
|
url: response.patch_url,
|
|
518
555
|
version: response.version
|
|
@@ -521,34 +558,34 @@ const $96cb7a03b537cb37$export$b96de494209cdc35 = async (version = 0)=>{
|
|
|
521
558
|
throw new Error(`Error fetching master patch: ${error.message}`);
|
|
522
559
|
}
|
|
523
560
|
};
|
|
524
|
-
const $
|
|
525
|
-
(0, $
|
|
526
|
-
const outputDir = await (0, $
|
|
527
|
-
const masterResponse = options.masterMetadata || await $
|
|
528
|
-
(0, $
|
|
529
|
-
const sourceTables = await (0, $
|
|
530
|
-
(0, $
|
|
531
|
-
if (!(0, $
|
|
532
|
-
(0, $
|
|
533
|
-
throw new Error(
|
|
561
|
+
const $e6ba238abdbefe7a$export$fd8b6353fde3f1de = async (options)=>{
|
|
562
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`downloadMasterDatabase ${JSON.stringify(options)}`);
|
|
563
|
+
const outputDir = await (0, $fd2c9bc034ddc705$export$1c500f521ad591da)('shamela_downloadMaster');
|
|
564
|
+
const masterResponse = options.masterMetadata || await $e6ba238abdbefe7a$export$b96de494209cdc35((0, $1857efaf39b32304$export$5bc725975f47e62c));
|
|
565
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`Downloading master database from: ${JSON.stringify(masterResponse)}`);
|
|
566
|
+
const sourceTables = await (0, $fd2c9bc034ddc705$export$fb61e277af91ac0)(masterResponse.url, outputDir);
|
|
567
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`sourceTables downloaded: ${sourceTables.toString()}`);
|
|
568
|
+
if (!(0, $6605706916cc9c29$export$c7660b0cda39b7c3)(sourceTables)) {
|
|
569
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).error(`Some source tables were not found: ${sourceTables.toString()}`);
|
|
570
|
+
throw new Error('Expected tables not found!');
|
|
534
571
|
}
|
|
535
|
-
const dbPath = (0, $
|
|
536
|
-
const client = (0, $
|
|
572
|
+
const dbPath = (0, $SK0tW$path).join(outputDir, 'master.db');
|
|
573
|
+
const client = (0, $SK0tW$createClient)({
|
|
537
574
|
url: `file:${dbPath}`
|
|
538
575
|
});
|
|
539
576
|
try {
|
|
540
|
-
(0, $
|
|
541
|
-
await (0, $
|
|
542
|
-
(0, $
|
|
543
|
-
await (0, $
|
|
544
|
-
const { ext: extension } = (0, $
|
|
545
|
-
if (extension ===
|
|
546
|
-
const result = await (0, $
|
|
547
|
-
await (0, $
|
|
577
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`Creating tables`);
|
|
578
|
+
await (0, $09a9521c7a529893$export$5d28a6b0dd65e4c4)(client);
|
|
579
|
+
(0, $526b48a37e8a8ec6$export$2e2bcd8739ae039).info(`Copying data to master table`);
|
|
580
|
+
await (0, $09a9521c7a529893$export$b3179f41dfd6e35b)(client, sourceTables);
|
|
581
|
+
const { ext: extension } = (0, $SK0tW$path).parse(options.outputFile.path);
|
|
582
|
+
if (extension === '.json') {
|
|
583
|
+
const result = await (0, $09a9521c7a529893$export$7a171f172be0782e)(client);
|
|
584
|
+
await (0, $SK0tW$promises).writeFile(options.outputFile.path, JSON.stringify(result, undefined, 2), 'utf8');
|
|
548
585
|
}
|
|
549
586
|
client.close();
|
|
550
|
-
if (extension ===
|
|
551
|
-
await (0, $
|
|
587
|
+
if (extension === '.db' || extension === '.sqlite') await (0, $SK0tW$promises).rename(dbPath, options.outputFile.path);
|
|
588
|
+
await (0, $SK0tW$promises).rm(outputDir, {
|
|
552
589
|
recursive: true
|
|
553
590
|
});
|
|
554
591
|
} finally{
|
|
@@ -556,22 +593,25 @@ const $96cb7a03b537cb37$export$fd8b6353fde3f1de = async (options)=>{
|
|
|
556
593
|
}
|
|
557
594
|
return options.outputFile.path;
|
|
558
595
|
};
|
|
559
|
-
const $
|
|
560
|
-
const outputDir = await (0, $
|
|
561
|
-
const outputPath = await $
|
|
596
|
+
const $e6ba238abdbefe7a$export$be7c2acc48adceee = async (id)=>{
|
|
597
|
+
const outputDir = await (0, $fd2c9bc034ddc705$export$1c500f521ad591da)('shamela_getBookData');
|
|
598
|
+
const outputPath = await $e6ba238abdbefe7a$export$3560c45fd9de930d(id, {
|
|
562
599
|
outputFile: {
|
|
563
|
-
path: (0, $
|
|
600
|
+
path: (0, $SK0tW$path).join(outputDir, `${id}.json`)
|
|
564
601
|
}
|
|
565
602
|
});
|
|
566
|
-
const data = JSON.parse(await (0, $
|
|
567
|
-
await (0, $
|
|
603
|
+
const data = JSON.parse(await (0, $SK0tW$promises).readFile(outputPath, 'utf8'));
|
|
604
|
+
await (0, $SK0tW$promises).rm(outputDir, {
|
|
568
605
|
recursive: true
|
|
569
606
|
});
|
|
570
607
|
return data;
|
|
571
608
|
};
|
|
572
609
|
|
|
573
610
|
|
|
611
|
+
var $e9528ebec83086b6$exports = {};
|
|
612
|
+
|
|
613
|
+
|
|
574
614
|
|
|
575
615
|
|
|
576
|
-
export {$
|
|
616
|
+
export {$e6ba238abdbefe7a$export$3560c45fd9de930d as downloadBook, $e6ba238abdbefe7a$export$fd8b6353fde3f1de as downloadMasterDatabase, $e6ba238abdbefe7a$export$be7c2acc48adceee as getBook, $e6ba238abdbefe7a$export$4c209aa17b4b3e57 as getBookMetadata, $e6ba238abdbefe7a$export$b96de494209cdc35 as getMasterMetadata};
|
|
577
617
|
//# sourceMappingURL=main.js.map
|