temp
This commit is contained in:
@@ -5,6 +5,9 @@ export type CNBCoreOptions<T = {}> = {
|
||||
*/
|
||||
cookie?: string;
|
||||
cnb?: CNBCore;
|
||||
cors?: {
|
||||
baseUrl?: string
|
||||
}
|
||||
} & T;
|
||||
|
||||
export type RequestOptions = {
|
||||
@@ -19,6 +22,7 @@ export type RequestOptions = {
|
||||
};
|
||||
export class CNBCore {
|
||||
baseURL = 'https://api.cnb.cool';
|
||||
hackURL = 'https://cnb.cool'
|
||||
public token: string;
|
||||
public cookie?: string;
|
||||
constructor(options: CNBCoreOptions) {
|
||||
@@ -32,6 +36,10 @@ export class CNBCore {
|
||||
this.cookie = options.cnb.cookie;
|
||||
}
|
||||
}
|
||||
if (options?.cors?.baseUrl) {
|
||||
this.baseURL = options.cors.baseUrl + '/' + this.baseURL;
|
||||
this.hackURL = options.cors.baseUrl + '/' + this.hackURL;
|
||||
}
|
||||
}
|
||||
|
||||
async request({ url, method = 'GET', data, params, headers, body, useCookie, useOrigin }: RequestOptions): Promise<any> {
|
||||
|
||||
@@ -23,7 +23,7 @@ export class Repo extends CNBCore {
|
||||
return this.post({ url, data: postData });
|
||||
}
|
||||
deleteRepo(name: string): Promise<any> {
|
||||
const url = `https://cnb.cool/${name}`;
|
||||
const url = `${this.hackURL}/${name}`;
|
||||
return this.delete({ url, useCookie: true });
|
||||
}
|
||||
async createCommit(repo: string, data: CreateCommitData): Promise<any> {
|
||||
@@ -38,7 +38,7 @@ export class Repo extends CNBCore {
|
||||
if (!data.parent_commit_sha && preCommitSha) {
|
||||
data.parent_commit_sha = preCommitSha;
|
||||
}
|
||||
const url = `https://cnb.cool/${repo}/-/git/commits`;
|
||||
const url = `${this.hackURL}/${repo}/-/git/commits`;
|
||||
const postData: CreateCommitData = {
|
||||
...data,
|
||||
base_branch: data.base_branch || 'refs/heads/main',
|
||||
|
||||
@@ -10,7 +10,7 @@ export class User extends CNBCore {
|
||||
* @returns
|
||||
*/
|
||||
getCurrentUser(): Promise<Result<UserInfo>> {
|
||||
const url = `https://cnb.cool/user`;
|
||||
const url = `${this.hackURL}/user`;
|
||||
return this.get({
|
||||
url,
|
||||
useCookie: true,
|
||||
@@ -26,7 +26,7 @@ export class User extends CNBCore {
|
||||
}
|
||||
createAccessToken(data?: { description?: string, scope?: string }): Promise<AccessTokenResponse> {
|
||||
const scope = data?.scope || 'mission-manage:rw,mission-delete:rw,group-delete:rw,group-manage:rw,group-resource:rw,account-engage:rw,account-email:r,account-profile:rw,registry-delete:rw,registry-manage:rw,registry-package-delete:rw,registry-package:rw,repo-security:r,repo-delete:rw,repo-manage:rw,repo-basic-info:r,repo-cnb-detail:rw,repo-cnb-history:r,repo-cnb-trigger:rw,repo-commit-status:rw,repo-contents:rw,repo-notes:rw,repo-issue:rw,repo-pr:rw,repo-code:rw'
|
||||
const url = 'https://cnb.cool/user/personal_access_tokens'
|
||||
const url = `${this.hackURL}/user/personal_access_tokens`
|
||||
return this.post({
|
||||
url,
|
||||
useCookie: true,
|
||||
@@ -37,7 +37,7 @@ export class User extends CNBCore {
|
||||
})
|
||||
}
|
||||
getAccessTokens(params?: { page?: number, page_size?: number }): Promise<AccessTokenResponse[]> {
|
||||
const url = 'https://cnb.cool/user/personal_access_tokens'
|
||||
const url = `${this.hackURL}/user/personal_access_tokens`
|
||||
return this.get({
|
||||
url,
|
||||
useCookie: true,
|
||||
@@ -49,7 +49,7 @@ export class User extends CNBCore {
|
||||
})
|
||||
}
|
||||
deleteAccessToken(tokenId: string): Promise<any> {
|
||||
const url = `https://cnb.cool/user/personal_access_tokens/${tokenId}`
|
||||
const url = `${this.hackURL}/user/personal_access_tokens/${tokenId}`
|
||||
return this.delete({
|
||||
url,
|
||||
useCookie: true,
|
||||
|
||||
Reference in New Issue
Block a user