-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.js
More file actions
50 lines (45 loc) · 1.4 KB
/
add.js
File metadata and controls
50 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { get } from 'https://kittenapps-films.github.io/edit/code.js'
import { Octokit } from "https://esm.sh/@octokit/core";
import { getContents } from "https://kittenapps-films.github.io/GeoFSUsers/getter.js"
export async function update(link,user, edit = false) {
var listOfUsers = await getContents()
console.log(listOfUsers)
const hasUser = user in listOfUsers;
console.log(hasUser)
if (hasUser) {edit = false};
if (!hasUser || edit) {
listOfUsers[user] = link
console.log(listOfUsers)
var content = `export var users = ${JSON.stringify(listOfUsers)}`
const octokit = new Octokit({
auth: get(),
})
var old = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: 'KittenApps-Films',
repo: 'GeoFS_Wiki',
path: 'GeoFSUsers.js',
branch: 'main',
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
var commiter = edit ? `Editing user ${user}` : `Adding user ${user} to users addon`;
var newFile = await octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
owner: 'KittenApps-Films',
repo: 'GeoFS_Wiki',
path: 'GeoFSUsers.js',
message: 'added to GeoFSUsers.js',
committer: {
name: commiter,
email: 'kittenappsandfilms@gmail.com'
},
content: btoa(content),
sha: old.data.sha,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
console.log(newFile)
}
}
update("brick.com","Go")