Skip to content

Commit 11765c5

Browse files
committed
0.0.3
correct database path (do not go to temp folder)
1 parent 3395942 commit 11765c5

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ Node module: @nocom_bot/mod_database_json
99
*/
1010

1111
import { JsonDB } from "node-json-db";
12+
import { join } from "node:path";
1213

1314
let instanceID = "unknown";
15+
let rDataPath, dataPath = new Promise(resolve => rDataPath = resolve);
1416

1517
/** @type {{[id: number]: JSONDatabase}} */
1618
let databaseList = {};
@@ -58,6 +60,14 @@ process.once("message", (data) => {
5860
module_namespace: "db_json"
5961
});
6062

63+
process.send({
64+
type: "api_send",
65+
call_cmd: "get_data_folder",
66+
call_to: "core",
67+
data: null,
68+
nonce: "DBJS0"
69+
});
70+
6171
process.on("message", portCallback);
6272
} else {
6373
process.exit(1);
@@ -97,11 +107,18 @@ async function portCallback(data) {
97107
nonce: data.nonce
98108
});
99109
}
110+
break;
100111
case "challenge":
101112
process.send({
102113
type: "challenge_response",
103114
challenge: data.challenge
104115
});
116+
break;
117+
case "api_response":
118+
if (data.nonce === "DBJS0") {
119+
rDataPath(data.data);
120+
}
121+
break;
105122
}
106123
}
107124

@@ -123,7 +140,7 @@ async function handleAPICall(cmd, data) {
123140
}
124141
case "connect_db":
125142
if (databaseList[data.databaseID]) throw "Database ID exists!";
126-
databaseList[data.databaseID] = new JSONDatabase(data.params.file, data.databaseName);
143+
databaseList[data.databaseID] = new JSONDatabase(join(await dataPath, data.params.file));
127144
return {
128145
exist: true,
129146
data: {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nocom_bot/mod_database_json",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "v1 Spec-compliant JSON database module for NOCOM_BOT",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)