File size: 5,827 Bytes
2b5389d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | # D04 - API对接规范
## 通用约定
### 请求
- 前端请求前缀: `/api` → Nuxt server proxy → BinV API
- 所有 User 请求路径: `/api/user/*`
- Content-Type: `application/json`
- 分页: `page` (1-indexed) + `page_size` (default=20, max=100)
### 响应格式
```typescript
interface ApiResponse<T = any> {
code: number;
msg: string;
data: T;
}
interface PaginatedData<T> {
list: T[];
total: number;
page: number;
page_size: number;
}
```
### 错误码
| 范围 | 说明 |
|---|---|
| 0 | 成功 |
| 40001-40099 | 鉴权错误(登录失败、token过期) |
| 40100-40199 | 参数校验错误 |
| 40200-40299 | 业务逻辑错误 |
| 50000-50099 | 服务器内部错误 |
### 鉴权
| 端 | 方式 | Header |
|---|---|---|
| 公开接口 | 无需 | - |
| 需登录接口 | JWT | `Authorization: Bearer {user_jwt}` |
---
## API接口清单
### 用户鉴权 — /user/auth
| 方法 | 路径 | 说明 | 需登录 |
|---|---|---|---|
| POST | /user/auth/register | 注册 | ❌ |
| POST | /user/auth/login | 登录 | ❌ |
| GET | /user/auth/profile | 获取用户信息 | ✅ |
### 影片浏览 — /user/vod
| 方法 | 路径 | 说明 | 需登录 |
|---|---|---|---|
| GET | /user/vod | 影片列表 | ❌ |
| GET | /user/vod/search | 搜索 | ❌ |
| GET | /user/vod/{id} | 详情+播放源 | ❌ |
| GET | /user/vod/recommended | 推荐列表 | ❌ |
| GET | /user/vod/latest | 最新更新 | ❌ |
### 分类 — /user/category
| 方法 | 路径 | 说明 | 需登录 |
|---|---|---|---|
| GET | /user/category | 分类树 | ❌ |
### 收藏 — /user/favorite
| 方法 | 路径 | 说明 | 需登录 |
|---|---|---|---|
| GET | /user/favorite | 收藏列表 | ✅ |
| POST | /user/favorite | 添加收藏 | ✅ |
| DELETE | /user/favorite/{vod_id} | 取消收藏 | ✅ |
### 播放历史 — /user/history
| 方法 | 路径 | 说明 | 需登录 |
|---|---|---|---|
| GET | /user/history | 历史列表 | ✅ |
| POST | /user/history | 记录/更新 | ✅ |
| DELETE | /user/history/{id} | 删除 | ✅ |
---
## 前端类型定义
### 用户
```typescript
interface UserLoginParams {
username: string;
password: string;
}
interface UserRegisterParams {
username: string;
password: string;
email?: string;
}
interface LoginResult {
token: string;
expires_in: number;
user: UserInfo;
}
interface UserInfo {
id: number;
username: string;
email: string | null;
nickname: string | null;
avatar: string | null;
favorite_count: number;
created_at: string;
}
```
### 影片
```typescript
interface VodUserItem {
id: number;
name: string;
sub_name: string | null;
category_id: number;
category_name: string;
cover: string | null;
actor: string | null;
director: string | null;
area: string | null;
lang: string | null;
year: string | null;
score: number | null;
remarks: string | null;
is_end: boolean;
source_count: number;
updated_at: string;
}
interface VodUserDetail extends VodUserItem {
duration: string | null;
blurb: string | null;
content: string | null;
view_count: number;
sources: VodPlaySource[];
}
interface VodPlaySource {
source_id: number;
source_name: string;
source_code: string;
play_from: string;
play_from_label: string;
episodes: EpisodeItem[];
}
interface EpisodeItem {
name: string;
url: string;
parse_url: string | null;
}
interface VodListParams {
category_id?: number;
area?: string;
lang?: string;
year?: string;
sort?: 'updated_at' | 'view_count' | 'score' | 'created_at';
order?: 'desc' | 'asc';
page?: number;
page_size?: number;
}
interface VodSearchParams {
keyword: string;
category_id?: number;
page?: number;
page_size?: number;
}
interface VodLatestParams {
hours?: number;
page?: number;
page_size?: number;
}
```
### 分类
```typescript
interface CategoryUserNode {
id: number;
name: string;
children: CategoryUserNode[] | null;
}
```
### 收藏
```typescript
interface FavoriteListResult {
list: VodUserItem[];
total: number;
}
interface FavoriteAddParams {
vod_id: number;
}
```
### 播放历史
```typescript
interface HistoryItem {
id: number;
vod_id: number;
vod_name: string;
vod_cover: string | null;
source_name: string;
episode: string | null;
progress: number;
duration: number;
updated_at: string;
}
interface HistoryRecordParams {
vod_id: number;
source_id: number;
episode?: string;
play_url: string;
progress?: number;
duration?: number;
}
```
---
## 页面 × API 调用映射
| 页面 | SSR/CSR | API 调用 |
|---|---|---|
| 首页 | SSR | `GET /user/vod/recommended` + `GET /user/vod/latest` + `GET /user/category` |
| 分类列表 | SSR | `GET /user/vod?category_id=X` + `GET /user/category` |
| 搜索 | CSR | `GET /user/vod/search?keyword=X` |
| 影片详情 | SSR | `GET /user/vod/{id}` |
| 登录 | CSR | `POST /user/auth/login` |
| 注册 | CSR | `POST /user/auth/register` |
| 收藏 | CSR | `GET /user/favorite` |
| 历史 | CSR | `GET /user/history` |
---
## Nuxt Server Proxy 配置
```typescript
// server/api/[...].ts
import { defineEventHandler, proxyRequest } from 'h3';
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig();
const path = event.path.replace(/^\/api/, '');
const target = `${config.apiBaseUrl}${path}`;
return proxyRequest(event, target);
});
```
### 环境变量
```bash
# .env
NUXT_PUBLIC_API_BASE=/api # 前端请求前缀
NUXT_API_BASE_URL=http://localhost:9999 # Server proxy 目标
```
### nuxt.config.ts
```typescript
export default defineNuxtConfig({
runtimeConfig: {
apiBaseUrl: process.env.NUXT_API_BASE_URL || 'http://localhost:9999',
public: {
apiBase: process.env.NUXT_PUBLIC_API_BASE || '/api',
},
},
});
```
|