godprotocol 1.2.14 → 1.2.15

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.
@@ -331,7 +331,7 @@ class Manager {
331
331
  else this.options.server_domain = this.options.server.hostname
332
332
  let handle = create_server({manager: this, ...this.options.server, app: this.options.app })
333
333
 
334
- this.handler = (req, res)=>{
334
+ this.handler = (req, res, cb)=>{
335
335
 
336
336
  handle(req,res)
337
337
 
@@ -342,6 +342,8 @@ class Manager {
342
342
  .then(async()=>{
343
343
  if (this.options.init_account){
344
344
  await this.add_account(this.options.init_account.name, {password: this.options.init_account.password, init: true})
345
+
346
+ cb && cb()
345
347
  }
346
348
  })
347
349
  }
package/Objects/Oracle.js CHANGED
@@ -153,8 +153,10 @@ class Oracle extends Handlers{
153
153
  let repo = this.repos[r]
154
154
 
155
155
  if (!repo.filter || address.match(repo.filter)){
156
- await repo.repo.write_file(address, content, args)
157
- res = await repo.repo.objectify()
156
+ res = await repo.repo.write_file(address, content, args)
157
+ if (!args.just_exists){
158
+ res = await repo.repo.objectify()
159
+ }
158
160
  if (counted && !count) break;
159
161
  count --
160
162
  }
@@ -1,5 +1,6 @@
1
1
  class Repository{
2
- constructor(){
2
+ constructor(type){
3
+ this.type = type;
3
4
  }
4
5
 
5
6
  objectify = ()=>{
@@ -16,6 +17,10 @@ class Repository{
16
17
 
17
18
  return obj
18
19
  }
20
+
21
+ match = async()=>{
22
+ return false
23
+ }
19
24
  }
20
25
 
21
26
  export default Repository;
package/Objects/Utils.js CHANGED
@@ -11,13 +11,20 @@ class Utils{
11
11
  await this.load({address: address.slice(this.physical_address.length+1), sequence: res, compiler: true, from_reload: true})
12
12
  }
13
13
 
14
- get_from_repo = async(address) =>{
15
- address = `${this.physical_address}/${address}/__literal__`
16
- let content = await this.manager.oracle.get_from_repo(address, {count: 1})
14
+ get_from_repo = async(address, options) =>{
15
+ address = `./storage/${this.physical_address}/${address}/__literal__`
16
+ let content = await this.manager.oracle.get_from_repos(address, {count: 1, args: options})
17
17
 
18
18
  return content && JSON.parse(content)
19
19
  }
20
20
 
21
+ set_to_repo = async(address, content, options) =>{
22
+ address = `./storage/${this.physical_address}/${address}/__literal__`
23
+ let response = await this.manager.oracle.set_to_repos(address, JSON.stringify(content), {count: 1, args: options})
24
+
25
+ return response
26
+ }
27
+
21
28
  read_file = async(address) =>{
22
29
  let content = await this.manager.oracle.read(address, {account: this.physical_address})
23
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "1.2.14",
3
+ "version": "1.2.15",
4
4
  "description": "A distributed computing environment",
5
5
  "main": "Index.js",
6
6
  "scripts": {
package/repos/github.js CHANGED
@@ -17,13 +17,14 @@ class Github extends Repository{
17
17
  });
18
18
 
19
19
  // Write (create or update) a file
20
- write_file = async (file_path, content) => {
20
+ write_file = async (file_path, content, options={}) => {
21
21
  const url = `${this.base_url}/repos/${this.owner}/${this.repo}/contents/${file_path}`;
22
- let sha = null;
22
+ let sha = null, exists;
23
23
 
24
24
  // Check if file exists, get its SHA
25
25
  try{
26
- const exists = await this.file_exists(file_path);
26
+ exists = await this.file_exists(file_path);
27
+
27
28
  if (exists) {
28
29
  const res = await fetch(url, { headers: this.get_headers() });
29
30
  if (res.ok) {
@@ -31,26 +32,36 @@ class Github extends Repository{
31
32
  sha = data.sha;
32
33
  }
33
34
  }
35
+ if (options.just_exists) return exists
34
36
  }catch(e){
35
37
  console.log(e.message)
36
38
  return
37
39
  }
38
-
39
40
 
40
41
  // Build payload
41
- const body = {
42
+ let body;
43
+ try{
44
+ body = {
42
45
  message: exists ? 'Update file' : 'Create file',
43
46
  content: Buffer.from(content).toString('base64'),
44
47
  ...(sha && { sha }),
45
48
  };
49
+ }catch(e){
46
50
 
47
- const response = await fetch(url, {
48
- method: 'PUT',
49
- headers: this.get_headers(),
50
- body: JSON.stringify(body),
51
- });
51
+ }
52
52
 
53
- return response.json();
53
+ try{
54
+ const response = await fetch(url, {
55
+ method: 'PUT',
56
+ headers: this.get_headers(),
57
+ body: JSON.stringify(body),
58
+ });
59
+
60
+ return response.json();
61
+ }catch(e){
62
+ console.log(e.message)
63
+ }
64
+
54
65
  };
55
66
 
56
67
  // Read a file
@@ -60,15 +71,15 @@ class Github extends Repository{
60
71
  let response;
61
72
  try{
62
73
  response = await fetch(url, { headers: this.get_headers() })
74
+
75
+ if (!response.ok) return null;
76
+
77
+ const fileData = await response.json();
78
+ return Buffer.from(fileData.content, 'base64').toString('utf-8');
63
79
  }catch(e){
64
- console.log(e)
80
+ console.log(e.message)
65
81
  return;
66
82
  }
67
- ;
68
- if (!response.ok) return null;
69
-
70
- const fileData = await response.json();
71
- return Buffer.from(fileData.content, 'base64').toString('utf-8');
72
83
  };
73
84
 
74
85
  // Check if file exists