node-sword-interface 1.0.97 → 1.0.99
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/API.md +22 -17
- package/examples/install_kjv.js +1 -1
- package/index.js +15 -11
- package/package.json +1 -1
- package/scripts/build_sword.sh +1 -1
- package/src/napi_module/install_module_worker.cpp +2 -1
- package/src/napi_module/install_module_worker.hpp +3 -0
- package/src/napi_module/node_sword_interface.cpp +65 -12
- package/src/node_sword_cli.cpp +10 -10
- package/src/sword_backend/module_installer.cpp +0 -12
- package/src/sword_backend/module_installer.hpp +0 -1
- package/src/sword_backend/text_processor.cpp +48 -3
- package/src/sword_backend/text_processor.hpp +2 -1
package/API.md
CHANGED
|
@@ -39,17 +39,17 @@ This is the main class of node-sword-interface and it provides a set of static f
|
|
|
39
39
|
* [.getAllRepoModules(repositoryName, moduleType)](#NodeSwordInterface+getAllRepoModules) ⇒ [<code>Array.<ModuleObject></code>](#ModuleObject)
|
|
40
40
|
* [.getRepoModulesByLang(repositoryName, language, moduleType, headersFilter, strongsFilter, hebrewStrongsKeys, greekStrongsKeys)](#NodeSwordInterface+getRepoModulesByLang) ⇒ [<code>Array.<ModuleObject></code>](#ModuleObject)
|
|
41
41
|
* [.getUpdatedRepoModules(repositoryName, includeBeta)](#NodeSwordInterface+getUpdatedRepoModules) ⇒ [<code>Array.<ModuleObject></code>](#ModuleObject)
|
|
42
|
-
* [.getRepoModule(moduleCode)](#NodeSwordInterface+getRepoModule) ⇒ [<code>ModuleObject</code>](#ModuleObject)
|
|
42
|
+
* [.getRepoModule(repositoryName, moduleCode)](#NodeSwordInterface+getRepoModule) ⇒ [<code>ModuleObject</code>](#ModuleObject)
|
|
43
43
|
* [.getAllLocalModules(moduleType)](#NodeSwordInterface+getAllLocalModules) ⇒ [<code>Array.<ModuleObject></code>](#ModuleObject)
|
|
44
44
|
* [.getRepoModuleCount(repositoryName, moduleType)](#NodeSwordInterface+getRepoModuleCount) ⇒ <code>Number</code>
|
|
45
45
|
* [.getRepoLanguageModuleCount(repositoryName, language, moduleType)](#NodeSwordInterface+getRepoLanguageModuleCount) ⇒ <code>Number</code>
|
|
46
|
-
* [.installModule(moduleCode, progressCB)](#NodeSwordInterface+installModule) ⇒ <code>Promise</code>
|
|
46
|
+
* [.installModule(repositoryName, moduleCode, progressCB)](#NodeSwordInterface+installModule) ⇒ <code>Promise</code>
|
|
47
47
|
* [.cancelInstallation()](#NodeSwordInterface+cancelInstallation)
|
|
48
48
|
* [.uninstallModule(moduleCode)](#NodeSwordInterface+uninstallModule) ⇒ <code>Promise</code>
|
|
49
49
|
* [.refreshLocalModules()](#NodeSwordInterface+refreshLocalModules)
|
|
50
50
|
* [.saveModuleUnlockKey(moduleCode, key)](#NodeSwordInterface+saveModuleUnlockKey)
|
|
51
51
|
* [.isModuleReadable(moduleCode)](#NodeSwordInterface+isModuleReadable) ⇒ <code>Boolean</code>
|
|
52
|
-
* [.getModuleDescription(moduleCode)](#NodeSwordInterface+getModuleDescription) ⇒ <code>String</code>
|
|
52
|
+
* [.getModuleDescription(repositoryName, moduleCode)](#NodeSwordInterface+getModuleDescription) ⇒ <code>String</code>
|
|
53
53
|
* [.enableMarkup()](#NodeSwordInterface+enableMarkup)
|
|
54
54
|
* [.disableMarkup()](#NodeSwordInterface+disableMarkup)
|
|
55
55
|
* [.enableStrongsWithNbsp()](#NodeSwordInterface+enableStrongsWithNbsp)
|
|
@@ -77,7 +77,7 @@ This is the main class of node-sword-interface and it provides a set of static f
|
|
|
77
77
|
* [.getStrongsEntry(strongsKey)](#NodeSwordInterface+getStrongsEntry) ⇒ [<code>StrongsEntry</code>](#StrongsEntry)
|
|
78
78
|
* [.getLocalModule(moduleCode)](#NodeSwordInterface+getLocalModule) ⇒ [<code>ModuleObject</code>](#ModuleObject)
|
|
79
79
|
* [.isModuleInUserDir(moduleCode)](#NodeSwordInterface+isModuleInUserDir) ⇒ <code>Boolean</code>
|
|
80
|
-
* [.isModuleAvailableInRepo(moduleCode)](#NodeSwordInterface+isModuleAvailableInRepo) ⇒ <code>Boolean</code>
|
|
80
|
+
* [.isModuleAvailableInRepo(moduleCode, repositoryName)](#NodeSwordInterface+isModuleAvailableInRepo) ⇒ <code>Boolean</code>
|
|
81
81
|
* [.getSwordTranslation(originalString, localeCode)](#NodeSwordInterface+getSwordTranslation)
|
|
82
82
|
* [.getBookAbbreviation(moduleName, bookCode, localeCode)](#NodeSwordInterface+getBookAbbreviation)
|
|
83
83
|
* [.unTarGZ(filePath, destPath)](#NodeSwordInterface+unTarGZ) ⇒ <code>Boolean</code>
|
|
@@ -90,11 +90,12 @@ This is the main class of node-sword-interface and it provides a set of static f
|
|
|
90
90
|
### new NodeSwordInterface(customHomeDir, localesBasePath, timeoutMillis)
|
|
91
91
|
Creates an instance of NodeSwordInterface.
|
|
92
92
|
|
|
93
|
+
|
|
93
94
|
| Param | Type | Default | Description |
|
|
94
95
|
| --- | --- | --- | --- |
|
|
95
|
-
| customHomeDir | <code>String</code> |
|
|
96
|
-
| localesBasePath | <code>String</code> |
|
|
97
|
-
| timeoutMillis | <code>Number</code> | <code>20000</code> | Optional timeout in milliseconds for repository operations
|
|
96
|
+
| customHomeDir | <code>String</code> | | Optional custom home directory for SWORD data. |
|
|
97
|
+
| localesBasePath | <code>String</code> | | Optional base path for locales (default: __dirname). |
|
|
98
|
+
| timeoutMillis | <code>Number</code> | <code>20000</code> | Optional timeout in milliseconds for repository operations (default: 20000). |
|
|
98
99
|
|
|
99
100
|
<a name="NodeSwordInterface+repositoryConfigExisting"></a>
|
|
100
101
|
|
|
@@ -189,13 +190,14 @@ Returns all updated modules from all repositories or one specific repository.
|
|
|
189
190
|
|
|
190
191
|
<a name="NodeSwordInterface+getRepoModule"></a>
|
|
191
192
|
|
|
192
|
-
### nodeSwordInterface.getRepoModule(moduleCode) ⇒ [<code>ModuleObject</code>](#ModuleObject)
|
|
193
|
+
### nodeSwordInterface.getRepoModule(repositoryName, moduleCode) ⇒ [<code>ModuleObject</code>](#ModuleObject)
|
|
193
194
|
Returns an object representation of a SWORD module from a repository.
|
|
194
195
|
|
|
195
196
|
**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
|
|
196
197
|
|
|
197
198
|
| Param | Type | Description |
|
|
198
199
|
| --- | --- | --- |
|
|
200
|
+
| repositoryName | <code>String</code> | The name of the repository to search in. |
|
|
199
201
|
| moduleCode | <code>String</code> | The module code of the SWORD module. |
|
|
200
202
|
|
|
201
203
|
<a name="NodeSwordInterface+getAllLocalModules"></a>
|
|
@@ -239,9 +241,9 @@ Returns the number of modules for a given repository and language (default: Bibl
|
|
|
239
241
|
|
|
240
242
|
<a name="NodeSwordInterface+installModule"></a>
|
|
241
243
|
|
|
242
|
-
### nodeSwordInterface.installModule(moduleCode, progressCB) ⇒ <code>Promise</code>
|
|
243
|
-
Installs a module. The
|
|
244
|
-
|
|
244
|
+
### nodeSwordInterface.installModule(repositoryName, moduleCode, progressCB) ⇒ <code>Promise</code>
|
|
245
|
+
Installs a module. The module is downloaded from the corresponding repository
|
|
246
|
+
and then installed in the local SWORD directory.
|
|
245
247
|
This operation may take some time depending on the available bandwidth and geographical
|
|
246
248
|
distance to the SWORD repository server.
|
|
247
249
|
|
|
@@ -255,6 +257,7 @@ If the installation fails, the Promise will be rejected with the following statu
|
|
|
255
257
|
|
|
256
258
|
| Param | Type | Description |
|
|
257
259
|
| --- | --- | --- |
|
|
260
|
+
| repositoryName | <code>String</code> | The name of the repository from which to install. |
|
|
258
261
|
| moduleCode | <code>String</code> | The module code of the SWORD module that shall be installed. |
|
|
259
262
|
| progressCB | <code>function</code> | Callback function that is called on progress events. |
|
|
260
263
|
|
|
@@ -310,7 +313,7 @@ Checks whether the module is readable.
|
|
|
310
313
|
|
|
311
314
|
<a name="NodeSwordInterface+getModuleDescription"></a>
|
|
312
315
|
|
|
313
|
-
### nodeSwordInterface.getModuleDescription(moduleCode) ⇒ <code>String</code>
|
|
316
|
+
### nodeSwordInterface.getModuleDescription(repositoryName, moduleCode) ⇒ <code>String</code>
|
|
314
317
|
Returns the description of a module.
|
|
315
318
|
|
|
316
319
|
**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
|
|
@@ -318,6 +321,7 @@ Returns the description of a module.
|
|
|
318
321
|
|
|
319
322
|
| Param | Type | Description |
|
|
320
323
|
| --- | --- | --- |
|
|
324
|
+
| repositoryName | <code>String</code> | The name of the repository to search in. |
|
|
321
325
|
| moduleCode | <code>String</code> | The module code of the SWORD module. |
|
|
322
326
|
|
|
323
327
|
<a name="NodeSwordInterface+enableMarkup"></a>
|
|
@@ -623,14 +627,15 @@ Checks whether the module resides in the user directory.
|
|
|
623
627
|
|
|
624
628
|
<a name="NodeSwordInterface+isModuleAvailableInRepo"></a>
|
|
625
629
|
|
|
626
|
-
### nodeSwordInterface.isModuleAvailableInRepo(moduleCode) ⇒ <code>Boolean</code>
|
|
627
|
-
Checks whether the module is available in any repository.
|
|
630
|
+
### nodeSwordInterface.isModuleAvailableInRepo(moduleCode, repositoryName) ⇒ <code>Boolean</code>
|
|
631
|
+
Checks whether the module is available in any repository (default) or in a specific repository.
|
|
628
632
|
|
|
629
633
|
**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
|
|
630
634
|
|
|
631
|
-
| Param | Type | Description |
|
|
632
|
-
| --- | --- | --- |
|
|
633
|
-
| moduleCode | <code>String</code> | The module code of the SWORD module. |
|
|
635
|
+
| Param | Type | Default | Description |
|
|
636
|
+
| --- | --- | --- | --- |
|
|
637
|
+
| moduleCode | <code>String</code> | | The module code of the SWORD module. |
|
|
638
|
+
| repositoryName | <code>String</code> | <code>all</code> | The name of the repository to check. |
|
|
634
639
|
|
|
635
640
|
<a name="NodeSwordInterface+getSwordTranslation"></a>
|
|
636
641
|
|
package/examples/install_kjv.js
CHANGED
|
@@ -27,7 +27,7 @@ async function installKJV() {
|
|
|
27
27
|
|
|
28
28
|
console.log("Installing King James module");
|
|
29
29
|
// Install the King James Version (Uses the internet connection to download and install the module)
|
|
30
|
-
await interface.installModule('KJV');
|
|
30
|
+
await interface.installModule('CrossWire', 'KJV');
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
installKJV().then(() => {
|
package/index.js
CHANGED
|
@@ -213,11 +213,12 @@ class NodeSwordInterface {
|
|
|
213
213
|
/**
|
|
214
214
|
* Returns an object representation of a SWORD module from a repository.
|
|
215
215
|
*
|
|
216
|
+
* @param {String} repositoryName - The name of the repository to search in.
|
|
216
217
|
* @param {String} moduleCode - The module code of the SWORD module.
|
|
217
218
|
* @return {ModuleObject}
|
|
218
219
|
*/
|
|
219
|
-
getRepoModule(moduleCode) {
|
|
220
|
-
return this.nativeInterface.getRepoModule(moduleCode);
|
|
220
|
+
getRepoModule(repositoryName, moduleCode) {
|
|
221
|
+
return this.nativeInterface.getRepoModule(repositoryName, moduleCode);
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
/**
|
|
@@ -253,8 +254,8 @@ class NodeSwordInterface {
|
|
|
253
254
|
}
|
|
254
255
|
|
|
255
256
|
/**
|
|
256
|
-
* Installs a module. The
|
|
257
|
-
*
|
|
257
|
+
* Installs a module. The module is downloaded from the corresponding repository
|
|
258
|
+
* and then installed in the local SWORD directory.
|
|
258
259
|
* This operation may take some time depending on the available bandwidth and geographical
|
|
259
260
|
* distance to the SWORD repository server.
|
|
260
261
|
*
|
|
@@ -264,17 +265,18 @@ class NodeSwordInterface {
|
|
|
264
265
|
* -1: General installation issue
|
|
265
266
|
* -9: Installation cancelled by user or internet connection suddenly interrupted
|
|
266
267
|
*
|
|
268
|
+
* @param {String} repositoryName - The name of the repository from which to install.
|
|
267
269
|
* @param {String} moduleCode - The module code of the SWORD module that shall be installed.
|
|
268
270
|
* @param {Function} progressCB - Callback function that is called on progress events.
|
|
269
271
|
* @return {Promise}
|
|
270
272
|
*/
|
|
271
|
-
async installModule(moduleCode, progressCB=undefined) {
|
|
273
|
+
async installModule(repositoryName, moduleCode, progressCB=undefined) {
|
|
272
274
|
if (progressCB === undefined) {
|
|
273
275
|
progressCB = function(progress) {};
|
|
274
276
|
}
|
|
275
277
|
|
|
276
278
|
return new Promise((resolve, reject) => {
|
|
277
|
-
this.nativeInterface.installModule(moduleCode, progressCB, function(result) {
|
|
279
|
+
this.nativeInterface.installModule(repositoryName, moduleCode, progressCB, function(result) {
|
|
278
280
|
if (result == 0) {
|
|
279
281
|
resolve();
|
|
280
282
|
} else {
|
|
@@ -343,11 +345,12 @@ class NodeSwordInterface {
|
|
|
343
345
|
/**
|
|
344
346
|
* Returns the description of a module.
|
|
345
347
|
*
|
|
348
|
+
* @param {String} repositoryName - The name of the repository to search in.
|
|
346
349
|
* @param {String} moduleCode - The module code of the SWORD module.
|
|
347
350
|
* @return {String} The description of the respective module.
|
|
348
351
|
*/
|
|
349
|
-
getModuleDescription(moduleCode) {
|
|
350
|
-
return this.nativeInterface.getModuleDescription(moduleCode);
|
|
352
|
+
getModuleDescription(repositoryName, moduleCode) {
|
|
353
|
+
return this.nativeInterface.getModuleDescription(repositoryName, moduleCode);
|
|
351
354
|
}
|
|
352
355
|
|
|
353
356
|
/**
|
|
@@ -730,13 +733,14 @@ class NodeSwordInterface {
|
|
|
730
733
|
}
|
|
731
734
|
|
|
732
735
|
/**
|
|
733
|
-
* Checks whether the module is available in any repository.
|
|
736
|
+
* Checks whether the module is available in any repository (default) or in a specific repository.
|
|
734
737
|
*
|
|
735
738
|
* @param {String} moduleCode - The module code of the SWORD module.
|
|
739
|
+
* @param {String} repositoryName - The name of the repository to check.
|
|
736
740
|
* @return {Boolean}
|
|
737
741
|
*/
|
|
738
|
-
isModuleAvailableInRepo(moduleCode) {
|
|
739
|
-
return this.nativeInterface.isModuleAvailableInRepo(moduleCode);
|
|
742
|
+
isModuleAvailableInRepo(moduleCode, repositoryName="all") {
|
|
743
|
+
return this.nativeInterface.isModuleAvailableInRepo(moduleCode, repositoryName);
|
|
740
744
|
}
|
|
741
745
|
|
|
742
746
|
/**
|
package/package.json
CHANGED
package/scripts/build_sword.sh
CHANGED
|
@@ -80,7 +80,8 @@ void InstallModuleWorker::Execute(const ExecutionProgress& progress)
|
|
|
80
80
|
this->_totalPercent = 0;
|
|
81
81
|
this->_filePercent = 0;
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
// Always use repository-specific installation
|
|
84
|
+
this->_result = this->_moduleInstaller.installModule(this->_repoName, this->_moduleName);
|
|
84
85
|
|
|
85
86
|
statusReporter.resetCallbacks();
|
|
86
87
|
unlockApi();
|
|
@@ -29,12 +29,14 @@ public:
|
|
|
29
29
|
ModuleInstaller& moduleInstaller,
|
|
30
30
|
const Napi::Function& jsProgressCallback,
|
|
31
31
|
const Napi::Function& callback,
|
|
32
|
+
std::string repoName,
|
|
32
33
|
std::string moduleName)
|
|
33
34
|
|
|
34
35
|
: ProgressWorker(repoInterface,
|
|
35
36
|
jsProgressCallback,
|
|
36
37
|
callback),
|
|
37
38
|
_moduleInstaller(moduleInstaller),
|
|
39
|
+
_repoName(repoName),
|
|
38
40
|
_moduleName(moduleName) {}
|
|
39
41
|
|
|
40
42
|
void swordPreStatusCB(long totalBytes, long completedBytes, const char *message);
|
|
@@ -46,6 +48,7 @@ private:
|
|
|
46
48
|
ModuleInstaller& _moduleInstaller;
|
|
47
49
|
int _result;
|
|
48
50
|
std::string _moduleName;
|
|
51
|
+
std::string _repoName;
|
|
49
52
|
long _completedBytes = 0;
|
|
50
53
|
long _totalBytes = 0;
|
|
51
54
|
int _totalPercent = 0;
|
|
@@ -324,9 +324,23 @@ Napi::Value NodeSwordInterface::isModuleInUserDir(const Napi::CallbackInfo& info
|
|
|
324
324
|
Napi::Value NodeSwordInterface::isModuleAvailableInRepo(const Napi::CallbackInfo& info)
|
|
325
325
|
{
|
|
326
326
|
lockApi();
|
|
327
|
-
INIT_SCOPE_AND_VALIDATE(ParamType::string);
|
|
327
|
+
INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string);
|
|
328
328
|
Napi::String moduleName = info[0].As<Napi::String>();
|
|
329
|
-
|
|
329
|
+
Napi::String repoName = info[1].As<Napi::String>();
|
|
330
|
+
|
|
331
|
+
if (string(moduleName).empty()) {
|
|
332
|
+
Napi::TypeError::New(info.Env(), "Module name cannot be empty").ThrowAsJavaScriptException();
|
|
333
|
+
unlockApi();
|
|
334
|
+
return info.Env().Null();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (string(repoName).empty()) {
|
|
338
|
+
Napi::TypeError::New(info.Env(), "Repository name cannot be empty").ThrowAsJavaScriptException();
|
|
339
|
+
unlockApi();
|
|
340
|
+
return info.Env().Null();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
bool moduleAvailable = this->_repoInterface->isModuleAvailableInRepo(moduleName, repoName);
|
|
330
344
|
unlockApi();
|
|
331
345
|
return Napi::Boolean::New(info.Env(), moduleAvailable);
|
|
332
346
|
}
|
|
@@ -469,11 +483,23 @@ Napi::Value NodeSwordInterface::getRepoModule(const Napi::CallbackInfo& info)
|
|
|
469
483
|
{
|
|
470
484
|
lockApi();
|
|
471
485
|
Napi::Env env = info.Env();
|
|
472
|
-
INIT_SCOPE_AND_VALIDATE(ParamType::string);
|
|
486
|
+
INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string);
|
|
473
487
|
Napi::Object napiObject = Napi::Object::New(env);
|
|
474
|
-
Napi::String
|
|
488
|
+
Napi::String repoName = info[0].As<Napi::String>();
|
|
489
|
+
Napi::String moduleName = info[1].As<Napi::String>();
|
|
490
|
+
|
|
491
|
+
if (string(repoName).empty()) {
|
|
492
|
+
Napi::TypeError::New(env, "Repository name cannot be empty").ThrowAsJavaScriptException();
|
|
493
|
+
unlockApi();
|
|
494
|
+
return env.Null();
|
|
495
|
+
}
|
|
475
496
|
|
|
476
|
-
|
|
497
|
+
if (string(moduleName).empty()) {
|
|
498
|
+
Napi::TypeError::New(env, "Module name cannot be empty").ThrowAsJavaScriptException();
|
|
499
|
+
unlockApi();
|
|
500
|
+
return env.Null();
|
|
501
|
+
}
|
|
502
|
+
|
|
477
503
|
SWModule* swordModule = this->_repoInterface->getRepoModule(moduleName, repoName);
|
|
478
504
|
|
|
479
505
|
if (swordModule == 0) {
|
|
@@ -492,10 +518,23 @@ Napi::Value NodeSwordInterface::getModuleDescription(const Napi::CallbackInfo& i
|
|
|
492
518
|
{
|
|
493
519
|
lockApi();
|
|
494
520
|
Napi::Env env = info.Env();
|
|
495
|
-
INIT_SCOPE_AND_VALIDATE(ParamType::string);
|
|
496
|
-
Napi::String
|
|
521
|
+
INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string);
|
|
522
|
+
Napi::String repoName = info[0].As<Napi::String>();
|
|
523
|
+
Napi::String moduleName = info[1].As<Napi::String>();
|
|
524
|
+
|
|
525
|
+
if (string(repoName).empty()) {
|
|
526
|
+
Napi::TypeError::New(env, "Repository name cannot be empty").ThrowAsJavaScriptException();
|
|
527
|
+
unlockApi();
|
|
528
|
+
return env.Null();
|
|
529
|
+
}
|
|
497
530
|
|
|
498
|
-
|
|
531
|
+
if (string(moduleName).empty()) {
|
|
532
|
+
Napi::TypeError::New(env, "Module name cannot be empty").ThrowAsJavaScriptException();
|
|
533
|
+
unlockApi();
|
|
534
|
+
return env.Null();
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
SWModule* swordModule = this->_repoInterface->getRepoModule(moduleName, repoName);
|
|
499
538
|
if (swordModule == 0) {
|
|
500
539
|
string errorMessage = "getRepoModule returned 0 for '" + string(moduleName) + "'";
|
|
501
540
|
THROW_JS_EXCEPTION(errorMessage);
|
|
@@ -867,15 +906,29 @@ Napi::Value NodeSwordInterface::getStrongsEntry(const Napi::CallbackInfo& info)
|
|
|
867
906
|
Napi::Value NodeSwordInterface::installModule(const Napi::CallbackInfo& info)
|
|
868
907
|
{
|
|
869
908
|
lockApi();
|
|
870
|
-
INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::function, ParamType::function);
|
|
871
|
-
Napi::String
|
|
872
|
-
Napi::
|
|
873
|
-
Napi::Function
|
|
909
|
+
INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string, ParamType::function, ParamType::function);
|
|
910
|
+
Napi::String repoName = info[0].As<Napi::String>();
|
|
911
|
+
Napi::String moduleName = info[1].As<Napi::String>();
|
|
912
|
+
Napi::Function progressCallback = info[2].As<Napi::Function>();
|
|
913
|
+
Napi::Function callback = info[3].As<Napi::Function>();
|
|
914
|
+
|
|
915
|
+
if (string(repoName).empty()) {
|
|
916
|
+
Napi::TypeError::New(info.Env(), "Repository name cannot be empty").ThrowAsJavaScriptException();
|
|
917
|
+
unlockApi();
|
|
918
|
+
return info.Env().Null();
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
if (string(moduleName).empty()) {
|
|
922
|
+
Napi::TypeError::New(info.Env(), "Module name cannot be empty").ThrowAsJavaScriptException();
|
|
923
|
+
unlockApi();
|
|
924
|
+
return info.Env().Null();
|
|
925
|
+
}
|
|
874
926
|
|
|
875
927
|
InstallModuleWorker* worker = new InstallModuleWorker(*(this->_repoInterface),
|
|
876
928
|
*(this->_moduleInstaller),
|
|
877
929
|
progressCallback,
|
|
878
930
|
callback,
|
|
931
|
+
repoName,
|
|
879
932
|
moduleName);
|
|
880
933
|
worker->Queue();
|
|
881
934
|
return info.Env().Undefined();
|
package/src/node_sword_cli.cpp
CHANGED
|
@@ -105,11 +105,11 @@ void get_module_text(TextProcessor& text_processor)
|
|
|
105
105
|
{
|
|
106
106
|
cout << "Text:" << endl;
|
|
107
107
|
text_processor.enableMarkup();
|
|
108
|
-
vector<Verse> verses = text_processor.getBookText("
|
|
108
|
+
vector<Verse> verses = text_processor.getBookText("NET", "Luke");
|
|
109
109
|
cout << "Got " << verses.size() << " verses!" << endl;
|
|
110
|
-
|
|
110
|
+
for (int i = 0; i < 10; i++) {
|
|
111
111
|
cout << verses[i].reference << "|" << verses[i].content << endl;
|
|
112
|
-
}
|
|
112
|
+
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
void get_reference_text(ModuleStore& module_store, TextProcessor& text_processor)
|
|
@@ -157,7 +157,7 @@ void get_dict_key_list(DictHelper& dict_helper)
|
|
|
157
157
|
void test_unlock_key(ModuleInstaller& module_installer, ModuleStore& module_store, TextProcessor& text_processor)
|
|
158
158
|
{
|
|
159
159
|
module_installer.uninstallModule("NA28");
|
|
160
|
-
module_installer.installModule("NA28");
|
|
160
|
+
module_installer.installModule("Deutsche Bibelgesellschaft", "NA28");
|
|
161
161
|
module_installer.saveModuleUnlockKey("NA28", "");
|
|
162
162
|
SWModule* m = module_store.getLocalModule("NA28");
|
|
163
163
|
cout << "Module readable: " << text_processor.isModuleReadable(m) << endl;
|
|
@@ -220,17 +220,17 @@ int main(int argc, char** argv)
|
|
|
220
220
|
|
|
221
221
|
show_modules(repoInterface);
|
|
222
222
|
|
|
223
|
-
/*int error = moduleInstaller.installModule("UKJV");
|
|
223
|
+
/*int error = moduleInstaller.installModule("CrossWire", "UKJV");
|
|
224
224
|
|
|
225
225
|
if (error) {
|
|
226
226
|
cout << "Error installing module (write permissions?)\n";
|
|
227
|
-
}
|
|
227
|
+
}*/
|
|
228
228
|
|
|
229
|
-
error = moduleInstaller.uninstallModule("
|
|
229
|
+
int error = moduleInstaller.uninstallModule("YLT");
|
|
230
230
|
|
|
231
231
|
if (error) {
|
|
232
232
|
cout << "Error uninstalling module (write permissions?)\n";
|
|
233
|
-
}
|
|
233
|
+
}
|
|
234
234
|
|
|
235
235
|
/*get_local_module(moduleStore);
|
|
236
236
|
|
|
@@ -241,9 +241,9 @@ int main(int argc, char** argv)
|
|
|
241
241
|
|
|
242
242
|
//get_strongs_entry(textProcessor);
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
get_module_text(textProcessor);
|
|
245
245
|
|
|
246
|
-
get_reference_text(moduleStore, textProcessor);
|
|
246
|
+
//get_reference_text(moduleStore, textProcessor);
|
|
247
247
|
|
|
248
248
|
//get_book_intro(textProcessor);
|
|
249
249
|
|
|
@@ -57,18 +57,6 @@ void ModuleInstaller::resetAllMgrs()
|
|
|
57
57
|
this->refreshMgr();
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
int ModuleInstaller::installModule(string moduleName)
|
|
61
|
-
{
|
|
62
|
-
string repoName = this->_repoInterface.getModuleRepo(moduleName);
|
|
63
|
-
|
|
64
|
-
if (repoName == "") {
|
|
65
|
-
cerr << "Could not find repository for module " << moduleName << endl;
|
|
66
|
-
return -1;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return this->installModule(repoName, moduleName);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
60
|
int ModuleInstaller::installModule(string repoName, string moduleName)
|
|
73
61
|
{
|
|
74
62
|
InstallSource* remoteSource = this->_repoInterface.getRemoteSource(repoName);
|
|
@@ -37,7 +37,6 @@ public:
|
|
|
37
37
|
ModuleInstaller(RepositoryInterface& repoInterface, ModuleStore& moduleStore, std::string customHomeDir="");
|
|
38
38
|
virtual ~ModuleInstaller();
|
|
39
39
|
|
|
40
|
-
int installModule(std::string moduleName);
|
|
41
40
|
int installModule(std::string repoName, std::string moduleName);
|
|
42
41
|
void cancelInstallation();
|
|
43
42
|
int uninstallModule(std::string moduleName);
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
// Own includes
|
|
32
32
|
#include "text_processor.hpp"
|
|
33
|
+
#include "module_store.hpp"
|
|
33
34
|
#include "module_helper.hpp"
|
|
34
35
|
#include "string_helper.hpp"
|
|
35
36
|
#include "strongs_entry.hpp"
|
|
@@ -45,7 +46,32 @@ TextProcessor::TextProcessor(ModuleStore& moduleStore, ModuleHelper& moduleHelpe
|
|
|
45
46
|
this->_rawMarkupEnabled = false;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
string TextProcessor::
|
|
49
|
+
string TextProcessor::getFileUrl(const string& nativePath)
|
|
50
|
+
{
|
|
51
|
+
if (nativePath.empty()) {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
string path = nativePath;
|
|
56
|
+
|
|
57
|
+
// Strip trailing slash or backslash
|
|
58
|
+
if (!path.empty() && (path.back() == '/' || path.back() == '\\')) {
|
|
59
|
+
path.pop_back();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Convert backslashes to forward slashes for URL compatibility
|
|
63
|
+
static regex backslash("\\\\");
|
|
64
|
+
path = regex_replace(path, backslash, "/");
|
|
65
|
+
|
|
66
|
+
// Build file:// URL (Windows needs extra slash for drive letter)
|
|
67
|
+
#if _WIN32
|
|
68
|
+
return "file:///" + path;
|
|
69
|
+
#else
|
|
70
|
+
return "file://" + path;
|
|
71
|
+
#endif
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
string TextProcessor::getFilteredText(const string& text, int chapter, int verseNr, bool hasStrongs, bool hasInconsistentClosingEndDivs, const string& moduleDataPath)
|
|
49
75
|
{
|
|
50
76
|
static string chapterFilter = "<chapter";
|
|
51
77
|
static regex pbElement = regex("<pb .*?/> ");
|
|
@@ -218,6 +244,14 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
|
|
|
218
244
|
filteredText = this->replaceSpacesInStrongs(filteredText);
|
|
219
245
|
}
|
|
220
246
|
|
|
247
|
+
// Prefix img src attributes starting with "/" with the module data path as a file:// URL
|
|
248
|
+
if (!moduleDataPath.empty()) {
|
|
249
|
+
string fileUrl = this->getFileUrl(moduleDataPath);
|
|
250
|
+
static string imgSrcSlash = "src=\"/";
|
|
251
|
+
string imgSrcReplacement = "src=\"" + fileUrl + "/";
|
|
252
|
+
this->findAndReplaceAll(filteredText, imgSrcSlash, imgSrcReplacement);
|
|
253
|
+
}
|
|
254
|
+
|
|
221
255
|
return filteredText;
|
|
222
256
|
}
|
|
223
257
|
|
|
@@ -254,7 +288,8 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
|
|
|
254
288
|
// Therefore we do not render chapter headings for the first verse of the chapter in this case.
|
|
255
289
|
chapterHeading = "";
|
|
256
290
|
} else {
|
|
257
|
-
|
|
291
|
+
string moduleDataPath = this->_moduleStore.getModuleDataPath(module);
|
|
292
|
+
chapterHeading = this->getFilteredText(chapterHeading, currentChapter, currentVerseNr, false, false, moduleDataPath);
|
|
258
293
|
}
|
|
259
294
|
}
|
|
260
295
|
|
|
@@ -275,7 +310,8 @@ string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStron
|
|
|
275
310
|
filteredText = verseText;
|
|
276
311
|
|
|
277
312
|
if (!this->_rawMarkupEnabled) {
|
|
278
|
-
|
|
313
|
+
string moduleDataPath = this->_moduleStore.getModuleDataPath(module);
|
|
314
|
+
filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasInconsistentClosingEndDivs, moduleDataPath);
|
|
279
315
|
}
|
|
280
316
|
} else {
|
|
281
317
|
verseText = string(module->stripText());
|
|
@@ -522,6 +558,15 @@ string TextProcessor::getBookIntroduction(string moduleName, string bookCode)
|
|
|
522
558
|
filteredText = regex_replace(filteredText, headStartElementFilter, "<div class=\"sword-markup sword-head\"");
|
|
523
559
|
filteredText = regex_replace(filteredText, headEndElementFilter, "</div>");
|
|
524
560
|
filteredText = regex_replace(filteredText, chapterDivFilter, "");
|
|
561
|
+
|
|
562
|
+
// Prefix img src attributes starting with "/" with the module data path as a file:// URL
|
|
563
|
+
string moduleDataPath = this->_moduleStore.getModuleDataPath(module);
|
|
564
|
+
if (!moduleDataPath.empty()) {
|
|
565
|
+
string fileUrl = this->getFileUrl(moduleDataPath);
|
|
566
|
+
static string imgSrcSlash = "src=\"/";
|
|
567
|
+
string imgSrcReplacement = "src=\"" + fileUrl + "/";
|
|
568
|
+
this->findAndReplaceAll(filteredText, imgSrcSlash, imgSrcReplacement);
|
|
569
|
+
}
|
|
525
570
|
}
|
|
526
571
|
|
|
527
572
|
return filteredText;
|
|
@@ -64,7 +64,8 @@ private:
|
|
|
64
64
|
int verseCount=-1);
|
|
65
65
|
|
|
66
66
|
std::string getCurrentChapterHeading(sword::SWModule* module);
|
|
67
|
-
std::string getFilteredText(const std::string& text, int chapter, int verseNr, bool hasStrongs=false, bool hasInconsistentClosingEndDivs=false);
|
|
67
|
+
std::string getFilteredText(const std::string& text, int chapter, int verseNr, bool hasStrongs=false, bool hasInconsistentClosingEndDivs=false, const std::string& moduleDataPath="");
|
|
68
|
+
std::string getFileUrl(const std::string& nativePath);
|
|
68
69
|
std::string replaceSpacesInStrongs(const std::string& text);
|
|
69
70
|
unsigned int findAndReplaceAll(std::string & data, std::string toSearch, std::string replaceStr);
|
|
70
71
|
|