This commit is contained in:
2025-09-14 16:36:47 +02:00
parent 397b544ab2
commit cde04c9917
2 changed files with 22 additions and 43 deletions

View File

@@ -717,17 +717,25 @@
}, },
{ {
"name": "fs_blob_get", "name": "fs_blob_get",
"summary": "Get a blob by ID", "summary": "Get a blob by ID or hash",
"description": "Retrieve a blob by its ID", "description": "Retrieve a blob by its ID or hash",
"params": [ "params": [
{ {
"name": "id", "name": "id",
"description": "ID of blob to fetch", "description": "ID of blob to fetch",
"required": true, "required": false,
"schema": { "schema": {
"type": "integer", "type": "integer",
"minimum": 0 "minimum": 0
} }
},
{
"name": "hash",
"description": "Hash of blob to fetch",
"required": false,
"schema": {
"type": "string"
}
} }
], ],
"result": { "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", "name": "fs_symlink_get",
"summary": "Get a symlink by ID", "summary": "Get a symlink by ID",

View File

@@ -9,7 +9,8 @@ import encoding.base64
@[params] @[params]
pub struct FSBlobGetArgs { pub struct FSBlobGetArgs {
pub mut: pub mut:
id u32 @[required] id u32
hash string
} }
@[params] @[params]
@@ -32,7 +33,15 @@ pub fn fs_blob_get(request Request) !Response {
} }
mut fs_factory := herofs.new()! 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 // Convert binary data to base64 for JSON transport
blob_response := { blob_response := {
@@ -81,25 +90,3 @@ pub fn fs_blob_delete(request Request) !Response {
return new_response_true(request.id) 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))
}