godprotocol 1.2.13 → 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.
- package/Objects/Manager.js +5 -0
- package/Objects/Oracle.js +17 -6
- package/Objects/Repository.js +4 -0
- package/Objects/Utils.js +21 -0
- package/package.json +1 -1
- package/repos/github.js +20 -7
- package/utils/create_server.js +9 -7
package/Objects/Manager.js
CHANGED
|
@@ -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
|
|
165
|
-
|
|
166
|
-
|
|
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={})=>{
|
package/Objects/Repository.js
CHANGED
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/package.json
CHANGED
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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();
|
package/utils/create_server.js
CHANGED
|
@@ -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
|
|
76
|
-
if (!
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
83
|
+
result = await account_obj.load(data);
|
|
82
84
|
}else if (req.url === '/run'){
|
|
83
|
-
result = await
|
|
85
|
+
result = await account_obj.run(data);
|
|
84
86
|
}else if (req.url === '/parse'){
|
|
85
|
-
result = await
|
|
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
|
}
|