Fix #116: Size parameter in avatar URLs does not affect image resolution #130

Open
typosaurus wants to merge 1 commits from typosaurus/ticket-116 into master
Collaborator

Resolves #116.

Plan

Implementation Plan

Objective: Fix the size parameter for SVG avatar endpoints so that the returned SVG respects the requested pixel dimensions.

Changes Required

  1. Modify generate_avatar_svg() in devplacepy/avatar.py

    • Add a size: int parameter to the function signature.
    • Include width="{size}" and height="{size}" attributes on the root <svg> element.
    • Keep viewBox="0 0 100 100" unchanged so the interior grid scales proportionally.
  2. Update the SVG route handler (likely devplacepy/routers/avatar.py)

    • Clamp the size parameter to the range [16, 512] (matching the devRant PNG endpoint).
    • Pass size to generate_avatar_svg().
    • Change the cache key from bare seed to f"{seed}:{size}" for both lookup and storage.
    • Ensure the ETag header already uses f"{seed}:{size}" (confirmed correct; may double-check).
  3. Add/update test coverage

    • In tests/api/avatar.py, after asserting status 200 and content‑type, verify that the response body contains width="{requested_size}" and height="{requested_size}" when ?size= is provided.
    • Add a new test that requests the same seed with two distinct size values and asserts that the bodies are not identical (or that ETag values differ).
    • Ensure the existing test for avatar_url() still passes (it only checks URL generation, not the wire response).
  4. Run project verification commands

    • pip install -e '.[dev]' -q && make test-unit
    • pip install -q ruff && ruff check .

Definition of Done

  • generate_avatar_svg(seed, size) is modified to accept size and produce an <svg> with width="<size>" and height="<size>".
  • The SVG route clamps size (16–512) and passes it to generate_avatar_svg().
  • Cache key in the SVG route is "{seed}:{size}" (not bare seed).
  • New tests confirm that the SVG response contains the correct width/height for a given size, and that different sizes produce distinct responses.
  • All existing tests pass when running make test-unit.
  • ruff check . reports zero errors.
  • Manual spot‑check: requesting /avatars/u/test.svg?size=32 returns SVG with width="32" height="32"; same seed with ?size=128 returns SVG with those different dimensions and a different ETag.

Opened automatically by Typosaurus.

Resolves #116. ## Plan ## Implementation Plan **Objective:** Fix the `size` parameter for SVG avatar endpoints so that the returned SVG respects the requested pixel dimensions. ### Changes Required 1. **Modify `generate_avatar_svg()` in `devplacepy/avatar.py`** - Add a `size: int` parameter to the function signature. - Include `width="{size}"` and `height="{size}"` attributes on the root `<svg>` element. - Keep `viewBox="0 0 100 100"` unchanged so the interior grid scales proportionally. 2. **Update the SVG route handler** (likely `devplacepy/routers/avatar.py`) - Clamp the `size` parameter to the range `[16, 512]` (matching the devRant PNG endpoint). - Pass `size` to `generate_avatar_svg()`. - Change the cache key from bare `seed` to `f"{seed}:{size}"` for both lookup and storage. - Ensure the `ETag` header already uses `f"{seed}:{size}"` (confirmed correct; may double-check). 3. **Add/update test coverage** - In `tests/api/avatar.py`, after asserting status 200 and content‑type, verify that the response body contains `width="{requested_size}"` and `height="{requested_size}"` when `?size=` is provided. - Add a new test that requests the same `seed` with two distinct `size` values and asserts that the bodies are not identical (or that `ETag` values differ). - Ensure the existing test for `avatar_url()` still passes (it only checks URL generation, not the wire response). 4. **Run project verification commands** - `pip install -e '.[dev]' -q && make test-unit` - `pip install -q ruff && ruff check .` --- ## Definition of Done - [ ] `generate_avatar_svg(seed, size)` is modified to accept `size` and produce an `<svg>` with `width="<size>"` and `height="<size>"`. - [ ] The SVG route clamps `size` (16–512) and passes it to `generate_avatar_svg()`. - [ ] Cache key in the SVG route is `"{seed}:{size}"` (not bare `seed`). - [ ] New tests confirm that the SVG response contains the correct `width`/`height` for a given `size`, and that different sizes produce distinct responses. - [ ] All existing tests pass when running `make test-unit`. - [ ] `ruff check .` reports zero errors. - [ ] Manual spot‑check: requesting `/avatars/u/test.svg?size=32` returns SVG with `width="32" height="32"`; same seed with `?size=128` returns SVG with those different dimensions and a different `ETag`. Opened automatically by Typosaurus.
typosaurus added 1 commit 2026-07-23 05:27:48 +02:00
ticket #116 attempt 1
Some checks failed
DevPlace CI / test (pull_request) Failing after 11s
6392e84917
Some checks failed
DevPlace CI / test (pull_request) Failing after 11s
This pull request has changes conflicting with the target branch.
  • .dpc/verify_cache.json

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin typosaurus/ticket-116:typosaurus/ticket-116
git checkout typosaurus/ticket-116
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: retoor/devplacepy#130
No description provided.