Skip to content

Commit

Permalink
fix: do not add query params on top of the URL with query params
Browse files Browse the repository at this point in the history
  • Loading branch information
gabivlj committed Nov 20, 2024
1 parent 3e532ba commit ea37472
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ v2Router.delete("/:name+/manifests/:reference", async (req, env: Env) => {
}
}

const url = new URL(req.url);
if (tags.truncated) {
url.searchParams.set("last", tags.truncated ? tags.cursor : "");
return new Response(JSON.stringify(ManifestTagsListTooBigError), {
status: 400,
headers: {
"Link": `${req.url}/?last=${tags.truncated ? tags.cursor : ""}; rel=next`,
"Link": `${url.toString()}; rel=next`,
"Content-Type": "application/json",
},
});
Expand Down Expand Up @@ -529,6 +531,9 @@ v2Router.get("/:name+/tags/list", async (req, env: Env) => {
});

const keys = tags.objects.map((object) => object.key.split("/").pop()!);
const url = new URL(req.url);
url.searchParams.set("n", `${n}`);
url.searchParams.set("last", keys.length ? keys[keys.length - 1] : "");
return new Response(
JSON.stringify({
name,
Expand All @@ -538,7 +543,7 @@ v2Router.get("/:name+/tags/list", async (req, env: Env) => {
status: 200,
headers: {
"Content-Type": "application/json",
"Link": `${req.url}?n=${n}&last=${keys.length ? keys[keys.length - 1] : ""}; rel=next`,
"Link": `${url.toString()}; rel=next`,
},
},
);
Expand Down

0 comments on commit ea37472

Please sign in to comment.