feat(image): 新建 knowai-core:1.0.0 镜像并完成推送
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
- 搭建 api、auth、utils 等逻辑模块 - 通过 tsc、eslint、vitest 测试验证 BREAKING CHANGE: 新镜像分支
This commit is contained in:
55
auth/storage-adapter.ts
Normal file
55
auth/storage-adapter.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 存储适配器接口
|
||||
* 提供统一的存储接口,用于非敏感数据的临时存储
|
||||
* 注意:此存储适配器不用于session管理,session完全由服务器端控制
|
||||
*/
|
||||
import type { StorageAdapter } from './types';
|
||||
|
||||
/**
|
||||
* 内存存储适配器
|
||||
* 适用于非敏感数据的临时存储,如UI状态、用户偏好设置等
|
||||
*/
|
||||
export class MemoryStorageAdapter implements StorageAdapter {
|
||||
private storage: Record<string, string> = {};
|
||||
|
||||
getItem(key: string): string | null {
|
||||
return this.storage[key] || null;
|
||||
}
|
||||
|
||||
setItem(key: string, value: string): void {
|
||||
this.storage[key] = value;
|
||||
}
|
||||
|
||||
removeItem(key: string): void {
|
||||
delete this.storage[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空所有存储项
|
||||
*/
|
||||
clear(): void {
|
||||
this.storage = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有存储键
|
||||
* @returns 存储键数组
|
||||
*/
|
||||
keys(): string[] {
|
||||
return Object.keys(this.storage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建存储适配器
|
||||
* @param type 存储类型,目前只支持memory
|
||||
* @returns 存储适配器实例
|
||||
*/
|
||||
export function createStorageAdapter(type: 'memory' = 'memory'): StorageAdapter {
|
||||
switch (type) {
|
||||
case 'memory':
|
||||
return new MemoryStorageAdapter();
|
||||
default:
|
||||
return new MemoryStorageAdapter();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user