图片上传、管理、互动等接口。
POST /api/photos/upload
Authorization: Bearer {token}
Content-Type: multipart/form-data
| 参数 | 类型 | 必填 | 说明 |
|---|
| file | file | 是 | 图片文件 |
| title | string | 否 | 标题 |
| description | string | 否 | 描述 |
| album_id | int | 否 | 相册ID |
| tags | string | 否 | 标签,逗号分隔 |
| is_public | int | 否 | 是否公开:1公开 0私密 |
{
"code": 0,
"message": "上传成功",
"data": {
"id": 123,
"title": "风景照",
"path": "/storage/photos/2025/01/abc123.jpg",
"thumb": "/storage/photos/2025/01/abc123_thumb.jpg",
"width": 1920,
"height": 1080,
"size": 1024000
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|
| page | int | 否 | 页码,默认1 |
| limit | int | 否 | 每页数量,默认20 |
| sort | string | 否 | 排序字段 |
| order | string | 否 | 排序方向 |
| album_id | int | 否 | 相册ID |
| tag | string | 否 | 标签 |
| keyword | string | 否 | 搜索关键词 |
{
"code": 0,
"data": {
"list": [
{
"id": 123,
"title": "风景照",
"thumb": "/storage/photos/2025/01/abc123_thumb.jpg",
"views": 100,
"likes": 50,
"favorites": 20,
"user": {
"id": 1,
"username": "user123",
"avatar": "/storage/avatars/1.jpg"
},
"create_time": "2025-01-18 10:00:00"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 100,
"pages": 5
}
}
}
{
"code": 0,
"data": {
"id": 123,
"title": "风景照",
"description": "美丽的风景",
"path": "/storage/photos/2025/01/abc123.jpg",
"thumb": "/storage/photos/2025/01/abc123_thumb.jpg",
"width": 1920,
"height": 1080,
"size": 1024000,
"views": 100,
"likes": 50,
"favorites": 20,
"downloads": 10,
"is_liked": false,
"is_favorited": false,
"tags": ["风景", "自然"],
"exif": {
"camera": "Canon EOS R5",
"aperture": "f/2.8",
"shutter": "1/1000",
"iso": 100
},
"user": {
"id": 1,
"username": "user123",
"nickname": "摄影师",
"avatar": "/storage/avatars/1.jpg"
},
"album": {
"id": 1,
"name": "风景集"
},
"create_time": "2025-01-18 10:00:00"
}
}
PUT /api/photos/{id}
Authorization: Bearer {token}
Content-Type: application/json
| 参数 | 类型 | 必填 | 说明 |
|---|
| title | string | 否 | 标题 |
| description | string | 否 | 描述 |
| album_id | int | 否 | 相册ID |
| tags | array | 否 | 标签数组 |
| is_public | int | 否 | 是否公开 |
{
"code": 0,
"message": "更新成功"
}
DELETE /api/photos/{id}
Authorization: Bearer {token}
{
"code": 0,
"message": "删除成功"
}
POST /api/photos/{id}/like
Authorization: Bearer {token}
{
"code": 0,
"message": "点赞成功",
"data": {
"is_liked": true,
"likes": 51
}
}
POST /api/photos/{id}/favorite
Authorization: Bearer {token}
{
"code": 0,
"message": "收藏成功",
"data": {
"is_favorited": true,
"favorites": 21
}
}
GET /api/photos/{id}/download
Authorization: Bearer {token}
返回图片文件流。
POST /api/photos/{id}/edit
Authorization: Bearer {token}
Content-Type: application/json
| 参数 | 类型 | 必填 | 说明 |
|---|
| action | string | 是 | 操作类型 |
| params | object | 是 | 操作参数 |
| action | 说明 | params |
|---|
| crop | 裁剪 | {x, y, width, height} |
| rotate | 旋转 | {angle: 90/180/270} |
| flip | 翻转 | {direction: h/v} |
| resize | 调整大小 | {width, height} |
| filter | 滤镜 | {type, value} |
{
"action": "crop",
"params": {
"x": 100,
"y": 100,
"width": 800,
"height": 600
}
}
{
"code": 0,
"message": "编辑成功",
"data": {
"path": "/storage/photos/2025/01/abc123_edited.jpg"
}
}
POST /api/photos/{id}/share
Authorization: Bearer {token}
Content-Type: application/json
| 参数 | 类型 | 必填 | 说明 |
|---|
| type | string | 是 | link/qrcode |
| expires | int | 否 | 有效期(天) |
| password | string | 否 | 访问密码 |
{
"code": 0,
"data": {
"url": "https://example.com/s/abc123",
"qrcode": "data:image/png;base64,..."
}
}
| code | 说明 |
|---|
| 20001 | 文件格式不支持 |
| 20002 | 文件大小超出限制 |
| 20003 | 图片不存在 |
| 20004 | 无权操作此图片 |