pathchain 1.1.23 → 1.1.24

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/package.json +1 -1
  2. package/updater.js +38 -9
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.23"
37
+ "version": "1.1.24"
38
38
  }
package/updater.js CHANGED
@@ -42,7 +42,7 @@ function setLinkNext(xlink = '', xnextlink = '') {
42
42
  console.log('Setting link:', xnextlink);
43
43
  console.log('As NEXT link for:', xlink);
44
44
 
45
- const linkProto = pb(fs.readFileSync('node_modules/pathchain/proto/link.proto'));
45
+ const link_pb = pb(fs.readFileSync('node_modules/pathchain/proto/link.proto'));
46
46
 
47
47
  try {
48
48
  // Check if both links exist
@@ -50,10 +50,24 @@ function setLinkNext(xlink = '', xnextlink = '') {
50
50
  fs.readFileSync(`files/${xnextlink}`);
51
51
 
52
52
  const fileContents = fs.readFileSync(`files/${xlink}`);
53
- const linkObj = linkProto.link.decode(fileContents);
54
- linkObj.next = xnextlink;
55
-
56
- return linkObj;
53
+ const linkObj = link_pb.link.decode(fileContents);
54
+
55
+ // Encode the link data into a protocol buffer
56
+ const buffer = link_pb.link.encode({
57
+ register: linkObj.register,
58
+ author: linkObj.author,
59
+ prev: xnextlink,
60
+ next: linkObj.next,
61
+ target: linkObj.target,
62
+ ancestor: linkObj.ancestor,
63
+ tag: linkObj.tag
64
+ });
65
+
66
+ // Ensure the directory exists and overwrite the link buffer to a file
67
+ checker.checkDir(xlink);
68
+ fs.writeFileSync(xlink, buffer);
69
+
70
+ return xlink;
57
71
  } catch (err) {
58
72
  return err.code === 'ENOENT' ? `Link '${err.path.split('/').pop()}' not found` : err;
59
73
  }
@@ -69,7 +83,7 @@ function setLinkPrev(xlink = '', xprevlink = '') {
69
83
  console.log('Setting link:', xprevlink);
70
84
  console.log('As PREV link for:', xlink);
71
85
 
72
- const linkProto = pb(fs.readFileSync('node_modules/pathchain/proto/link.proto'));
86
+ const link_pb = pb(fs.readFileSync('node_modules/pathchain/proto/link.proto'));
73
87
 
74
88
  try {
75
89
  // Check if both links exist
@@ -77,10 +91,25 @@ function setLinkPrev(xlink = '', xprevlink = '') {
77
91
  fs.readFileSync(`files/${xprevlink}`);
78
92
 
79
93
  const fileContents = fs.readFileSync(`files/${xlink}`);
80
- const linkObj = linkProto.link.decode(fileContents);
81
- linkObj.prev = xprevlink;
94
+ const linkObj = link_pb.link.decode(fileContents);
95
+
96
+ // Encode the link data into a protocol buffer
97
+ const buffer = link_pb.link.encode({
98
+ register: linkObj.register,
99
+ author: linkObj.author,
100
+ prev: xprevlink,
101
+ next: linkObj.next,
102
+ target: linkObj.target,
103
+ ancestor: linkObj.ancestor,
104
+ tag: linkObj.tag
105
+ });
106
+
107
+ // Ensure the directory exists and overwrite the link buffer to a file
108
+ checker.checkDir(xlink);
109
+ fs.writeFileSync(xlink, buffer);
110
+
111
+ return xlink;
82
112
 
83
- return linkObj;
84
113
  } catch (err) {
85
114
  return err.code === 'ENOENT' ? `Link '${err.path.split('/').pop()}' not found` : err;
86
115
  }