pathchain 1.1.4 → 1.1.6
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/checker.js +47 -76
- package/getter.js +107 -240
- package/maker.js +1 -2
- package/package.json +1 -1
package/checker.js
CHANGED
|
@@ -1,101 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const emptyDir = require('empty-dir');
|
|
3
|
+
const pb = require('protocol-buffers');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* [Function that creates directory if it does not exist]
|
|
9
|
-
*
|
|
10
|
-
* @param {string} dir (required)
|
|
11
|
-
*
|
|
12
|
-
* @return void
|
|
5
|
+
/**
|
|
6
|
+
* Creates a directory if it does not exist.
|
|
7
|
+
* @param {string} dir - The directory path to check and create.
|
|
13
8
|
*/
|
|
14
|
-
function checkDir(dir){
|
|
15
|
-
if (!fs.existsSync(dir)){
|
|
9
|
+
function checkDir(dir) {
|
|
10
|
+
if (!fs.existsSync(dir)) {
|
|
16
11
|
fs.mkdirSync(dir, { recursive: true });
|
|
17
12
|
}
|
|
18
13
|
}
|
|
19
14
|
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* @
|
|
24
|
-
*
|
|
25
|
-
* @return void
|
|
15
|
+
/**
|
|
16
|
+
* Returns an array of files in the specified directory.
|
|
17
|
+
* @param {string} dir - The directory path to check.
|
|
18
|
+
* @returns {string[]} An array of file names in the directory.
|
|
26
19
|
*/
|
|
27
|
-
function checkFiles(dir){
|
|
28
|
-
|
|
29
|
-
return files;
|
|
20
|
+
function checkFiles(dir) {
|
|
21
|
+
return fs.readdirSync(dir);
|
|
30
22
|
}
|
|
31
23
|
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @
|
|
36
|
-
*
|
|
37
|
-
* @return {bool} empty_dir
|
|
24
|
+
/**
|
|
25
|
+
* Checks if the specified directory is empty.
|
|
26
|
+
* @param {string} dir - The directory path to check.
|
|
27
|
+
* @returns {boolean} True if the directory is empty, false otherwise.
|
|
38
28
|
*/
|
|
39
29
|
function checkEmptyDir(dir) {
|
|
40
|
-
|
|
41
|
-
return empty_dir
|
|
30
|
+
return emptyDir.sync(dir);
|
|
42
31
|
}
|
|
43
32
|
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
48
|
-
*
|
|
49
|
-
* @return {bool} empty_dir
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a file exists at the specified path.
|
|
35
|
+
* @param {string} dir - The file path to check.
|
|
36
|
+
* @returns {boolean} True if the file exists, false otherwise.
|
|
50
37
|
*/
|
|
51
|
-
function checkFile(dir){
|
|
38
|
+
function checkFile(dir) {
|
|
52
39
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
console.error(err)
|
|
40
|
+
return fs.existsSync(dir);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error(err);
|
|
43
|
+
return false;
|
|
58
44
|
}
|
|
59
|
-
return false;
|
|
60
45
|
}
|
|
61
46
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
68
|
-
* @return {bool} used_secret
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a secret has been used.
|
|
49
|
+
* @param {string} xsecret - The secret hash.
|
|
50
|
+
* @param {string} [xauthor=''] - The author of the secret (optional).
|
|
51
|
+
* @returns {boolean|string} True if the secret has been used, false if not, or an error message.
|
|
69
52
|
*/
|
|
70
|
-
function isSecretUsed(xsecret, xauthor =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
53
|
+
function isSecretUsed(xsecret, xauthor = '') {
|
|
54
|
+
const secretProto = pb(fs.readFileSync('node_modules/pathchain/proto/secret.proto'));
|
|
55
|
+
const filePath = `files/${xauthor ? xauthor + '/' : ''}secrets/${xsecret}`;
|
|
74
56
|
|
|
75
|
-
// LOADING PB
|
|
76
|
-
var secret_pb = pb(fs.readFileSync('node_modules/pathchain/proto/secret.proto'))
|
|
77
|
-
|
|
78
|
-
// NOT FOUND EXCEPTION
|
|
79
|
-
var fileContents;
|
|
80
57
|
try {
|
|
81
|
-
fileContents = fs.readFileSync(
|
|
58
|
+
const fileContents = fs.readFileSync(filePath);
|
|
59
|
+
const secretObj = secretProto.secret.decode(fileContents);
|
|
60
|
+
return secretObj.used;
|
|
82
61
|
} catch (err) {
|
|
83
|
-
|
|
84
|
-
return "Secret not found";
|
|
85
|
-
} else {
|
|
86
|
-
throw err;
|
|
87
|
-
}
|
|
62
|
+
return err.code === 'ENOENT' ? 'Secret not found' : err;
|
|
88
63
|
}
|
|
89
|
-
|
|
90
|
-
// DECODING SECRET
|
|
91
|
-
var secret_enc = fileContents
|
|
92
|
-
var secret_obj = secret_pb.secret.decode(secret_enc)
|
|
93
|
-
|
|
94
|
-
return secret_obj.used;
|
|
95
64
|
}
|
|
96
65
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
66
|
+
module.exports = {
|
|
67
|
+
checkDir,
|
|
68
|
+
checkFiles,
|
|
69
|
+
checkFile,
|
|
70
|
+
checkEmptyDir,
|
|
71
|
+
isSecretUsed
|
|
72
|
+
};
|
package/getter.js
CHANGED
|
@@ -1,301 +1,168 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @return {string} current_datetime
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const pb = require('protocol-buffers');
|
|
3
|
+
const dt = require('date-and-time');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the current datetime string in the specified format.
|
|
7
|
+
* @param {string} [format='MM DD YYYY HH:mm:SSS [GMT]Z'] - The desired date format.
|
|
8
|
+
* @returns {string} The formatted current datetime.
|
|
10
9
|
*/
|
|
11
|
-
function getCurrentDate(format = 'MM DD YYYY HH:mm:SSS [GMT]Z'){
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return current_datetime;
|
|
10
|
+
function getCurrentDate(format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
11
|
+
const currentDatetime = new Date();
|
|
12
|
+
return dt.format(currentDatetime, dt.compile(format, true));
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
*
|
|
23
|
-
* @return void
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves and decodes a moment object from a file.
|
|
17
|
+
* @param {string} xmoment - The moment hash or path.
|
|
18
|
+
* @returns {Object|string} The decoded moment object or an error message.
|
|
24
19
|
*/
|
|
25
20
|
function getMomentObj(xmoment) {
|
|
26
|
-
// "moments/hash"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// LOADING PB
|
|
32
|
-
var moment_pb = pb(fs.readFileSync('node_modules/pathchain/proto/moment.proto'))
|
|
21
|
+
// Handle "moments/hash" format
|
|
22
|
+
const momentHash = xmoment.includes('/') ? xmoment.split('/')[1] : xmoment;
|
|
23
|
+
|
|
24
|
+
const momentProto = pb(fs.readFileSync('node_modules/pathchain/proto/moment.proto'));
|
|
33
25
|
|
|
34
|
-
// NOT FOUND EXCEPTION
|
|
35
|
-
var fileContents;
|
|
36
26
|
try {
|
|
37
|
-
fileContents = fs.readFileSync(
|
|
27
|
+
const fileContents = fs.readFileSync(`files/moments/${momentHash}`);
|
|
28
|
+
return momentProto.moment.decode(fileContents);
|
|
38
29
|
} catch (err) {
|
|
39
|
-
|
|
40
|
-
return "Moment buffer not found";
|
|
41
|
-
} else {
|
|
42
|
-
throw err;
|
|
43
|
-
}
|
|
30
|
+
return err.code === 'ENOENT' ? "Moment buffer not found" : err;
|
|
44
31
|
}
|
|
45
|
-
|
|
46
|
-
// DECODING MOMENT
|
|
47
|
-
var moment_enc = fileContents
|
|
48
|
-
var moment_obj = moment_pb.moment.decode(moment_enc)
|
|
49
|
-
|
|
50
|
-
return moment_obj;
|
|
51
32
|
}
|
|
52
33
|
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
57
|
-
*
|
|
58
|
-
* @return void
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves and decodes a pioneer object from a file.
|
|
36
|
+
* @param {string} xpioneer - The pioneer hash.
|
|
37
|
+
* @returns {Object|string} The decoded pioneer object or an error message.
|
|
59
38
|
*/
|
|
60
39
|
function getPioneerObj(xpioneer) {
|
|
61
|
-
|
|
62
|
-
// LOADING PB
|
|
63
|
-
var pioneer_pb = pb(fs.readFileSync('node_modules/pathchain/proto/entity.proto'))
|
|
40
|
+
const pioneerProto = pb(fs.readFileSync('node_modules/pathchain/proto/entity.proto'));
|
|
64
41
|
|
|
65
|
-
// NOT FOUND EXCEPTION
|
|
66
|
-
var fileContents;
|
|
67
42
|
try {
|
|
68
|
-
fileContents = fs.readFileSync(
|
|
43
|
+
const fileContents = fs.readFileSync(`files/pioneer/${xpioneer}`);
|
|
44
|
+
return pioneerProto.entity.decode(fileContents);
|
|
69
45
|
} catch (err) {
|
|
70
|
-
|
|
71
|
-
return "Pioneer not found";
|
|
72
|
-
} else {
|
|
73
|
-
throw err;
|
|
74
|
-
}
|
|
46
|
+
return err.code === 'ENOENT' ? "Pioneer not found" : err;
|
|
75
47
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// DECODING PIONEER
|
|
79
|
-
var pioneer_enc = fileContents
|
|
80
|
-
var pioneer_obj = pioneer_pb.entity.decode(pioneer_enc)
|
|
81
|
-
|
|
82
|
-
return pioneer_obj;
|
|
83
48
|
}
|
|
84
49
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @
|
|
90
|
-
*
|
|
91
|
-
* @return void
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves and decodes a secret object from a file.
|
|
52
|
+
* @param {string} xsecret - The secret hash.
|
|
53
|
+
* @param {string} xauthor - The author of the secret (optional).
|
|
54
|
+
* @returns {Object|string} The decoded secret object or an error message.
|
|
92
55
|
*/
|
|
93
|
-
function getSecretObj(xsecret, xauthor) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
xauthor = xauthor + '/';
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// LOADING PB
|
|
100
|
-
var secret_pb = pb(fs.readFileSync('node_modules/pathchain/proto/secret.proto'))
|
|
56
|
+
function getSecretObj(xsecret, xauthor = '') {
|
|
57
|
+
const secretProto = pb(fs.readFileSync('node_modules/pathchain/proto/secret.proto'));
|
|
58
|
+
const filePath = `files/${xauthor ? xauthor + '/' : ''}secrets/${xsecret}`;
|
|
101
59
|
|
|
102
|
-
// NOT FOUND EXCEPTION
|
|
103
|
-
var fileContents;
|
|
104
60
|
try {
|
|
105
|
-
fileContents = fs.readFileSync(
|
|
61
|
+
const fileContents = fs.readFileSync(filePath);
|
|
62
|
+
return secretProto.secret.decode(fileContents);
|
|
106
63
|
} catch (err) {
|
|
107
|
-
|
|
108
|
-
return "Secret not found";
|
|
109
|
-
} else {
|
|
110
|
-
throw err;
|
|
111
|
-
}
|
|
64
|
+
return err.code === 'ENOENT' ? "Secret not found" : err;
|
|
112
65
|
}
|
|
113
|
-
|
|
114
|
-
// DECODING SECRET
|
|
115
|
-
var secret_enc = fileContents
|
|
116
|
-
var secret_obj = secret_pb.secret.decode(secret_enc)
|
|
117
|
-
|
|
118
|
-
return secret_obj;
|
|
119
66
|
}
|
|
120
67
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* @
|
|
126
|
-
*
|
|
127
|
-
* @return void
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves and decodes an entity object from a file.
|
|
70
|
+
* @param {string} xentity - The entity hash.
|
|
71
|
+
* @param {string} xauthor - The author of the entity (optional).
|
|
72
|
+
* @returns {Object|string} The decoded entity object or an error message.
|
|
128
73
|
*/
|
|
129
|
-
function getEntityObj(xentity, xauthor) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// LOADING PB
|
|
135
|
-
var entity_pb = pb(fs.readFileSync('node_modules/pathchain/proto/entity.proto'))
|
|
74
|
+
function getEntityObj(xentity, xauthor = '') {
|
|
75
|
+
const entityProto = pb(fs.readFileSync('node_modules/pathchain/proto/entity.proto'));
|
|
76
|
+
const filePath = `files/${xauthor ? xauthor + '/' : ''}entities/${xentity}`;
|
|
136
77
|
|
|
137
|
-
// NOT FOUND EXCEPTION
|
|
138
|
-
var fileContents;
|
|
139
78
|
try {
|
|
140
|
-
fileContents = fs.readFileSync(
|
|
79
|
+
const fileContents = fs.readFileSync(filePath);
|
|
80
|
+
return entityProto.entity.decode(fileContents);
|
|
141
81
|
} catch (err) {
|
|
142
|
-
|
|
143
|
-
return "Entity not found";
|
|
144
|
-
} else {
|
|
145
|
-
throw err;
|
|
146
|
-
}
|
|
82
|
+
return err.code === 'ENOENT' ? "Entity not found" : err;
|
|
147
83
|
}
|
|
148
|
-
|
|
149
|
-
// DECODING ENTITY
|
|
150
|
-
var entity_enc = fileContents
|
|
151
|
-
var entity_obj = entity_pb.entity.decode(entity_enc)
|
|
152
|
-
|
|
153
|
-
return entity_obj;
|
|
154
84
|
}
|
|
155
85
|
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* @param {string}
|
|
160
|
-
*
|
|
161
|
-
* @return void
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves and decodes a node object from a file.
|
|
88
|
+
* @param {string} xnode - The node hash.
|
|
89
|
+
* @param {string} xauthor - The author of the node (optional).
|
|
90
|
+
* @returns {Object|string} The decoded node object or an error message.
|
|
162
91
|
*/
|
|
163
|
-
function getNodeObj(xnode, xauthor) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
xauthor = xauthor + '/';
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// LOADING PB
|
|
170
|
-
var node_pb = pb(fs.readFileSync('node_modules/pathchain/proto/node.proto'))
|
|
92
|
+
function getNodeObj(xnode, xauthor = '') {
|
|
93
|
+
const nodeProto = pb(fs.readFileSync('node_modules/pathchain/proto/node.proto'));
|
|
94
|
+
const filePath = `files/${xauthor ? xauthor + '/' : ''}nodes/${xnode}`;
|
|
171
95
|
|
|
172
|
-
// NOT FOUND EXCEPTION
|
|
173
|
-
var fileContents;
|
|
174
96
|
try {
|
|
175
|
-
fileContents = fs.readFileSync(
|
|
97
|
+
const fileContents = fs.readFileSync(filePath);
|
|
98
|
+
return nodeProto.node.decode(fileContents);
|
|
176
99
|
} catch (err) {
|
|
177
|
-
|
|
178
|
-
return "Node not found";
|
|
179
|
-
} else {
|
|
180
|
-
throw err;
|
|
181
|
-
}
|
|
100
|
+
return err.code === 'ENOENT' ? "Node not found" : err;
|
|
182
101
|
}
|
|
183
|
-
|
|
184
|
-
// DECODING NODE
|
|
185
|
-
var node_enc = fileContents
|
|
186
|
-
var node_obj = node_pb.node.decode(node_enc)
|
|
187
|
-
|
|
188
|
-
return node_obj;
|
|
189
102
|
}
|
|
190
103
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* @
|
|
196
|
-
*
|
|
197
|
-
* @return void
|
|
104
|
+
/**
|
|
105
|
+
* Retrieves and decodes a link object from a file.
|
|
106
|
+
* @param {string} xlink - The link hash.
|
|
107
|
+
* @param {string} xauthor - The author of the link (optional).
|
|
108
|
+
* @returns {Object|string} The decoded link object or an error message.
|
|
198
109
|
*/
|
|
199
|
-
function getLinkObj(xlink, xauthor) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
xauthor = xauthor + '/';
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// LOADING PB
|
|
206
|
-
var link_pb = pb(fs.readFileSync('node_modules/pathchain/proto/link.proto'))
|
|
110
|
+
function getLinkObj(xlink, xauthor = '') {
|
|
111
|
+
const linkProto = pb(fs.readFileSync('node_modules/pathchain/proto/link.proto'));
|
|
112
|
+
const filePath = `files/${xauthor ? xauthor + '/' : ''}links/${xlink}`;
|
|
207
113
|
|
|
208
|
-
// NOT FOUND EXCEPTION
|
|
209
|
-
var fileContents;
|
|
210
114
|
try {
|
|
211
|
-
fileContents = fs.readFileSync(
|
|
115
|
+
const fileContents = fs.readFileSync(filePath);
|
|
116
|
+
return linkProto.link.decode(fileContents);
|
|
212
117
|
} catch (err) {
|
|
213
|
-
|
|
214
|
-
return "Link not found";
|
|
215
|
-
} else {
|
|
216
|
-
throw err;
|
|
217
|
-
}
|
|
118
|
+
return err.code === 'ENOENT' ? "Link not found" : err;
|
|
218
119
|
}
|
|
219
|
-
|
|
220
|
-
// DECODING NODE
|
|
221
|
-
var link_enc = fileContents
|
|
222
|
-
var link_obj = link_pb.link.decode(link_enc)
|
|
223
|
-
|
|
224
|
-
return link_obj;
|
|
225
120
|
}
|
|
226
121
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* @
|
|
232
|
-
*
|
|
233
|
-
* @return void
|
|
122
|
+
/**
|
|
123
|
+
* Retrieves and decodes a path object from a file.
|
|
124
|
+
* @param {string} xpath - The path hash.
|
|
125
|
+
* @param {string} xauthor - The author of the path (optional).
|
|
126
|
+
* @returns {Object|string} The decoded path object or an error message.
|
|
234
127
|
*/
|
|
235
|
-
function getPathObj(xpath, xauthor) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
xauthor = xauthor + '/';
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// LOADING PB
|
|
242
|
-
var path_pb = pb(fs.readFileSync('node_modules/pathchain/proto/path.proto'))
|
|
128
|
+
function getPathObj(xpath, xauthor = '') {
|
|
129
|
+
const pathProto = pb(fs.readFileSync('node_modules/pathchain/proto/path.proto'));
|
|
130
|
+
const filePath = `files/${xauthor ? xauthor + '/' : ''}paths/${xpath}`;
|
|
243
131
|
|
|
244
|
-
// NOT FOUND EXCEPTION
|
|
245
|
-
var fileContents;
|
|
246
132
|
try {
|
|
247
|
-
fileContents = fs.readFileSync(
|
|
133
|
+
const fileContents = fs.readFileSync(filePath);
|
|
134
|
+
return pathProto.path.decode(fileContents);
|
|
248
135
|
} catch (err) {
|
|
249
|
-
|
|
250
|
-
return "Path not found";
|
|
251
|
-
} else {
|
|
252
|
-
throw err;
|
|
253
|
-
}
|
|
136
|
+
return err.code === 'ENOENT' ? "Path not found" : err;
|
|
254
137
|
}
|
|
255
|
-
|
|
256
|
-
// DECODING PATH
|
|
257
|
-
var path_enc = fileContents
|
|
258
|
-
var path_obj = path_pb.path.decode(path_enc)
|
|
259
|
-
|
|
260
|
-
return path_obj;
|
|
261
138
|
}
|
|
262
139
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* @param {string} xlabel (required)
|
|
269
|
-
*
|
|
270
|
-
* @return void
|
|
140
|
+
/**
|
|
141
|
+
* Retrieves and decodes a label object from a file.
|
|
142
|
+
* @param {string} xlabel - The label hash.
|
|
143
|
+
* @param {string} xauthor - The author of the label (optional).
|
|
144
|
+
* @returns {Object|string} The decoded label object or an error message.
|
|
271
145
|
*/
|
|
272
|
-
function getLabelObj(xlabel, xauthor) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
xauthor = xauthor + '/';
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// LOADING PB
|
|
279
|
-
var label_pb = pb(fs.readFileSync('node_modules/pathchain/proto/label.proto'))
|
|
146
|
+
function getLabelObj(xlabel, xauthor = '') {
|
|
147
|
+
const labelProto = pb(fs.readFileSync('node_modules/pathchain/proto/label.proto'));
|
|
148
|
+
const filePath = `files/${xauthor ? xauthor + '/' : ''}labels/${xlabel}`;
|
|
280
149
|
|
|
281
|
-
// NOT FOUND EXCEPTION
|
|
282
|
-
var fileContents;
|
|
283
150
|
try {
|
|
284
|
-
fileContents = fs.readFileSync(
|
|
151
|
+
const fileContents = fs.readFileSync(filePath);
|
|
152
|
+
return labelProto.label.decode(fileContents);
|
|
285
153
|
} catch (err) {
|
|
286
|
-
|
|
287
|
-
return "Label not found";
|
|
288
|
-
} else {
|
|
289
|
-
throw err;
|
|
290
|
-
}
|
|
154
|
+
return err.code === 'ENOENT' ? "Label not found" : err;
|
|
291
155
|
}
|
|
292
|
-
|
|
293
|
-
// DECODING LABEL
|
|
294
|
-
var label_enc = fileContents
|
|
295
|
-
var label_obj = label_pb.label.decode(label_enc)
|
|
296
|
-
|
|
297
|
-
return label_obj;
|
|
298
156
|
}
|
|
299
157
|
|
|
300
|
-
|
|
301
|
-
|
|
158
|
+
module.exports = {
|
|
159
|
+
getCurrentDate,
|
|
160
|
+
getMomentObj,
|
|
161
|
+
getPioneerObj,
|
|
162
|
+
getSecretObj,
|
|
163
|
+
getEntityObj,
|
|
164
|
+
getNodeObj,
|
|
165
|
+
getLinkObj,
|
|
166
|
+
getPathObj,
|
|
167
|
+
getLabelObj
|
|
168
|
+
};
|
package/maker.js
CHANGED
|
@@ -143,13 +143,12 @@ function entity(xsecret, format) {
|
|
|
143
143
|
const register = dt.format(new Date(), dt.compile(format, true));
|
|
144
144
|
const register_moment_hash = moment(register, 0, 0, 0, 0, 0, format);
|
|
145
145
|
const ancestor_entity_hash = getter.getSecretObj(xsecret, "").author;
|
|
146
|
-
console.log("MAKER :: ENTITY :: xsecret obj : ", getter.getSecretObj(xsecret));
|
|
147
146
|
|
|
148
147
|
const entity_hash = sha256(`${register_moment_hash}_${ancestor_entity_hash}`);
|
|
149
148
|
|
|
150
149
|
const buffer = entity.entity.encode({
|
|
151
150
|
register: `moments/${register_moment_hash}`,
|
|
152
|
-
ancestor:
|
|
151
|
+
ancestor: `${ancestor_entity_hash}`,
|
|
153
152
|
tag: `entities/${entity_hash}`,
|
|
154
153
|
});
|
|
155
154
|
|
package/package.json
CHANGED