node-sword-interface 1.0.95 → 1.0.97
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 +12 -0
- package/CMakeLists.txt +2 -0
- package/index.js +8 -2
- package/package.json +1 -1
- package/src/napi_module/node_sword_interface.cpp +8 -1
- package/src/node_sword_cli.cpp +18 -1
- package/src/sword_backend/repository_interface.cpp +9 -3
- package/src/sword_backend/repository_interface.hpp +3 -1
- package/src/sword_backend/text_processor.cpp +2 -0
package/API.md
CHANGED
|
@@ -31,6 +31,7 @@ This is the main class of node-sword-interface and it provides a set of static f
|
|
|
31
31
|
**Kind**: global class
|
|
32
32
|
|
|
33
33
|
* [NodeSwordInterface](#NodeSwordInterface)
|
|
34
|
+
* [new NodeSwordInterface(customHomeDir, localesBasePath, timeoutMillis)](#new_NodeSwordInterface_new)
|
|
34
35
|
* [.repositoryConfigExisting()](#NodeSwordInterface+repositoryConfigExisting) ⇒ <code>Boolean</code>
|
|
35
36
|
* [.updateRepositoryConfig(progressCB)](#NodeSwordInterface+updateRepositoryConfig) ⇒ <code>Promise</code>
|
|
36
37
|
* [.getRepoNames()](#NodeSwordInterface+getRepoNames) ⇒ <code>Array.<String></code>
|
|
@@ -84,6 +85,17 @@ This is the main class of node-sword-interface and it provides a set of static f
|
|
|
84
85
|
* [.getSwordVersion()](#NodeSwordInterface+getSwordVersion) ⇒ <code>String</code>
|
|
85
86
|
* [.getSwordPath()](#NodeSwordInterface+getSwordPath) ⇒ <code>String</code>
|
|
86
87
|
|
|
88
|
+
<a name="new_NodeSwordInterface_new"></a>
|
|
89
|
+
|
|
90
|
+
### new NodeSwordInterface(customHomeDir, localesBasePath, timeoutMillis)
|
|
91
|
+
Creates an instance of NodeSwordInterface.
|
|
92
|
+
|
|
93
|
+
| Param | Type | Default | Description |
|
|
94
|
+
| --- | --- | --- | --- |
|
|
95
|
+
| customHomeDir | <code>String</code> | <code>undefined</code> | Optional custom home directory for SWORD data. |
|
|
96
|
+
| localesBasePath | <code>String</code> | <code>__dirname</code> | Optional base path for locales. |
|
|
97
|
+
| timeoutMillis | <code>Number</code> | <code>20000</code> | Optional timeout in milliseconds for repository operations. Invalid values (≤ 0 or non-numeric) trigger a warning and fallback to the default. |
|
|
98
|
+
|
|
87
99
|
<a name="NodeSwordInterface+repositoryConfigExisting"></a>
|
|
88
100
|
|
|
89
101
|
### nodeSwordInterface.repositoryConfigExisting() ⇒ <code>Boolean</code>
|
package/CMakeLists.txt
CHANGED
|
@@ -46,6 +46,8 @@ ${CMAKE_SOURCE_DIR}/src/sword_backend/module_installer.cpp
|
|
|
46
46
|
${CMAKE_SOURCE_DIR}/src/sword_backend/text_processor.cpp
|
|
47
47
|
${CMAKE_SOURCE_DIR}/src/sword_backend/module_search.cpp
|
|
48
48
|
${CMAKE_SOURCE_DIR}/src/sword_backend/mutex.cpp
|
|
49
|
+
${CMAKE_SOURCE_DIR}/src/sword_backend/unzip/ioapi.c
|
|
50
|
+
${CMAKE_SOURCE_DIR}/src/sword_backend/unzip/unzip.c
|
|
49
51
|
)
|
|
50
52
|
|
|
51
53
|
add_executable(node_sword_cli ${SOURCES})
|
package/index.js
CHANGED
|
@@ -105,9 +105,15 @@ const searchMutex = new Mutex();
|
|
|
105
105
|
|
|
106
106
|
/** This is the main class of node-sword-interface and it provides a set of static functions that wrap SWORD library functionality. */
|
|
107
107
|
class NodeSwordInterface {
|
|
108
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Creates an instance of NodeSwordInterface.
|
|
110
|
+
* @param {String} customHomeDir - Optional custom home directory for SWORD data.
|
|
111
|
+
* @param {String} localesBasePath - Optional base path for locales (default: __dirname).
|
|
112
|
+
* @param {Number} timeoutMillis - Optional timeout in milliseconds for repository operations (default: 20000).
|
|
113
|
+
*/
|
|
114
|
+
constructor(customHomeDir=undefined, localesBasePath=__dirname, timeoutMillis=20000) {
|
|
109
115
|
var localesDir = path.join(localesBasePath, './locales.d');
|
|
110
|
-
this.nativeInterface = new nodeSwordInterfaceModule.NodeSwordInterface(customHomeDir, localesDir);
|
|
116
|
+
this.nativeInterface = new nodeSwordInterfaceModule.NodeSwordInterface(customHomeDir, localesDir, timeoutMillis);
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
/**
|
package/package.json
CHANGED
|
@@ -151,6 +151,7 @@ NodeSwordInterface::NodeSwordInterface(const Napi::CallbackInfo& info) : Napi::O
|
|
|
151
151
|
|
|
152
152
|
std::string localeDir = "";
|
|
153
153
|
this->customHomeDir = "";
|
|
154
|
+
long timeoutMillis = 20000;
|
|
154
155
|
|
|
155
156
|
bool homeDirError = false;
|
|
156
157
|
bool localeDirError = false;
|
|
@@ -177,11 +178,17 @@ NodeSwordInterface::NodeSwordInterface(const Napi::CallbackInfo& info) : Napi::O
|
|
|
177
178
|
localeDirError = true;
|
|
178
179
|
}
|
|
179
180
|
|
|
181
|
+
if (info[2].IsNumber()) {
|
|
182
|
+
timeoutMillis = info[2].As<Napi::Number>().Int64Value();
|
|
183
|
+
} else if (!info[2].IsUndefined() && !info[2].IsNull()) {
|
|
184
|
+
cerr << "Warning: Invalid timeoutMillis value (not a number), using default (20000)" << endl;
|
|
185
|
+
}
|
|
186
|
+
|
|
180
187
|
if (!homeDirError && !localeDirError) { // We only proceed if there has not been any issue with the homeDir or localeDir
|
|
181
188
|
this->_moduleStore = new ModuleStore(this->customHomeDir);
|
|
182
189
|
this->_moduleHelper = new ModuleHelper(*(this->_moduleStore));
|
|
183
190
|
this->_dictHelper = new DictHelper(*(this->_moduleStore));
|
|
184
|
-
this->_repoInterface = new RepositoryInterface(this->_swordStatusReporter, *(this->_moduleHelper), *(this->_moduleStore), this->customHomeDir);
|
|
191
|
+
this->_repoInterface = new RepositoryInterface(this->_swordStatusReporter, *(this->_moduleHelper), *(this->_moduleStore), this->customHomeDir, timeoutMillis);
|
|
185
192
|
this->_moduleInstaller = new ModuleInstaller(*(this->_repoInterface), *(this->_moduleStore), this->customHomeDir);
|
|
186
193
|
this->_napiSwordHelper = new NapiSwordHelper(*(this->_moduleHelper), *(this->_moduleStore));
|
|
187
194
|
this->_textProcessor = new TextProcessor(*(this->_moduleStore), *(this->_moduleHelper));
|
package/src/node_sword_cli.cpp
CHANGED
|
@@ -112,6 +112,20 @@ void get_module_text(TextProcessor& text_processor)
|
|
|
112
112
|
}*/
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
void get_reference_text(ModuleStore& module_store, TextProcessor& text_processor)
|
|
116
|
+
{
|
|
117
|
+
cout << "RAW Text:" << endl;
|
|
118
|
+
SWModule* swordModule = module_store.getLocalModule("NETnote");
|
|
119
|
+
swordModule->setKey("1 Tim 3:2");
|
|
120
|
+
string rawText = swordModule->getRawEntry();
|
|
121
|
+
cout << rawText << endl;
|
|
122
|
+
|
|
123
|
+
cout << "Processed Text: " << endl;
|
|
124
|
+
text_processor.enableMarkup();
|
|
125
|
+
Verse text = text_processor.getReferenceText("NETnote", "1 Tim 3:2");
|
|
126
|
+
cout << text.content << endl;
|
|
127
|
+
}
|
|
128
|
+
|
|
115
129
|
void get_book_intro(TextProcessor& text_processor)
|
|
116
130
|
{
|
|
117
131
|
cout << "Text:" << endl;
|
|
@@ -183,7 +197,8 @@ int main(int argc, char** argv)
|
|
|
183
197
|
ModuleHelper moduleHelper(moduleStore);
|
|
184
198
|
DictHelper dictHelper(moduleStore);
|
|
185
199
|
SwordStatusReporter statusReporter;
|
|
186
|
-
|
|
200
|
+
long timeoutMillis = 20000;
|
|
201
|
+
RepositoryInterface repoInterface(statusReporter, moduleHelper, moduleStore, "", timeoutMillis);
|
|
187
202
|
ModuleInstaller moduleInstaller(repoInterface, moduleStore);
|
|
188
203
|
TextProcessor textProcessor(moduleStore, moduleHelper);
|
|
189
204
|
ModuleSearch moduleSearch(moduleStore, moduleHelper, textProcessor);
|
|
@@ -228,6 +243,8 @@ int main(int argc, char** argv)
|
|
|
228
243
|
|
|
229
244
|
//get_module_text(textProcessor);
|
|
230
245
|
|
|
246
|
+
get_reference_text(moduleStore, textProcessor);
|
|
247
|
+
|
|
231
248
|
//get_book_intro(textProcessor);
|
|
232
249
|
|
|
233
250
|
//get_book_list(moduleHelper);
|
|
@@ -53,9 +53,16 @@ static Mutex remoteSourceUpdateMutex;
|
|
|
53
53
|
RepositoryInterface::RepositoryInterface(SwordStatusReporter& statusReporter,
|
|
54
54
|
ModuleHelper& moduleHelper,
|
|
55
55
|
ModuleStore& moduleStore,
|
|
56
|
-
string customHomeDir
|
|
56
|
+
string customHomeDir,
|
|
57
|
+
long timeoutMillis)
|
|
57
58
|
: _statusReporter(statusReporter), _moduleHelper(moduleHelper), _moduleStore(moduleStore)
|
|
58
59
|
{
|
|
60
|
+
if (timeoutMillis <= 0) {
|
|
61
|
+
cerr << "Warning: Invalid timeoutMillis value (" << timeoutMillis << "), using default (20000)" << endl;
|
|
62
|
+
this->_timeoutMillis = 20000;
|
|
63
|
+
} else {
|
|
64
|
+
this->_timeoutMillis = timeoutMillis;
|
|
65
|
+
}
|
|
59
66
|
this->_fileSystemHelper.setCustomHomeDir(customHomeDir);
|
|
60
67
|
this->resetMgr();
|
|
61
68
|
remoteSourceUpdateMutex.init();
|
|
@@ -72,8 +79,7 @@ void RepositoryInterface::resetMgr()
|
|
|
72
79
|
this->_installMgr = new InstallMgr(this->_fileSystemHelper.getInstallMgrDir().c_str(), &this->_statusReporter);
|
|
73
80
|
this->_installMgr->setUserDisclaimerConfirmed(true);
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
this->_installMgr->setTimeoutMillis(timeoutMillis);
|
|
82
|
+
this->_installMgr->setTimeoutMillis(this->_timeoutMillis);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
int RepositoryInterface::refreshRepositoryConfig()
|
|
@@ -43,7 +43,8 @@ public:
|
|
|
43
43
|
RepositoryInterface(SwordStatusReporter& statusReporter,
|
|
44
44
|
ModuleHelper& moduleHelper,
|
|
45
45
|
ModuleStore& moduleStore,
|
|
46
|
-
std::string customHomeDir=""
|
|
46
|
+
std::string customHomeDir="",
|
|
47
|
+
long timeoutMillis=20000);
|
|
47
48
|
|
|
48
49
|
virtual ~RepositoryInterface(){}
|
|
49
50
|
|
|
@@ -115,6 +116,7 @@ private:
|
|
|
115
116
|
FileSystemHelper _fileSystemHelper;
|
|
116
117
|
ModuleHelper& _moduleHelper;
|
|
117
118
|
ModuleStore& _moduleStore;
|
|
119
|
+
long _timeoutMillis = 20000;
|
|
118
120
|
};
|
|
119
121
|
|
|
120
122
|
#endif // _REPOSITORY_INTERFACE
|
|
@@ -52,6 +52,7 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
|
|
|
52
52
|
|
|
53
53
|
static string lbBeginParagraph = "<lb type=\"x-begin-paragraph\"/>";
|
|
54
54
|
static string lbEndParagraph = "<lb type=\"x-end-paragraph\"/>";
|
|
55
|
+
static string emptyParagraphElement = "<p/>";
|
|
55
56
|
static string lbElementFilter = "<lb ";
|
|
56
57
|
static string lElementFilter = "<l ";
|
|
57
58
|
static string lgElementFilter = "<lg ";
|
|
@@ -117,6 +118,7 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
|
|
|
117
118
|
this->findAndReplaceAll(filteredText, chapterFilter, "<chapter class=\"sword-markup sword-chapter\"");
|
|
118
119
|
this->findAndReplaceAll(filteredText, lbBeginParagraph, "");
|
|
119
120
|
this->findAndReplaceAll(filteredText, lbEndParagraph, " <div class=\"sword-markup sword-paragraph-end\"><br></div>");
|
|
121
|
+
this->findAndReplaceAll(filteredText, emptyParagraphElement, "");
|
|
120
122
|
this->findAndReplaceAll(filteredText, lbElementFilter, "<div class=\"sword-markup sword-lb\" ");
|
|
121
123
|
this->findAndReplaceAll(filteredText, lElementFilter, "<div class=\"sword-markup sword-l\" ");
|
|
122
124
|
this->findAndReplaceAll(filteredText, lgElementFilter, "<div class=\"sword-markup sword-lg\" ");
|