Task 21: avatar widget and image cache (#21) #45
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "task/21-ui-avatar-image-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What this builds
fluxer-core::media_urls(pure):avatar_url(&Endpoints, &UserPartial, size) -> AvatarSource { Url(Url) | Default(u8) }andguild_icon_url(&Endpoints, &Guild, size) -> Option<Url>, ported from the fork'sAvatarUtils.tsandMediaProxyUtils.ts:{media}/avatars/{id}/{hash}.webp?size={snapped}through a port ofbuildMediaProxyURL, the 33-step size ladder,snapIconImageSize(clamped to 128..1024), andgetDefaultAvatarIndex(id % 6). An empty or unparseable media endpoint falls back to the default avatar /Noneinstead of panicking.fluxer-ui::images: theImageLoadertrait (fn load(&self, Url) -> BoxFuture<'static, Result<RgbaImage, ImageError>>) andImages, the per-URL state (requestreturns aniced::Task,update,get). Each URL is loaded once.fluxer-ui::widgets::avatar:avatar::view(source, size, presence: Option<UserStatus>)with a circle clip (Image::border_radius), the six default avatars copied from the web app intoassets/avatars/, and a presence dot placed with the web app'sAvatarStatusGeometrytable and coloured from the--status-*tokens.avatar::request/avatar::resolveconnect a coreAvatarSourcetoImages.fluxer-platform::images::ImageCache:ImageCache::new(cache_dir, max_mem_bytes),async fn get(&self, &Url) -> Result<RgbaImage, ImageCacheError>: memory (LRU by decoded bytes, 64 MiB default), thencache_dir/images/<sha256 of URL>, then reqwest. Decodes PNG, JPEG, GIF, WebP with theimagecrate. ImplementsImageLoader;loadspawns onto the tokio runtime the cache was created on, because iced polls tasks on its own executor.crates/fluxer-ui/README.mdandCLAUDE.md; READMEs of the three crates are updated.Stacked on: task/16-ui-theme-fonts-icons, task/8-core-store-session
How it was tested
crates/fluxer-core/tests/media_urls.rs(9 tests):avatar_url_matches_web_app_for_known_hash,default_avatar_index_matches, size snapping, animated hashes requested static, guild icons,buildMediaProxyURLparameter order, unusable media endpoints.crates/fluxer-platform/tests/images.rs(10 tests, wiremock):image_cache_hits_disk_after_first_fetch(server expects exactly one request; the second read uses a fresh cache on the same directory), memory hit, LRU eviction, WebP decode, non-image body, HTTP 404, corrupt disk entry refetched, non-HTTP scheme, unwritable cache directory,ImageLoader::loadpolled from a thread with no tokio context.fluxer-uiforImages(load once, failure remembered, forgotten URL ignored) and the avatar widget (default avatars decode, status geometry table and interpolation, token colours, view builds for odd sizes).cargo xtask ciis green locally on the merged base and on this branch (screenshot step skipped locally, as on the base).Deviations from the plan
avatar_url_matches_web_app_for_known_hashwas derived by tracing the TypeScript by hand (device pixel ratio 1), not by executing it: the function needs the web app's bundler aliases and runtime config to run. Worth a second pair of eyes against the real client.ImageCache::newtakes the cache directory (impl AsRef<Path>) rather than apathsvalue:fluxer-platformhas no paths type yet (Task 12).fluxer_ui::images::ImageError(cloneable, for iced messages) andfluxer_platform::images::ImageCacheError.crates/fluxer-ui/src/images.rs(the loader trait and image state are not avatar-specific),crates/fluxer-ui/src/widgets/mod.rs,crates/fluxer-ui/assets/avatars/.avatar::view'ssourceis a UI-sideavatar::Source { Image(Handle) | Default(u8) | Placeholder }, produced byavatar::resolve(&images, &AvatarSource). A remote avatar shows a plain disc until it is loaded.viewassumes--background-secondary,view_ontakes the colour). Idle/DND are plain coloured dots, not the web app's moon and bar shapes.image0.25 (no default features; png, jpeg, gif, webp) andsha20.11 in the workspace, and iced'simage-without-codecsfeature.fluxer-platformnow depends onfluxer-ui(as the plan's interface requires), which pulls iced into it.Imageskeeps every loaded handle for its lifetime (no eviction in the UI tier); fine for avatars and icons, to revisit when attachments arrive.Closes #21
🤖 Generated with Claude Code
Independent review: Task 21 (avatar widget and image cache), commit
5c961c3Scope:
git diff 00f9dee..origin/task/21-ui-avatar-image-cache.Checks
avatar_url_matches_web_app_for_known_hashexpectshttps://fluxer.forked.io/media/avatars/1533494601170563073/a1b2c3d4e5f60718.webp?size=128;default_avatar_index_matchescoversid % 6;image_cache_hits_disk_after_first_fetchuses a wiremockexpect(1)with a second, freshImageCache, so the second read can only come from disk.avatar_url(&Endpoints, &UserPartial, u16) -> AvatarSource { Url(Url) | Default(u8) },guild_icon_url,ImageCache::new,ImageCache::get,ImageLoader::load(&self, Url) -> BoxFuture<'static, Result<RgbaImage, _>>are present. Deviations are listed below; no other task's Interfaces block in the plan names these symbols.fluxer-coregains no banned dependency (the xtask core-isolation step passes);fluxer-uidoes no I/O beyondImageLoaderviaTask::perform, recorded inCLAUDE.mdand the crate README; body size, decoded size and allocation are capped and nothing in the server-data paths panics; no tokens in code or fixtures, and the image client sends no auth header.cargo xtask ciin the review worktree: green (fmt, clippy, deny, core isolation, tests; the screenshot step is skipped becauseFLUXER_SCREENSHOT_TESTSis not 1).I compared the port line by line with the fork:
AvatarUtils.ts(getUserAvatarURL,getGuildIconURL,getDefaultAvatarIndex,snapImageSizeWithinServerRange, icon range 128..1024),MediaProxyUtils.ts(snapMediaProxyImageSize,appendMediaProxyParamsparameter order,animatedremoval, svg/data/blob bypass), the 33-rung size ladder, and theAvatarStatusGeometry.tsdesktop table. All match. The six default avatar PNGs are byte-identical to the fork's.Findings
crates/fluxer-core/tests/media_urls.rs: the expected URL was hand-traced, not produced by running the TS function as Step 1 asks. My own trace ofgetUserAvatarURL→getMediaURL→setPathQueryParams→buildMediaProxyURLat DPR 1 gives the same string, so the value is right; the plan step is just not followed literally.crates/fluxer-platform/src/images.rs:ImageCache::new(cache_dir: impl AsRef<Path>, max_mem_bytes)instead of the plan'snew(paths, ...), andgetreturnsResult<RgbaImage, ImageCacheError>. Reasonable while there is no paths type (Task 12); Task 14 must pass the cache dir itself.crates/fluxer-ui/src/widgets/avatar.rs:avatar::viewtakes the UI-sideavatar::Source(viaavatar::resolve(&images, &AvatarSource)), not the coreAvatarSource. Tasks 18 and 20 need therequest/resolve/viewtrio; it is documented in the README.crates/fluxer-platform/Cargo.toml:fluxer-platformnow depends onfluxer-ui, so every consumer of the platform crate (Task 12 store, Task 23 notifications) compiles iced. It follows from the plan's "trait in ui, impl in platform", but a small trait-only crate or a feature gate would avoid it. Worth a follow-up issue.crates/fluxer-platform/src/images.rs:ImageLoader::loadneeds the tokioHandlecaptured inImageCache::new; a cache built outside a runtime fails every load with "no tokio runtime" (an error, not a panic). Task 14 must construct it inside the runtime. Also, two concurrentgets for the same URL both hit the network (the UI'sImagesdedups per URL, so this only matters for direct callers), and a memory hit clones the full pixel buffer.crates/fluxer-ui/src/images.rs:Imagesnever evicts handles and a failed load stays failed untilforget, so a transient network error leaves a placeholder for the session. No follow-up issue was opened; one should be before attachments or emoji use this path.crates/fluxer-ui/src/widgets/avatar.rs: the presence dot is a backdrop-coloured ring plus a plain dot rather than the web app's mask cutout, with no idle/dnd glyphs, andguild_icon_urltakes a size where the web app always asks for 160. No side-by-side screenshots are attached (nothing renders the widget yet); they are owed with Tasks 17/24.Verdict: APPROVE (0 blocking, 7 minor; local
cargo xtask cigreen).