spark-server/docs/media.md

43 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 媒体压缩与检测
> App 端主压缩;服务端对用户路径做检测,对机器人路径强制压缩后写对象存储。
## 规格(与 App 对齐)
| 类型 | 最长边 | 体积参考 |
|------|--------|----------|
| 普通图片(广场/朋友圈等) | ≤ **1080** | ≤ 10 MiB |
| 视频 | ≤ **720** | ≤ 100 MiB |
| 头像 | ≤ **200×200** | ≤ 2 MiB |
## 检测点(用户上传)
| 时机 | 位置 | 行为 |
|------|------|------|
| 申请上传凭证 | `upload/logic.CreateCredential` → `checkDeclaredSize` | 按 `purpose` 校验声明 `size`;超限默认 **打 Warn 日志**,`media.user_reject=true` 时返回 `40005` |
| 广场发帖 | `square/logic.publish` → `checkMediaMeta` | 用客户端声明的图/视频宽高与 size 校验;同上 |
| 朋友圈发帖 | `moment/logic.publish` → `checkMediaMeta` | 同上 |
主压缩仍在 **App 上传前**;服务端不把用户文件再压一遍(除非开启拒收)。
## 机器人压缩点
| 时机 | 位置 | 行为 |
|------|------|------|
| RSS 配图 | `squarebot` Tick → `attachMedia` → `FetchImage` → `objectstore.PutLarge` | 下载后压到 ≤1080,再写入 `perm/square/image/` |
| 机器人视频路径 | `PrepareVideoAsset` / `FetchVideo` | ffmpeg 压到 ≤720(部署需 `ffmpeg`) |
| 机器人头像 | `FetchAvatar` / `PrepareBotAvatar` | ≤200×200 |
开关:`media.bot_compress`(默认 true)。关闭时机器人帖仍发文字摘要+链接,不拉配图。
## 配置
见 `configs/config.yaml` 的 `media:` 与 `square_bot:`。
## 部署注意
- 视频压缩依赖主机 **`ffmpeg`**(`media.ffmpeg_path`,默认 `ffmpeg`)。运行镜像 `Dockerfile` 已 `apk add ffmpeg`。
- 迁移:`migrations/0026_square_bot_rss.sql`(`source` / `source_url` / `expires_at` + `t_square_bot_links`)。
- Seed:`go run ./cmd/seed -config configs/config.yaml` 确保 `bot001@spark.bot`… 存在。
- 错误码:`40005` / `media_oversized`(`media.user_reject=true` 时拒凭证或发帖)。