godprotocol 1.2.12 → 1.2.14

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.
@@ -339,6 +339,11 @@ class Manager {
339
339
  this.served = true
340
340
  this.oracle = this.options.oracle;
341
341
  this.oracle.set_manager(this)
342
+ .then(async()=>{
343
+ if (this.options.init_account){
344
+ await this.add_account(this.options.init_account.name, {password: this.options.init_account.password, init: true})
345
+ }
346
+ })
342
347
  }
343
348
  }
344
349
  }
package/Objects/Oracle.js CHANGED
@@ -147,25 +147,36 @@ class Oracle extends Handlers{
147
147
  return res;
148
148
  }
149
149
 
150
- set_to_repos = async(address, content)=>{
150
+ set_to_repos = async(address, content, options)=>{
151
+ let {count, args} = options, counted = count != null, res;
151
152
  for (let r=0; r< this.repos.length; r++){
152
153
  let repo = this.repos[r]
153
154
 
154
155
  if (!repo.filter || address.match(repo.filter)){
155
- await repo.repo.write_file(address, content)
156
+ await repo.repo.write_file(address, content, args)
157
+ res = await repo.repo.objectify()
158
+ if (counted && !count) break;
159
+ count --
156
160
  }
157
161
  }
162
+
163
+ return res;
158
164
  }
159
165
 
160
- get_from_repos = async(address)=>{
166
+ get_from_repos = async(address, repo_)=>{
167
+ let content
161
168
  for (let r=0; r< this.repos.length; r++){
162
169
  let repo = this.repos[r]
163
170
 
164
- if (!repo.filter || address.match(repo.filter)){
165
- let content = await repo.repo.read_file(address)
166
- if (content) return content;
171
+ if(repo_ && repo.repo.match(repo_)){
172
+ content = await repo.repo.read_file(address)
173
+ break
174
+ } else if (!repo.filter || address.match(repo.filter)){
175
+ content = await repo.repo.read_file(address)
176
+ if (content) break
167
177
  }
168
178
  }
179
+ return content
169
180
  }
170
181
 
171
182
  read = async(path, options={})=>{
@@ -8,6 +8,10 @@ class Repository{
8
8
  obj.name = this.name;
9
9
  obj.remote = this.remote
10
10
  obj.__dirname = this.__dirname
11
+ }else if (this.type === 'github'){
12
+ obj.key = this.auth_token
13
+ obj.username = this.owner
14
+ obj.repo = this.repo;
11
15
  }
12
16
 
13
17
  return obj
package/Objects/Utils.js CHANGED
@@ -10,6 +10,27 @@ class Utils{
10
10
 
11
11
  await this.load({address: address.slice(this.physical_address.length+1), sequence: res, compiler: true, from_reload: true})
12
12
  }
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})
17
+
18
+ return content && JSON.parse(content)
19
+ }
20
+
21
+ read_file = async(address) =>{
22
+ let content = await this.manager.oracle.read(address, {account: this.physical_address})
23
+
24
+ return content;
25
+ }
26
+
27
+ write_file = async(address, content)=>{
28
+ let res = await this.manager.oracle.write(address, JSON.stringify(content), {account: this.physical_address})
29
+ }
30
+
31
+ read = async(address, query)=>{
32
+
33
+ }
13
34
  }
14
35
 
15
36
 
package/html/index.js CHANGED
@@ -22,18 +22,23 @@ const header_script = (manager)=>{
22
22
  let domain = manager.options.server_domain
23
23
  if (domain.startsWith('127')) domain = `http://${domain}`
24
24
  else domain = `https://${domain}`
25
-
25
+
26
26
  return ` let ftch = async(path, body)=>{
27
- let fch = await fetch("${domain}".concat(path), {
28
- method: 'POST',
29
- header: {
30
- 'Content-Type': 'application/json',
31
- Accept: 'application/json'
32
- },
33
- body: JSON.stringify(body)
34
- })
35
- let response = await fch.json()
36
- return response;
27
+ try{
28
+ let fch = await fetch("${domain}".concat(path), {
29
+ method: 'POST',
30
+ header: {
31
+ 'Content-Type': 'application/json',
32
+ Accept: 'application/json'
33
+ },
34
+ body: JSON.stringify(body)
35
+ })
36
+ let response = await fch.json()
37
+ return response;
38
+ }catch(e){
39
+ console.log(e)
40
+ return {message: e.message}
41
+ }
37
42
  }`
38
43
  }
39
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
4
4
  "description": "A distributed computing environment",
5
5
  "main": "Index.js",
6
6
  "scripts": {
package/repos/github.js CHANGED
@@ -22,14 +22,20 @@ class Github extends Repository{
22
22
  let sha = null;
23
23
 
24
24
  // Check if file exists, get its SHA
25
- const exists = await this.file_exists(file_path);
26
- if (exists) {
27
- const res = await fetch(url, { headers: this.get_headers() });
28
- if (res.ok) {
29
- const data = await res.json();
30
- sha = data.sha;
25
+ try{
26
+ const exists = await this.file_exists(file_path);
27
+ if (exists) {
28
+ const res = await fetch(url, { headers: this.get_headers() });
29
+ if (res.ok) {
30
+ const data = await res.json();
31
+ sha = data.sha;
32
+ }
31
33
  }
34
+ }catch(e){
35
+ console.log(e.message)
36
+ return
32
37
  }
38
+
33
39
 
34
40
  // Build payload
35
41
  const body = {
@@ -51,7 +57,14 @@ class Github extends Repository{
51
57
  read_file = async (file_path) => {
52
58
  const url = `${this.base_url}/repos/${this.owner}/${this.repo}/contents/${file_path}`;
53
59
 
54
- const response = await fetch(url, { headers: this.get_headers() });
60
+ let response;
61
+ try{
62
+ response = await fetch(url, { headers: this.get_headers() })
63
+ }catch(e){
64
+ console.log(e)
65
+ return;
66
+ }
67
+ ;
55
68
  if (!response.ok) return null;
56
69
 
57
70
  const fileData = await response.json();
@@ -72,17 +72,19 @@ export const handle_routes = async (req, res, manager, app) => {
72
72
  result = await manager.oracle.call(data);
73
73
  break;
74
74
  default:
75
- let accountName = account_uids[data.account];
76
- if (!accountName) return res.end(JSON.stringify({ message: `Account ${data.account} not found` }));
77
-
78
- let accountObj = await manager.get_account(accountName);
75
+ let account_name = account_uids[data.account], account_obj;
76
+ if (!account_name){
77
+ if (['load', 'run', 'parse'].includes(req.url.slice(1))){
78
+ return res.end(JSON.stringify({ message: `Account ${data.account} not found` }));
79
+ }
80
+ }else account_obj = await manager.get_account(account_name);
79
81
 
80
82
  if (req.url === '/load'){
81
- result = await accountObj.load(data);
83
+ result = await account_obj.load(data);
82
84
  }else if (req.url === '/run'){
83
- result = await accountObj.run(data);
85
+ result = await account_obj.run(data);
84
86
  }else if (req.url === '/parse'){
85
- result = await accountObj.parse(data);
87
+ result = await account_obj.parse(data);
86
88
  }else {
87
89
  return app? app(req,res): res.writeHead(404).end('Not Found');
88
90
  }