fix(api-client): supports silent mode (#5512)
Some checks are pending
Build docker image / build-and-push (push) Waiting to run
Build pro image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase frontEnd test / frontend-test (18) (push) Waiting to run

This commit is contained in:
chenos 2024-10-25 16:13:31 +08:00 committed by GitHub
parent 4712a19d6d
commit 158ef760fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 6 deletions

View File

@ -61,6 +61,19 @@ export class APIClient extends APIClientSDK {
/** 该值会在 AntdAppProvider 中被重新赋值 */ /** 该值会在 AntdAppProvider 中被重新赋值 */
notification: any = notification; notification: any = notification;
cloneInstance() {
const api = new APIClient(this.options);
api.options = this.options;
api.services = this.services;
api.storage = this.storage;
api.app = this.app;
api.auth = this.auth;
api.storagePrefix = this.storagePrefix;
api.notification = this.notification;
api.axios = this.axios;
return api;
}
getHeaders() { getHeaders() {
const headers = super.getHeaders(); const headers = super.getHeaders();
const appName = this.app.getName(); const appName = this.app.getName();
@ -180,7 +193,8 @@ export class APIClient extends APIClientSDK {
} }
silent() { silent() {
this.silence = true; const api = this.cloneInstance();
return this; api.silence = true;
return api;
} }
} }

View File

@ -275,6 +275,7 @@ interface ExtendedOptions {
export type APIClientOptions = AxiosInstance | (AxiosRequestConfig & ExtendedOptions); export type APIClientOptions = AxiosInstance | (AxiosRequestConfig & ExtendedOptions);
export class APIClient { export class APIClient {
options?: APIClientOptions;
axios: AxiosInstance; axios: AxiosInstance;
auth: Auth; auth: Auth;
storage: Storage; storage: Storage;
@ -297,11 +298,12 @@ export class APIClient {
return headers; return headers;
} }
constructor(instance?: APIClientOptions) { constructor(options?: APIClientOptions) {
if (typeof instance === 'function') { this.options = options;
this.axios = instance; if (typeof options === 'function') {
this.axios = options;
} else { } else {
const { authClass, storageType, storageClass, storagePrefix = 'NOCOBASE_', ...others } = instance || {}; const { authClass, storageType, storageClass, storagePrefix = 'NOCOBASE_', ...others } = options || {};
this.storagePrefix = storagePrefix; this.storagePrefix = storagePrefix;
this.axios = axios.create(others); this.axios = axios.create(others);
this.initStorage(storageClass, storageType); this.initStorage(storageClass, storageType);