pathchain 1.1.9 → 1.1.11

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 (2) hide show
  1. package/maker.js +33 -16
  2. package/package.json +1 -1
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,29 @@ 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
+ }
350
+ }
351
+
352
+ // Checking target existance
353
+ if (!checker.checkFile(`files/${target}`)) {
354
+ return "Target was not found!";
325
355
  }
326
356
 
327
357
  // Homogenize the author.
@@ -329,30 +359,17 @@ function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:S
329
359
  // Make a copy of it inside *author* address if it is not public or if the original author is different than *author*
330
360
  // What the fuck
331
361
 
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
362
  // Create a moment for this link
342
363
  const register = dt.format(new Date(), dt.compile(format, true));
343
364
  const register_moment_hash = moment(register, 0, 0, 0, 0, 0, format);
344
365
 
345
366
  // Generate a unique hash for this link
346
367
  const link_hash = sha256(`${register_moment_hash}_${author}_${prev}_${next}`);
347
-
368
+
348
369
  // Set default values if not provided
349
370
  if (ancestor === "") { ancestor = link_hash; }
350
371
  if (prev === "") { prev = link_hash; }
351
372
  if (next === "") { next = link_hash; }
352
-
353
- if (!checker.checkFile(`files/${target}`)) {
354
- return "Target was not found!";
355
- }
356
373
 
357
374
  // Encode the link data into a protocol buffer
358
375
  const buffer = link_pb.link.encode({
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.9"
37
+ "version": "1.1.11"
38
38
  }