pathchain 1.1.8 → 1.1.10

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.
Files changed (3) hide show
  1. package/maker.js +33 -16
  2. package/package.json +1 -1
  3. package/updater.js +7 -2
package/maker.js CHANGED
@@ -313,6 +313,15 @@ function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:S
313
313
  const link_pb = pb(fs.readFileSync('node_modules/pathchain/proto/link.proto'));
314
314
  var target_type = "";
315
315
 
316
+ // Handle author and author folder
317
+ let author_folder = author;
318
+ if (author === "") {
319
+ author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
320
+ author_folder = "";
321
+ } else {
322
+ author_folder = `${author_folder}/`;
323
+ }
324
+
316
325
  // Validate target
317
326
  if (target === "") {
318
327
  return "The link must be linking something. The target cannot be null.";
@@ -320,8 +329,24 @@ function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:S
320
329
  else{
321
330
  var splitted_target = target.split("/");
322
331
  console.log("Splitted target: ", splitted_target);
323
- target_type = splitted_target[splitted_target.length - 2];
324
- console.log("Target type: ", target_type);
332
+ if(splitted_target.length>1){
333
+ target_type = splitted_target[splitted_target.length - 2];
334
+ console.log("Target type: ", target_type);
335
+ }
336
+ else{
337
+ // Determine the nature of the target (node, path, or label)
338
+ if (checker.checkFile(`files/${author_folder}nodes/${target}`)) {
339
+ target_type = "nodes";
340
+ target = `${author_folder}nodes/${target}`;
341
+ } else if (checker.checkFile(`files/${author_folder}paths/${target}`)) {
342
+ target_type = "paths";
343
+ target = `${author_folder}paths/${target}`;
344
+ } else if (checker.checkFile(`files/${author_folder}labels/${target}`)) {
345
+ target_type = "labels";
346
+ target = `${author_folder}labels/${target}`;
347
+ }
348
+ console.log("Target type determined for single buffer: ", target_type);
349
+ }
325
350
  }
326
351
 
327
352
  // Homogenize the author.
@@ -329,27 +354,19 @@ function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:S
329
354
  // Make a copy of it inside *author* address if it is not public or if the original author is different than *author*
330
355
  // What the fuck
331
356
 
332
- // Handle author and author folder
333
- let author_folder = author;
334
- if (author === "") {
335
- author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
336
- author_folder = "";
337
- } else {
338
- author_folder = `${author_folder}/`;
339
- }
340
-
341
357
  // Create a moment for this link
342
358
  const register = dt.format(new Date(), dt.compile(format, true));
343
359
  const register_moment_hash = moment(register, 0, 0, 0, 0, 0, format);
344
360
 
345
- // Generate a unique hash for this link
346
- const link_hash = sha256(`${register_moment_hash}_${author}_${prev}_${next}`);
347
361
 
348
362
  // Set default values if not provided
349
363
  if (ancestor === "") { ancestor = link_hash; }
350
364
  if (prev === "") { prev = link_hash; }
351
365
  if (next === "") { next = link_hash; }
352
366
 
367
+ // Generate a unique hash for this link
368
+ const link_hash = sha256(`${register_moment_hash}_${author}_${prev}_${next}`);
369
+
353
370
  if (!checker.checkFile(`files/${target}`)) {
354
371
  return "Target was not found!";
355
372
  }
@@ -358,8 +375,8 @@ function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:S
358
375
  const buffer = link_pb.link.encode({
359
376
  register: `moments/${register_moment_hash}`,
360
377
  author: `entities/${author}`,
361
- prev: `links/${prev}`,
362
- next: `links/${next}`,
378
+ prev: `${author_folder}links/${prev}`,
379
+ next: `${author_folder}links/${next}`,
363
380
  target: target,
364
381
  ancestor: `${author_folder}links/${ancestor}`,
365
382
  tag: `${author_folder}links/${link_hash}`
@@ -369,7 +386,7 @@ function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:S
369
386
  checker.checkDir(`files/${author_folder}links/`);
370
387
  fs.writeFileSync(`files/${author_folder}links/${link_hash}`, buffer);
371
388
 
372
- return link_hash;
389
+ return `${author_folder}links/${link_hash}`;
373
390
  }
374
391
 
375
392
  module.exports = { moment, pioneer, secret, entity, node, path, label, link };
package/package.json CHANGED
@@ -34,5 +34,5 @@
34
34
  "deprecated": false,
35
35
  "description": "![image](https://user-images.githubusercontent.com/104391124/282268780-cbbc1ee6-8d97-4d80-b896-66ae3eb723dd.png)",
36
36
  "name": "pathchain",
37
- "version": "1.1.8"
37
+ "version": "1.1.10"
38
38
  }
package/updater.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var fs = require("fs");
2
2
  var pb = require('protocol-buffers');
3
+ const getter = require("./getter");
3
4
 
4
5
  /** useSecret
5
6
  * [Function that changes a secret state to used]
@@ -9,8 +10,12 @@ var pb = require('protocol-buffers');
9
10
  * @return {string} xsecret
10
11
  */
11
12
  function useSecret(xsecret, xauthor = "") {
12
- if(xauthor == ""){
13
- xauthor = xauthor + '/';
13
+ let author_folder = xauthor;
14
+ if (xauthor == "") {
15
+ xauthor = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
16
+ author_folder = "";
17
+ } else {
18
+ author_folder = `${author_folder}/`;
14
19
  }
15
20
 
16
21
  // LOADING PB