Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export class YdbEmbeddedAPI {
meta?: MetaAPI;
codeAssist?: CodeAssistAPI;

constructor({webVersion = false, withCredentials = false} = {}) {
constructor({
webVersion = false,
withCredentials = false,
csrfTokenGetter = () => undefined,
} = {}) {
const config: AxiosRequestConfig = {withCredentials};

this.auth = new AuthAPI({config});
Expand All @@ -47,5 +51,20 @@ export class YdbEmbeddedAPI {
this.tablets = new TabletsAPI({config});
this.vdisk = new VDiskAPI({config});
this.viewer = new ViewerAPI({config});

const token = csrfTokenGetter();
if (token) {
this.auth.setCSRFToken(token);
this.meta?.setCSRFToken(token);
this.codeAssist?.setCSRFToken(token);
this.operation.setCSRFToken(token);
this.pdisk.setCSRFToken(token);
this.scheme.setCSRFToken(token);
this.storage.setCSRFToken(token);
this.streaming.setCSRFToken(token);
this.tablets.setCSRFToken(token);
this.vdisk.setCSRFToken(token);
this.viewer.setCSRFToken(token);
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repetitive manual token setting for each API service creates maintainability issues. Consider iterating over the API services or creating a helper method to reduce code duplication.

Suggested change
this.auth.setCSRFToken(token);
this.meta?.setCSRFToken(token);
this.codeAssist?.setCSRFToken(token);
this.operation.setCSRFToken(token);
this.pdisk.setCSRFToken(token);
this.scheme.setCSRFToken(token);
this.storage.setCSRFToken(token);
this.streaming.setCSRFToken(token);
this.tablets.setCSRFToken(token);
this.vdisk.setCSRFToken(token);
this.viewer.setCSRFToken(token);
const services = [
this.auth,
this.meta,
this.codeAssist,
this.operation,
this.pdisk,
this.scheme,
this.storage,
this.streaming,
this.tablets,
this.vdisk,
this.viewer,
];
services.forEach(service => service?.setCSRFToken(token));

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont like

}
}
}
Loading