Build every ApiClient request URL in one place (closes #18) #87

Merged
clawbot merged 1 commits from issue-18-url-helper into next2 2026-09-23 02:57:42 +02:00
Collaborator

Implements #18.

ApiClient built request URLs two ways: getJSON used new URL and then overwrote host and path, which dropped a base path from a self-hosted apiOrigin; postJSON, putJSON and the file and thumbnail download URLs joined strings. Every one of those now goes through buildURL, a plain function next to the class. It accepts a path with or without a leading slash and an origin with or without a trailing slash or base path, and percent-encodes query parameters.

Things the diff does not make obvious:

  • Behaviour change: a self-hosted apiOrigin such as https://example.com/ente now keeps /ente on getJSON requests too; before, only POST/PUT and downloads kept it.
  • A path containing ? is rejected, as the brief asks. Judgement call: # is rejected as well, since new URL would otherwise quietly treat the rest as a fragment.
  • The rejection is thrown before the request's retry wrapper, so it is not retried.
  • The constructor still strips trailing slashes, because the check for a custom origin compares against the default after stripping.
  • Existing URL tests in test/api/client.test.ts are unchanged; new tests are in the "ApiClient request URLs" block.

make check green.

Model: opus-5-5

Implements https://git.eeqj.de/sneak/quak/issues/18. `ApiClient` built request URLs two ways: `getJSON` used `new URL` and then overwrote host and path, which dropped a base path from a self-hosted `apiOrigin`; `postJSON`, `putJSON` and the file and thumbnail download URLs joined strings. Every one of those now goes through `buildURL`, a plain function next to the class. It accepts a path with or without a leading slash and an origin with or without a trailing slash or base path, and percent-encodes query parameters. Things the diff does not make obvious: - Behaviour change: a self-hosted `apiOrigin` such as `https://example.com/ente` now keeps `/ente` on `getJSON` requests too; before, only POST/PUT and downloads kept it. - A path containing `?` is rejected, as the brief asks. Judgement call: `#` is rejected as well, since `new URL` would otherwise quietly treat the rest as a fragment. - The rejection is thrown before the request's retry wrapper, so it is not retried. - The constructor still strips trailing slashes, because the check for a custom origin compares against the default after stripping. - Existing URL tests in `test/api/client.test.ts` are unchanged; new tests are in the "ApiClient request URLs" block. `make check` green. Model: opus-5-5
clawbot added the needs-review label 2026-09-23 02:41:33 +02:00
clawbot self-assigned this 2026-09-23 02:41:33 +02:00
Author
Collaborator

PASS on cc09eef rebased onto next2 ed535be (TODO.md-only conflict, resolved locally).

Non-blocking: the # rejection in buildURL (src/api/client.ts:111) has no test; removing it leaves the suite green. A one-line case next to the ? rejection test would pin it.

Model: opus-5-5

PASS on `cc09eef` rebased onto `next2` `ed535be` (TODO.md-only conflict, resolved locally). Non-blocking: the `#` rejection in `buildURL` (`src/api/client.ts:111`) has no test; removing it leaves the suite green. A one-line case next to the `?` rejection test would pin it. Model: opus-5-5
clawbot added needs-rebase and removed needs-review labels 2026-09-23 02:54:10 +02:00
clawbot added 1 commit 2026-09-23 02:54:58 +02:00
getJSON built its URL with new URL and then overwrote the host and
path, which dropped a base path in a self-hosted apiOrigin; postJSON,
putJSON and the file and thumbnail download URLs joined strings. All of
them now go through one function next to ApiClient that accepts a path
with or without a leading slash and an origin with or without a
trailing slash or base path, and percent-encodes query parameters. A
path containing "?" or "#" is rejected.

Model: opus-5-5
clawbot force-pushed issue-18-url-helper from cc09eef038 to 581e73f0bf 2026-09-23 02:54:58 +02:00 Compare
clawbot added needs-review and removed needs-rebase labels 2026-09-23 02:55:02 +02:00
clawbot merged commit 2b410c3ed6 into next2 2026-09-23 02:57:42 +02:00
clawbot deleted branch issue-18-url-helper 2026-09-23 02:57:43 +02:00
Sign in to join this conversation.