58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import Cookies from 'js-cookie';
|
|
import type { StorageLike } from 'pinia-plugin-persistedstate';
|
|
import { Base64 } from 'js-base64';
|
|
|
|
export const LocalStorageApi: {
|
|
Get: (key: string) => string | null;
|
|
Set: (key: string, value: string) => void;
|
|
StorageApi: StorageLike;
|
|
} = {
|
|
Get(key: string): string | null {
|
|
const data = localStorage.getItem(key);
|
|
if (data) {
|
|
return Base64.decode(data);
|
|
}
|
|
return null;
|
|
},
|
|
Set(key: string, value: string) {
|
|
localStorage.setItem(key, Base64.encode(value));
|
|
},
|
|
StorageApi: {
|
|
getItem(key: string) {
|
|
return LocalStorageApi.Get(key);
|
|
},
|
|
setItem(key: string, value: string) {
|
|
LocalStorageApi.Set(key, value);
|
|
},
|
|
},
|
|
};
|
|
|
|
const CookiesApi: {
|
|
Get: (key: string) => string | null;
|
|
Set: (key: string, value: string) => void;
|
|
StorageApi: StorageLike;
|
|
} = {
|
|
Get(key: string): string | null {
|
|
const data = Cookies.get(key);
|
|
if (data) {
|
|
return Base64.decode(data);
|
|
}
|
|
return null;
|
|
},
|
|
Set(key: string, value: string) {
|
|
Cookies.set(key, Base64.encode(value), {
|
|
expires: 265,
|
|
});
|
|
},
|
|
StorageApi: {
|
|
getItem(key: string) {
|
|
return CookiesApi.Get(key);
|
|
},
|
|
setItem(key: string, value: string) {
|
|
CookiesApi.Set(key, value);
|
|
},
|
|
},
|
|
};
|
|
|
|
export default CookiesApi;
|