mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-11-07 00:05:14 +00:00
20 lines
597 B
Go
20 lines
597 B
Go
import { Base64 } from 'js-base64';
|
|
|
|
type StringLikeRecord = object;
|
|
|
|
export const encodeBase64 = (value: string) => Base64.encode(value);
|
|
|
|
export const decodeBase64 = (value: string) => Base64.decode(value);
|
|
|
|
export const encodeBase64Fields = <T extends StringLikeRecord>(target: T, fields: Array<Extract<keyof T, string>>) => {
|
|
fields.forEach((field) => {
|
|
const record = target as Record<string, unknown>;
|
|
const value = record[field];
|
|
if (typeof value === 'string' && value) {
|
|
record[field] = encodeBase64(value);
|
|
}
|
|
});
|
|
|
|
return target;
|
|
};
|