feat(file): restrict preview to images and videos

- generate size-aware thumbnails (32-512px) with single-flight and atomic writes
- add optional v parameter for immutable browser caching
- serve PNG for PNG/GIF sources and JPEG otherwise
- drop PDF, text and WebP from preview support
This commit is contained in:
Timi
2026-11-25 20:05:28 +08:00
parent 62a2bbfe44
commit 02193b2ad1
8 changed files with 382 additions and 68 deletions
+9
View File
@@ -205,6 +205,15 @@ Accept-Language: zh-CN
具体哪些接口属于二进制响应,以 OpenAPI 中定义的响应 `Content-Type` 为准。
#### 缩略图预览
`GET /system/file/preview/{path}` 仅支持图片和视频,其他类型返回 `400`。图片和视频统一返回缩略图:
- `size`:缩略图最大边长(像素),范围 `32-512`,默认 `256`
- `v`:缓存版本号,建议传文件列表返回的 `etag`;传入后响应使用一年强缓存,不传时缓存一天
- 响应 `Content-Type` 为 `image/jpeg` 或 `image/png`;PNG/GIF 源图使用 PNG,其余使用 JPEG
- 支持 `If-None-Match` 条件请求,`ETag` 已包含缩略图尺寸和算法版本
### 3.2 SSE
部分长任务接口使用 `text/event-stream`,不经过 `TimiResponse`。事件类型如下: