fix: serve local avatar assets from server#7
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds server-side static resource handling so character avatar images can be served from a local filesystem directory (e.g., a Docker-mounted volume) instead of only relying on external storage URLs.
Changes:
- Add a Spring MVC
ResourceHandlermapping/static/avatar/**to a configurable local directory. - Introduce
vocata.static.character-avatar-pathconfiguration (env-overridable). - Mount
./data/imginto the server container at/app/data/img(read-only) for local avatar assets. - Add a Mockito MockMaker extension configuration for tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
vocata-server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker |
Forces Mockito mock maker to subclass for tests. |
vocata-server/src/main/resources/application.yml |
Adds vocata.static.character-avatar-path config key. |
vocata-server/src/main/java/com/vocata/config/WebMvcConfig.java |
Registers /static/avatar/** -> filesystem resource handler. |
docker-compose.yml |
Mounts local avatar directory into the container. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Value("${vocata.static.character-avatar-path:file:/app/data/img/}") | ||
| private String characterAvatarPath; |
There was a problem hiding this comment.
character-avatar-path 的默认值在 application.yml 和这里的 @Value(...:file:/app/data/img/) 中重复维护,后续改路径时容易发生漂移。建议只保留一处默认值(更推荐在配置文件里),并让代码只读取必填属性。
| registry.addResourceHandler("/static/avatar/**") | ||
| .addResourceLocations(ensureTrailingSlash(characterAvatarPath)) | ||
| .setCachePeriod(3600); |
There was a problem hiding this comment.
这里直接把配置值传给 addResourceLocations(...),如果运维把环境变量配置成常见的“裸路径”(例如 /app/data/img) 而不是带 file: scheme 的形式,Spring 会把它当作非文件 URL 资源位置,导致静态资源无法被正确解析。建议在进入 addResourceLocations 前对路径做规范化(必要时补全 file: 前缀)并对空字符串等异常配置做显式失败处理,避免意外暴露错误目录。
| @@ -0,0 +1 @@ | |||
| mock-maker-subclass | |||
There was a problem hiding this comment.
该文件显式指定 mock-maker-subclass,但当前 pom 仅引入 spring-boot-starter-test(默认就是 subclass mock maker),因此这份配置看起来是冗余的;同时它会阻止未来使用 Mockito inline 能力(例如 mock final/static)。建议删除该文件,或在测试文档/注释中说明为何需要强制使用 subclass。
| volumes: | ||
| - ./vocata-server/logs:/app/logs | ||
| - ./data/img:/app/data/img:ro | ||
| healthcheck: |
There was a problem hiding this comment.
PR 描述仍是模板占位内容,未说明本次“本地头像静态资源由服务端提供”的具体实现方式(资源路径、配置项、docker volume 等)以及实际验证步骤。建议更新 PR description,便于评审与回归。
📌 变更内容
✅ 测试验证
PR 提交规范提醒: