From cde04c9917226694f2badede8f303c4232c90bfd Mon Sep 17 00:00:00 2001 From: despiegk Date: Sun, 14 Sep 2025 16:36:47 +0200 Subject: [PATCH] ... --- lib/hero/herofs/rpc/openrpc.json | 30 ++++++++++---------------- lib/hero/herofs/rpc/rpc_fs_blob.v | 35 ++++++++++--------------------- 2 files changed, 22 insertions(+), 43 deletions(-) diff --git a/lib/hero/herofs/rpc/openrpc.json b/lib/hero/herofs/rpc/openrpc.json index e81d439d..3ff870c6 100644 --- a/lib/hero/herofs/rpc/openrpc.json +++ b/lib/hero/herofs/rpc/openrpc.json @@ -717,17 +717,25 @@ }, { "name": "fs_blob_get", - "summary": "Get a blob by ID", - "description": "Retrieve a blob by its ID", + "summary": "Get a blob by ID or hash", + "description": "Retrieve a blob by its ID or hash", "params": [ { "name": "id", "description": "ID of blob to fetch", - "required": true, + "required": false, "schema": { "type": "integer", "minimum": 0 } + }, + { + "name": "hash", + "description": "Hash of blob to fetch", + "required": false, + "schema": { + "type": "string" + } } ], "result": { @@ -798,22 +806,6 @@ } } }, - { - "name": "fs_blob_list", - "summary": "List all blobs", - "description": "List all blobs in the system", - "params": [], - "result": { - "name": "blobs", - "description": "List of all blob objects with base64-encoded data", - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Blob" - } - } - } - }, { "name": "fs_symlink_get", "summary": "Get a symlink by ID", diff --git a/lib/hero/herofs/rpc/rpc_fs_blob.v b/lib/hero/herofs/rpc/rpc_fs_blob.v index 99b09980..e5a65f19 100644 --- a/lib/hero/herofs/rpc/rpc_fs_blob.v +++ b/lib/hero/herofs/rpc/rpc_fs_blob.v @@ -9,7 +9,8 @@ import encoding.base64 @[params] pub struct FSBlobGetArgs { pub mut: - id u32 @[required] + id u32 + hash string } @[params] @@ -32,8 +33,16 @@ pub fn fs_blob_get(request Request) !Response { } mut fs_factory := herofs.new()! - blob := fs_factory.fs_blob.get(payload.id)! + // Get blob by either id or hash + mut blob := if payload.id > 0 { + fs_factory.fs_blob.get(payload.id)! + } else if payload.hash != '' { + fs_factory.fs_blob.get_by_hash(payload.hash)! + } else { + return jsonrpc.invalid_params_with_msg("Either id or hash must be provided") + } + // Convert binary data to base64 for JSON transport blob_response := { 'id': blob.id.str() @@ -81,25 +90,3 @@ pub fn fs_blob_delete(request Request) !Response { return new_response_true(request.id) } - -pub fn fs_blob_list(request Request) !Response { - mut fs_factory := herofs.new()! - blob_list := fs_factory.fs_blob.list()! - - // Convert binary data to base64 for each blob - mut blob_responses := []map[string]string{} - for blob in blob_list { - blob_responses << { - 'id': blob.id.str() - 'created_at': blob.created_at.str() - 'updated_at': blob.updated_at.str() - 'mime_type': blob.mime_type - 'name': blob.name - 'hash': blob.hash - 'size_bytes': blob.size_bytes.str() - 'data_base64': base64.encode(blob.data) - } - } - - return jsonrpc.new_response(request.id, json.encode(blob_responses)) -}