更新版本号至0.0.18,优化构建脚本,更新@types/node依赖至25.2.1,并重构CNBCore类以提高可读性
This commit is contained in:
@@ -20,9 +20,11 @@ export type RequestOptions = {
|
||||
useCookie?: boolean;
|
||||
useOrigin?: boolean;
|
||||
};
|
||||
const API_BASER_URL = 'https://api.cnb.cool'
|
||||
const API_HACK_URL = 'https://cnb.cool'
|
||||
export class CNBCore {
|
||||
baseURL = 'https://api.cnb.cool';
|
||||
hackURL = 'https://cnb.cool'
|
||||
baseURL = API_BASER_URL;
|
||||
hackURL = API_HACK_URL;
|
||||
public token: string;
|
||||
public cookie?: string;
|
||||
constructor(options: CNBCoreOptions) {
|
||||
@@ -37,8 +39,8 @@ export class CNBCore {
|
||||
}
|
||||
}
|
||||
if (options?.cors?.baseUrl) {
|
||||
this.baseURL = options.cors.baseUrl + '/' + this.baseURL;
|
||||
this.hackURL = options.cors.baseUrl + '/' + this.hackURL;
|
||||
this.baseURL = options.cors.baseUrl + '/' + API_BASER_URL.replace('https://', '');
|
||||
this.hackURL = options.cors.baseUrl + '/' + API_HACK_URL.replace('https://', '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +109,11 @@ export class CNBCore {
|
||||
if (url && url.startsWith('http')) {
|
||||
return url;
|
||||
}
|
||||
return new URL(url || '', this.baseURL).toString();
|
||||
console.log('url', url, this.baseURL)
|
||||
if (url.startsWith('/')) {
|
||||
return this.baseURL + url;
|
||||
}
|
||||
return this.baseURL + '/' + url;
|
||||
}
|
||||
get<T = any>({ url, ...REST }: RequestOptions): Promise<T> {
|
||||
const fullUrl = this.makeUrl(url);
|
||||
|
||||
Reference in New Issue
Block a user