fed-sx-m1: Step 8c-art — GET /artifacts/{cid} route reusing match_prefix + 9 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 29s

This commit is contained in:
2026-05-28 09:41:41 +00:00
parent a4905a3e71
commit 2aeab806fb
3 changed files with 135 additions and 10 deletions

View File

@@ -2,7 +2,8 @@
-export([route/1, ok_response/1, not_found_response/0,
welcome_body/0, capabilities_body/0,
capabilities_path/0,
match_prefix/2, actors_prefix/0, actor_doc_response/1]).
match_prefix/2, actors_prefix/0, actor_doc_response/1,
artifacts_prefix/0, artifact_response/1]).
%% HTTP request router per design §16.1.
%%
@@ -35,16 +36,18 @@ dispatch(<<71, 69, 84>>,
<<47,46,119,101,108,108,45,107,110,111,119,110,
47,115,120,45,99,97,112,97,98,105,108,105,116,105,101,115>>) ->
ok_response(capabilities_body());
%% GET /actors/{id}
%% GET /actors/{id} or /artifacts/{cid}
dispatch(<<71, 69, 84>>, Path) ->
case match_prefix(actors_prefix(), Path) of
{ok, Id} ->
case byte_size(Id) of
0 -> not_found_response();
_ -> actor_doc_response(Id)
end;
nomatch ->
not_found_response()
{ok, Id} when byte_size(Id) > 0 ->
actor_doc_response(Id);
_ ->
case match_prefix(artifacts_prefix(), Path) of
{ok, Cid} when byte_size(Cid) > 0 ->
artifact_response(Cid);
_ ->
not_found_response()
end
end;
dispatch(_, _) ->
not_found_response().
@@ -112,3 +115,16 @@ actor_doc_response(Id) ->
Pre = <<97,99,116,111,114,58,32>>,
Body = <<Pre/binary, Id/binary, 10>>,
ok_response(Body).
%% "/artifacts/" — 11 bytes
artifacts_prefix() ->
<<47,97,114,116,105,102,97,99,116,115,47>>.
%% Artifact stub. Real implementation will fetch the bytes from
%% the registry (or a CID-keyed store) and content-negotiate.
%% v1 echoes the CID so route resolution can be tested.
artifact_response(Cid) ->
%% "artifact: " — 10 bytes
Pre = <<97,114,116,105,102,97,99,116,58,32>>,
Body = <<Pre/binary, Cid/binary, 10>>,
ok_response(Body).