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;
|
url: URL;
|
||||||
username: string;
|
username: string;
|
||||||
token?: Auth;
|
token?: Auth;
|
||||||
|
cors: boolean;
|
||||||
/**
|
/**
|
||||||
* Represents a Forgejo instance.
|
* Represents a Forgejo instance.
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -20,6 +21,7 @@ class Forgejo {
|
||||||
*/
|
*/
|
||||||
constructor(url: string) {
|
constructor(url: string) {
|
||||||
this.url = new URL(url);
|
this.url = new URL(url);
|
||||||
|
this.cors = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,12 +52,21 @@ class Forgejo {
|
||||||
return { Authorization: `token ${this.getTokenAuth().getToken()}` };
|
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
|
* Get logged in user
|
||||||
*/
|
*/
|
||||||
async getUser(): Promise<User> {
|
async getUser(): Promise<User> {
|
||||||
this.url.pathname = "/api/v1/user";
|
this.url.pathname = "/api/v1/user";
|
||||||
let res = await fetch(this.url, {
|
let res = await fetch(this.getUrl(), {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
credentials: "omit",
|
credentials: "omit",
|
||||||
headers: this.getTokenAuthHeader(),
|
headers: this.getTokenAuthHeader(),
|
||||||
|
@ -63,14 +74,17 @@ class Forgejo {
|
||||||
return await res.json();
|
return await res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCors() {
|
||||||
|
this.cors = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all notifications
|
* Get all notifications
|
||||||
*/
|
*/
|
||||||
async getNotifications(): Promise<Array<Notification>> {
|
async getNotifications(): Promise<Array<Notification>> {
|
||||||
this.url.pathname = "/api/v1/notifications";
|
|
||||||
this.url.pathname = "/api/v1/notifications";
|
this.url.pathname = "/api/v1/notifications";
|
||||||
console.log(this.url);
|
console.log(this.url);
|
||||||
let res = await fetch(this.url, {
|
let res = await fetch(this.getUrl(), {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
credentials: "omit",
|
credentials: "omit",
|
||||||
headers: this.getTokenAuthHeader(),
|
headers: this.getTokenAuthHeader(),
|
||||||
|
@ -83,7 +97,7 @@ class Forgejo {
|
||||||
*/
|
*/
|
||||||
async getNumUnreadNotifications(): Promise<number> {
|
async getNumUnreadNotifications(): Promise<number> {
|
||||||
this.url.pathname = "/api/v1/notifications/new";
|
this.url.pathname = "/api/v1/notifications/new";
|
||||||
let res = await fetch(this.url, {
|
let res = await fetch(this.getUrl(), {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
credentials: "omit",
|
credentials: "omit",
|
||||||
headers: this.getTokenAuthHeader(),
|
headers: this.getTokenAuthHeader(),
|
||||||
|
@ -99,7 +113,7 @@ class Forgejo {
|
||||||
*/
|
*/
|
||||||
async getNotificationThread(id: number): Promise<Notification> {
|
async getNotificationThread(id: number): Promise<Notification> {
|
||||||
this.url.pathname = `/api/v1/notifications/threads/${id}`;
|
this.url.pathname = `/api/v1/notifications/threads/${id}`;
|
||||||
let res = await fetch(this.url, {
|
let res = await fetch(this.getUrl(), {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
credentials: "omit",
|
credentials: "omit",
|
||||||
headers: this.getTokenAuthHeader(),
|
headers: this.getTokenAuthHeader(),
|
||||||
|
@ -181,7 +195,7 @@ class Forgejo {
|
||||||
*/
|
*/
|
||||||
async getIssue(owner: string, repo: string, id: number): Promise<Issue> {
|
async getIssue(owner: string, repo: string, id: number): Promise<Issue> {
|
||||||
this.url.pathname = `/api/v1/repos/${owner}/${repo}/issues/${id}`;
|
this.url.pathname = `/api/v1/repos/${owner}/${repo}/issues/${id}`;
|
||||||
let res = await fetch(this.url, {
|
let res = await fetch(this.getUrl(), {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
credentials: "omit",
|
credentials: "omit",
|
||||||
headers: this.getTokenAuthHeader(),
|
headers: this.getTokenAuthHeader(),
|
||||||
|
@ -214,7 +228,7 @@ class Forgejo {
|
||||||
// TODO: check if issue.number != issue.id causes problems. I'm assuming
|
// 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
|
// 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`;
|
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",
|
method: "GET",
|
||||||
credentials: "omit",
|
credentials: "omit",
|
||||||
headers: this.getTokenAuthHeader(),
|
headers: this.getTokenAuthHeader(),
|
||||||
|
|
Loading…
Reference in a new issue