fix KV API to unified format

This commit is contained in:
Pierre
2026-01-24 22:19:51 +01:00
parent 53c4463084
commit 759009c019
4 changed files with 28 additions and 5 deletions
@@ -1198,8 +1198,8 @@ export class UnifiedAPIServer {
} }
try { try {
const key = `/file/${hashId}/${property}`; // Write directly to Redis Hash (not flat keys)
await this.kvClient!.setProperty(key, String(value)); await this.kvClient!.setMetadataProperty(hashId, property, String(value));
return { return {
status: 'ok', status: 'ok',
@@ -1341,11 +1341,10 @@ export class UnifiedAPIServer {
await this.kvClient!.setMetadataFlat(hashId, metadata, ['processingStatus']); await this.kvClient!.setMetadataFlat(hashId, metadata, ['processingStatus']);
} }
// Update individual properties // Update individual properties (write to Redis Hash)
if (properties) { if (properties) {
for (const [property, value] of Object.entries(properties)) { for (const [property, value] of Object.entries(properties)) {
const key = `/file/${hashId}/${property}`; await this.kvClient!.setMetadataProperty(hashId, property, String(value));
await this.kvClient!.setProperty(key, String(value));
} }
} }
@@ -112,6 +112,13 @@ class MockKVClient implements IKVClient {
return entry.get(propertyPath) ?? null; 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> { async deleteMetadataFlat(hashId: string): Promise<number> {
const entry = this.data.get(hashId); const entry = this.data.get(hashId);
const count = entry?.size ?? 0; const count = entry?.size ?? 0;
@@ -96,6 +96,11 @@ export interface IKVClient {
*/ */
getMetadata(hashId: string, propertyPath: string): Promise<any | null>; 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 * 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> { async deleteMetadataFlat(hashId: string): Promise<number> {
const hashKey = this.buildKey(`file:${hashId}`); const hashKey = this.buildKey(`file:${hashId}`);
const fieldCount = await this.redis.hlen(hashKey); const fieldCount = await this.redis.hlen(hashKey);