hotfix: hardcode stuff to work w bassetts/warp-cors
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
d43f1d29ca
commit
d76b64a70f
2 changed files with 21 additions and 15 deletions
|
@ -1,8 +0,0 @@
|
|||
module.exports = {
|
||||
entry: {
|
||||
web: __dirname + "/src/index.ts",
|
||||
},
|
||||
output: {
|
||||
path: __dirname + "/dist",
|
||||
},
|
||||
};
|
28
src/index.ts
28
src/index.ts
|
@ -13,6 +13,7 @@ class Forgejo {
|
|||
url: URL;
|
||||
username: string;
|
||||
token?: Auth;
|
||||
cors: boolean;
|
||||
/**
|
||||
* Represents a Forgejo instance.
|
||||
* @constructor
|
||||
|
@ -20,6 +21,7 @@ class Forgejo {
|
|||
*/
|
||||
constructor(url: string) {
|
||||
this.url = new URL(url);
|
||||
this.cors = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,12 +52,21 @@ class Forgejo {
|
|||
return { Authorization: `token ${this.getTokenAuth().getToken()}` };
|
||||
}
|
||||
|
||||
getUrl(): URL {
|
||||
if (this.cors) {
|
||||
let url = new URL("http://localhost:3030");
|
||||
url.pathname = this.url.toString();
|
||||
return url;
|
||||
}
|
||||
return this.url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logged in user
|
||||
*/
|
||||
async getUser(): Promise<User> {
|
||||
this.url.pathname = "/api/v1/user";
|
||||
let res = await fetch(this.url, {
|
||||
let res = await fetch(this.getUrl(), {
|
||||
method: "GET",
|
||||
credentials: "omit",
|
||||
headers: this.getTokenAuthHeader(),
|
||||
|
@ -63,14 +74,17 @@ class Forgejo {
|
|||
return await res.json();
|
||||
}
|
||||
|
||||
setCors() {
|
||||
this.cors = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all notifications
|
||||
*/
|
||||
async getNotifications(): Promise<Array<Notification>> {
|
||||
this.url.pathname = "/api/v1/notifications";
|
||||
this.url.pathname = "/api/v1/notifications";
|
||||
console.log(this.url);
|
||||
let res = await fetch(this.url, {
|
||||
let res = await fetch(this.getUrl(), {
|
||||
method: "GET",
|
||||
credentials: "omit",
|
||||
headers: this.getTokenAuthHeader(),
|
||||
|
@ -83,7 +97,7 @@ class Forgejo {
|
|||
*/
|
||||
async getNumUnreadNotifications(): Promise<number> {
|
||||
this.url.pathname = "/api/v1/notifications/new";
|
||||
let res = await fetch(this.url, {
|
||||
let res = await fetch(this.getUrl(), {
|
||||
method: "GET",
|
||||
credentials: "omit",
|
||||
headers: this.getTokenAuthHeader(),
|
||||
|
@ -99,7 +113,7 @@ class Forgejo {
|
|||
*/
|
||||
async getNotificationThread(id: number): Promise<Notification> {
|
||||
this.url.pathname = `/api/v1/notifications/threads/${id}`;
|
||||
let res = await fetch(this.url, {
|
||||
let res = await fetch(this.getUrl(), {
|
||||
method: "GET",
|
||||
credentials: "omit",
|
||||
headers: this.getTokenAuthHeader(),
|
||||
|
@ -181,7 +195,7 @@ class Forgejo {
|
|||
*/
|
||||
async getIssue(owner: string, repo: string, id: number): Promise<Issue> {
|
||||
this.url.pathname = `/api/v1/repos/${owner}/${repo}/issues/${id}`;
|
||||
let res = await fetch(this.url, {
|
||||
let res = await fetch(this.getUrl(), {
|
||||
method: "GET",
|
||||
credentials: "omit",
|
||||
headers: this.getTokenAuthHeader(),
|
||||
|
@ -214,7 +228,7 @@ class Forgejo {
|
|||
// TODO: check if issue.number != issue.id causes problems. I'm assuming
|
||||
// Issue.number is the local repository issue ID and issue.id is DB ID
|
||||
this.url.pathname = `/api/v1/repos/${issue.repository.owner}/${issue.repository.name}/issues/${issue.number}/comments`;
|
||||
let res = await fetch(this.url, {
|
||||
let res = await fetch(this.getUrl(), {
|
||||
method: "GET",
|
||||
credentials: "omit",
|
||||
headers: this.getTokenAuthHeader(),
|
||||
|
|
Loading…
Reference in a new issue