Skip to content

Commit

Permalink
Update Github.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistium authored Aug 14, 2024
1 parent 97a8fc5 commit a0835dd
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions files/Github.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,16 @@
async getRepositoryInfo({ INFO, USER, REPO }) {
const url = `https://api.github.com/repos/${USER}/${REPO}`;
try {
const response = await fetch(url);
let response;
if (this.authToken) {
response = await fetch(url, {
headers: {
'Authorization': `token ${this.authToken}`
}
});
} else {
response = await fetch(url);
}
if (!response.ok) {
throw new Error('Failed to fetch repository info.');
}
Expand Down Expand Up @@ -194,7 +203,16 @@
async getFileData({ PATH, USER, REPO, BRANCH }) {
const url = `https://raw.githubusercontent.com/${USER}/${REPO}/${BRANCH}/${PATH}`;
try {
const response = await fetch(url);
let response;
if (this.authToken) {
response = await fetch(url, {
headers: {
'Authorization': `token ${this.authToken}`
}
});
} else {
response = await fetch(url);
}
if (!response.ok) {
throw new Error('Failed to fetch file data.');
}
Expand All @@ -209,7 +227,16 @@
async getFolderContents({ TYPE, FOLDER, USER, REPO }) {
const url = `https://api.github.com/repos/${USER}/${REPO}/contents/${FOLDER}`;
try {
const response = await fetch(url);
let response;
if (this.authToken) {
response = await fetch(url, {
headers: {
'Authorization': `token ${this.authToken}`
}
});
} else {
response = await fetch(url);
}
if (!response.ok) {
throw new Error('Failed to fetch folder contents.');
}
Expand Down

0 comments on commit a0835dd

Please sign in to comment.