godprotocol 1.2.25 → 1.2.26

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/repos/github.js DELETED
@@ -1,185 +0,0 @@
1
- import Repository from "../Objects/Repository.js";
2
-
3
- class Github extends Repository {
4
- constructor({ key, username, repo, branch }) {
5
- super("github");
6
-
7
- this.base_url = "https://api.github.com";
8
- this.auth_token = key;
9
- this.owner = username;
10
- this.repo = repo;
11
- this.branch = branch || "master";
12
- }
13
-
14
- // Headers for API calls
15
- get_headers = () => ({
16
- Authorization: `Bearer ${this.auth_token}`,
17
- Accept: "application/vnd.github.v3+json",
18
- });
19
-
20
- // Write (create or update) a file
21
- write_file = async (file_path, content, options = {}) => {
22
- let url = `${this.base_url}/repos/${this.owner}/${this.repo}/contents/${file_path}`;
23
- let sha = null,
24
- exists;
25
-
26
- // Check if file exists, get its SHA
27
- try {
28
- exists = await this.file_exists(file_path);
29
-
30
- if (exists) {
31
- let res = await fetch(url, { headers: this.get_headers() });
32
- if (res.ok) {
33
- let data = await res.json();
34
- sha = data.sha;
35
- }
36
- }
37
- if (options.just_exists) return exists;
38
- } catch (e) {
39
- console.log(e.message);
40
- return;
41
- }
42
-
43
- // Build payload
44
- let body;
45
- try {
46
- body = {
47
- message: exists ? "Update file" : "Create file",
48
- content: Buffer.from(content).toString("base64"),
49
- ...(sha && { sha }),
50
- };
51
- } catch (e) {}
52
-
53
- try {
54
- let 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
- };
65
-
66
- // Read a file
67
- read_file = async (file_path) => {
68
- let url = `${this.base_url}/repos/${this.owner}/${this.repo}/contents/${file_path}`;
69
-
70
- let response;
71
- try {
72
- response = await fetch(url, { headers: this.get_headers() });
73
-
74
- if (!response.ok) return null;
75
-
76
- let fileData = await response.json();
77
- return Buffer.from(fileData.content, "base64").toString("utf-8");
78
- } catch (e) {
79
- console.log(e.message);
80
- return;
81
- }
82
- };
83
-
84
- // Check if file exists
85
- file_exists = async (file_path) => {
86
- let url = `${this.base_url}/repos/${this.owner}/${this.repo}/contents/${file_path}`;
87
- try {
88
- let response = await fetch(url, { headers: this.get_headers() });
89
- return response.ok;
90
- } catch {
91
- return false;
92
- }
93
- };
94
-
95
- // --- Delete File ---
96
- delete_file = async (file_path, message = "Delete file") => {
97
- let url = `${this.base_url}/repos/${this.owner}/${this.repo}/contents/${file_path}`;
98
-
99
- try {
100
- let res = await fetch(url, { headers: this.get_headers() });
101
- if (!res.ok) throw new Error("File not found");
102
- let data = await res.json();
103
- let sha = data.sha;
104
-
105
- let body = { message, sha };
106
-
107
- let del = await fetch(url, {
108
- method: "DELETE",
109
- headers: this.get_headers(),
110
- body: JSON.stringify(body),
111
- });
112
-
113
- if (!del.ok) {
114
- let err = await del.text();
115
- throw new Error(`Failed to delete file: ${err}`);
116
- }
117
-
118
- return await del.json();
119
- } catch (e) {
120
- console.log(e.message);
121
- return null;
122
- }
123
- };
124
-
125
- delete_folder = async (folder_path, message = "Delete folder") => {
126
- let headers = this.get_headers();
127
-
128
- // 1️⃣ Get the latest commit SHA
129
- let refUrl = `${this.base_url}/repos/${this.owner}/${this.repo}/git/ref/heads/${this.branch}`;
130
- let refRes = await fetch(refUrl, { headers });
131
- let refData = await refRes.json();
132
- let commitSha = refData.object.sha;
133
-
134
- // 2️⃣ Get the tree of that commit
135
- let commitUrl = `${this.base_url}/repos/${this.owner}/${this.repo}/git/commits/${commitSha}`;
136
- let commitRes = await fetch(commitUrl, { headers });
137
- let commitData = await commitRes.json();
138
- let treeSha = commitData.tree.sha;
139
-
140
- // 3️⃣ Get the full tree (recursive)
141
- let treeUrl = `${this.base_url}/repos/${this.owner}/${this.repo}/git/trees/${treeSha}?recursive=1`;
142
- let treeRes = await fetch(treeUrl, { headers });
143
- let treeData = await treeRes.json();
144
-
145
- // 4️⃣ Filter out the folder you want to delete
146
- let filtered = treeData.tree.filter((t) => !t.path.startsWith(folder_path));
147
-
148
- // 5️⃣ Create a new tree without that folder
149
- let newTreeRes = await fetch(
150
- `${this.base_url}/repos/${this.owner}/${this.repo}/git/trees`,
151
- {
152
- method: "POST",
153
- headers,
154
- body: JSON.stringify({ tree: filtered }),
155
- }
156
- );
157
- let newTreeData = await newTreeRes.json();
158
-
159
- // 6️⃣ Create a new commit pointing to the new tree
160
- let newCommitRes = await fetch(
161
- `${this.base_url}/repos/${this.owner}/${this.repo}/git/commits`,
162
- {
163
- method: "POST",
164
- headers,
165
- body: JSON.stringify({
166
- message,
167
- tree: newTreeData.sha,
168
- parents: [commitSha],
169
- }),
170
- }
171
- );
172
- let newCommitData = await newCommitRes.json();
173
-
174
- // 7️⃣ Update the branch ref
175
- await fetch(refUrl, {
176
- method: "PATCH",
177
- headers,
178
- body: JSON.stringify({ sha: newCommitData.sha }),
179
- });
180
-
181
- return { success: true, message: "Folder deleted via new commit" };
182
- };
183
- }
184
-
185
- export default Github;
package/repos/ram.js DELETED
@@ -1,47 +0,0 @@
1
- class Ram {
2
- constructor(account){
3
- this.account = account;
4
- this.oracle = account.manager.oracle;
5
- this.blocks = new Object();
6
- this.mbr = new Object()
7
- }
8
-
9
- write = async(path, content, repo)=>{
10
- let contents = this.blocks[repo]
11
- if (!contents){
12
- contents = new Object()
13
- this.blocks[repo] = contents
14
- }
15
- contents[path] = content;
16
- this.mbr[path] = content;
17
- }
18
-
19
- mkdir = async(path, repo)=>{
20
- await this.oracle.mkdir(path, repo)
21
- }
22
-
23
- exists = async(path, repo)=>{
24
- return await this.oracle.exists(path, repo)
25
- }
26
-
27
- read = async(path, repo)=>{
28
- // console.log(path, repo, 'uhh')
29
- if (!repo) return this.mbr[path]
30
-
31
- let contents = this.blocks[repo]
32
-
33
- if(!contents){
34
- contents = {}
35
- this.blocks[repo] = contents
36
- }
37
- if (!contents[path]){
38
- let cont = await this.oracle.read(path, repo)
39
-
40
- if (cont) contents[path] = cont
41
- }
42
-
43
- return contents[path]
44
- }
45
- }
46
-
47
- export default Ram