mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-12-02 10:03:15 +00:00
Merge branch 'main' of https://github.com/siiddhantt/DocsGPT into pr/1930
This commit is contained in:
16
frontend/src/utils/providerUtils.ts
Normal file
16
frontend/src/utils/providerUtils.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Utility functions for managing session tokens for different cloud service providers.
|
||||
* Follows the convention: {provider}_session_token
|
||||
*/
|
||||
|
||||
export const getSessionToken = (provider: string): string | null => {
|
||||
return localStorage.getItem(`${provider}_session_token`);
|
||||
};
|
||||
|
||||
export const setSessionToken = (provider: string, token: string): void => {
|
||||
localStorage.setItem(`${provider}_session_token`, token);
|
||||
};
|
||||
|
||||
export const removeSessionToken = (provider: string): void => {
|
||||
localStorage.removeItem(`${provider}_session_token`);
|
||||
};
|
||||
@@ -2,3 +2,12 @@ export function truncate(str: string, n: number) {
|
||||
// slices long strings and ends with ...
|
||||
return str.length > n ? str.slice(0, n - 1) + '...' : str;
|
||||
}
|
||||
|
||||
export function formatBytes(bytes: number | null): string {
|
||||
if (!bytes || bytes <= 0) return '';
|
||||
|
||||
const k = 1024;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user