fix KV API to unified format
This commit is contained in:
@@ -1198,8 +1198,8 @@ export class UnifiedAPIServer {
|
||||
}
|
||||
|
||||
try {
|
||||
const key = `/file/${hashId}/${property}`;
|
||||
await this.kvClient!.setProperty(key, String(value));
|
||||
// Write directly to Redis Hash (not flat keys)
|
||||
await this.kvClient!.setMetadataProperty(hashId, property, String(value));
|
||||
|
||||
return {
|
||||
status: 'ok',
|
||||
@@ -1341,11 +1341,10 @@ export class UnifiedAPIServer {
|
||||
await this.kvClient!.setMetadataFlat(hashId, metadata, ['processingStatus']);
|
||||
}
|
||||
|
||||
// Update individual properties
|
||||
// Update individual properties (write to Redis Hash)
|
||||
if (properties) {
|
||||
for (const [property, value] of Object.entries(properties)) {
|
||||
const key = `/file/${hashId}/${property}`;
|
||||
await this.kvClient!.setProperty(key, String(value));
|
||||
await this.kvClient!.setMetadataProperty(hashId, property, String(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,13 @@ class MockKVClient implements IKVClient {
|
||||
return entry.get(propertyPath) ?? null;
|
||||
}
|
||||
|
||||
async setMetadataProperty(hashId: string, property: string, value: string): Promise<void> {
|
||||
if (!this.data.has(hashId)) {
|
||||
this.data.set(hashId, new Map());
|
||||
}
|
||||
this.data.get(hashId)!.set(property, value);
|
||||
}
|
||||
|
||||
async deleteMetadataFlat(hashId: string): Promise<number> {
|
||||
const entry = this.data.get(hashId);
|
||||
const count = entry?.size ?? 0;
|
||||
|
||||
@@ -96,6 +96,11 @@ export interface IKVClient {
|
||||
*/
|
||||
getMetadata(hashId: string, propertyPath: string): Promise<any | null>;
|
||||
|
||||
/**
|
||||
* Set a single metadata property for a file (writes to Redis Hash)
|
||||
*/
|
||||
setMetadataProperty(hashId: string, property: string, value: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Delete all metadata for a file
|
||||
*/
|
||||
|
||||
@@ -298,6 +298,18 @@ export class RedisKVClient implements IKVClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single metadata property for a file
|
||||
* Writes directly to Redis hash field
|
||||
*/
|
||||
async setMetadataProperty(hashId: string, property: string, value: string): Promise<void> {
|
||||
const hashKey = this.buildKey(`file:${hashId}`);
|
||||
await this.redis.hset(hashKey, property, value);
|
||||
|
||||
// Also ensure the file is in the index
|
||||
await this.redis.sadd(this.buildKey('file:__index__'), hashId);
|
||||
}
|
||||
|
||||
async deleteMetadataFlat(hashId: string): Promise<number> {
|
||||
const hashKey = this.buildKey(`file:${hashId}`);
|
||||
const fieldCount = await this.redis.hlen(hashKey);
|
||||
|
||||
Reference in New Issue
Block a user