2023-05-25 11:37:11 +08:00
|
|
|
import { IStorage } from '@certd/pipeline';
|
2024-07-15 00:30:33 +08:00
|
|
|
import { StorageService } from './storage-service.js';
|
2023-01-29 13:44:19 +08:00
|
|
|
|
|
|
|
|
export class DbStorage implements IStorage {
|
|
|
|
|
/**
|
|
|
|
|
* 范围: user / pipeline / runtime / task
|
|
|
|
|
*/
|
|
|
|
|
storageService: StorageService;
|
|
|
|
|
userId: number;
|
|
|
|
|
constructor(userId: number, storageService: StorageService) {
|
|
|
|
|
this.userId = userId;
|
|
|
|
|
this.storageService = storageService;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-04 02:35:45 +08:00
|
|
|
async remove(scope: string, namespace: string, version: string, key: string): Promise<void> {
|
2023-05-24 15:41:35 +08:00
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 01:30:00 +08:00
|
|
|
async get(scope: string, namespace: string, version: string, key: string): Promise<string | null> {
|
2023-01-29 13:44:19 +08:00
|
|
|
const storageEntity = await this.storageService.get({
|
|
|
|
|
userId: this.userId,
|
|
|
|
|
scope: scope,
|
|
|
|
|
namespace: namespace,
|
2023-05-24 15:41:35 +08:00
|
|
|
version,
|
2023-01-29 13:44:19 +08:00
|
|
|
key,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (storageEntity != null) {
|
|
|
|
|
return storageEntity.value;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 01:30:00 +08:00
|
|
|
async set(scope: string, namespace: string, version: string, key: string, value: string): Promise<void> {
|
2023-01-29 13:44:19 +08:00
|
|
|
await this.storageService.set({
|
|
|
|
|
userId: this.userId,
|
|
|
|
|
scope: scope,
|
|
|
|
|
namespace: namespace,
|
2023-05-24 15:41:35 +08:00
|
|
|
version,
|
2023-01-29 13:44:19 +08:00
|
|
|
key,
|
|
|
|
|
value,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|