A:完成照片接口对接

This commit is contained in:
jimmy committed 2025-08-21 21:46:43 +08:00
1 parent 5bd1481766
commit 83cdefe5d1
21 files changed
+1393 -403

No files matched your search

+185
View File
@@ -0,0 +1,185 @@
# Argus HTTP API 测试文件
本目录包含了 Argus 照片管理系统的全套 HTTP API 测试文件,按功能模块进行分类。
## 📁 文件结构
```
tests/
├── README.md # 本文档
├── base.http # 基础功能测试(健康检查、环境配置)
├── library.http # 图像库管理测试
├── photo.http # 照片文件和详情接口测试
├── exif.http # EXIF信息查询测试
├── user.http # 用户管理接口测试
└── dev.http # 开发调试接口测试
```
## 🚀 快速开始
### 1. 环境准备
在项目根目录创建 `http-client.env.json` 文件:
```json
{
"dev": {
"baseUrl": "http://localhost:8080",
"sampleHash": "your_actual_hash_here"
},
"prod": {
"baseUrl": "https://your-production-domain.com",
"sampleHash": "production_hash_here"
}
}
```
### 2. 启动服务器
```bash
go run .
```
### 3. 测试顺序
建议按以下顺序执行测试:
1. **基础功能** (`base.http`)
- 健康检查
- API基础路由
2. **图像库管理** (`library.http`)
- 添加图像库路径
- 启用图像库
- 开始索引
- 获取图像hash值
3. **照片接口** (`photo.http`)
- 使用实际hash测试图像访问
- 测试各种缩略图尺寸
- 获取图像详情
4. **EXIF查询** (`exif.http`)
- 查询EXIF信息
- 按相机、参数筛选
- GPS信息查询
5. **用户管理** (`user.http`)
- 用户CRUD操作
- 用户查询和筛选
6. **开发调试** (`dev.http`)
- 系统状态监控
- 性能测试
- 开发工具
## 📝 测试说明
### 变量替换
测试文件中使用了以下变量,需要替换为实际值:
- `{{baseUrl}}`: 服务器地址 (如: http://localhost:8080)
- `{{apiBase}}`: API基础路径 ({{baseUrl}}/api/v1)
- `{{sampleHash}}`: 实际的图像hash值
### 获取实际Hash值
执行 `library.http` 中的图像库索引后,从响应中获取实际的图像hash值,然后替换测试文件中的 `sample_hash_12345`。
### 文件路径注意事项
- Windows: 使用反斜杠 `D:\\Pictures\\sample.jpg` 或正斜杠 `D:/Pictures/sample.jpg`
- Linux/Mac: 使用正斜杠 `/home/user/Pictures/sample.jpg`
- 确保路径中的图像文件真实存在
## 🔧 IDE 配置
### VS Code
安装 `REST Client` 扩展,可以直接在编辑器中执行HTTP请求。
### IntelliJ IDEA / WebStorm
内置HTTP客户端支持,可以直接运行 `.http` 文件。
### 命令行工具
也可以使用 curl 执行测试:
```bash
# 健康检查
curl http://localhost:8080/health
# 获取图像
curl "http://localhost:8080/api/v1/photo/your_hash?format=thumbnail&size=400x400"
# 获取图像详情
curl "http://localhost:8080/api/v1/assets/your_hash"
```
## 📊 响应格式
### 成功响应
```json
{
"code": 200,
"message": "Success",
"data": { ... }
}
```
### 错误响应
```json
{
"code": 404,
"message": "Photo not found",
"error": "详细错误信息"
}
```
### 图像文件响应
图像接口直接返回二进制数据,HTTP头包含正确的 `Content-Type`。
## ⚠️ 注意事项
1. **数据安全**: 测试前备份重要数据
2. **路径检查**: 确保文件路径存在且可访问
3. **性能影响**: 大量并发测试可能影响系统性能
4. **开发接口**: `dev.http` 中的接口仅供开发环境使用
5. **权限要求**: 某些操作可能需要特定权限
## 🐛 常见问题
### 连接失败
- 检查服务器是否启动
- 确认端口号正确
- 检查防火墙设置
### 404 错误
- 确认API路径正确
- 检查图像hash是否有效
- 验证图像文件是否存在
### 缩略图生成失败
- 检查ImageMagick/LibVips安装
- 确认原图文件可读
- 查看系统日志获取详细错误
### EXIF解析失败
- 检查ExifTool安装
- 确认图像文件包含EXIF数据
- 验证文件格式支持
## 📚 相关文档
- [API使用指南](../API_USAGE.md)
- [项目说明](../CLAUDE.md)
- [配置文档](../config.yaml)
+25
View File
@@ -0,0 +1,25 @@
### Argus 照片管理系统 - 基础功能测试
### 服务器地址
@baseUrl = http://localhost:8080
@apiBase = {{baseUrl}}/api/v1
### ===== 健康检查 =====
### 健康检查
GET {{baseUrl}}/health
### API 基础路由
GET {{apiBase}}
### ===== 环境变量示例 =====
### 在http-client.env.json中配置:
### {
### "dev": {
### "baseUrl": "http://localhost:8080",
### "sampleHash": "your_actual_hash_here"
### },
### "prod": {
### "baseUrl": "https://your-production-domain.com",
### "sampleHash": "production_hash_here"
### }
### }
+131
View File
@@ -0,0 +1,131 @@
### Argus 照片管理系统 - 开发和调试接口测试
### 服务器地址
@baseUrl = http://localhost:8080
@apiBase = {{baseUrl}}/api/v1
### ===== 开发工具接口 =====
### 开发工具 - 获取EXIF信息
GET {{baseUrl}}/dev/tool/exiftool/get_exif?imagePath=D:/Pictures/sample.jpg
### 开发工具 - 获取EXIF信息 (Linux路径示例)
GET {{baseUrl}}/dev/tool/exiftool/get_exif?imagePath=/home/user/Pictures/sample.jpg
### 开发工具 - 获取EXIF信息 (相对路径)
GET {{baseUrl}}/dev/tool/exiftool/get_exif?imagePath=./examples/sample.jpg
### ===== 系统状态和调试 =====
### 系统信息
GET {{baseUrl}}/dev/system/info
### 内存使用情况
GET {{baseUrl}}/dev/system/memory
### 数据库连接状态
GET {{baseUrl}}/dev/database/status
### 数据库表信息
GET {{baseUrl}}/dev/database/tables
### 缓存状态
GET {{baseUrl}}/dev/cache/status
### 清理缓存
DELETE {{baseUrl}}/dev/cache/clear
### ===== 日志和监控 =====
### 获取系统日志
GET {{baseUrl}}/dev/logs?level=info&limit=100
### 获取错误日志
GET {{baseUrl}}/dev/logs?level=error&limit=50
### 获取最近的处理任务
GET {{baseUrl}}/dev/tasks/recent
### 获取失败的任务
GET {{baseUrl}}/dev/tasks/failed
### ===== 测试数据生成 =====
### 生成测试用户
POST {{baseUrl}}/dev/test/users
Content-Type: application/json
{
"count": 5
}
### 生成测试图像记录
POST {{baseUrl}}/dev/test/photos
Content-Type: application/json
{
"count": 10,
"with_exif": true
}
### 清理测试数据
DELETE {{baseUrl}}/dev/test/cleanup
### ===== 性能测试 =====
### 数据库性能测试
GET {{baseUrl}}/dev/benchmark/database
### 图像处理性能测试
GET {{baseUrl}}/dev/benchmark/image?size=1920x1080
### EXIF解析性能测试
GET {{baseUrl}}/dev/benchmark/exif
### ===== 配置管理 =====
### 获取当前配置
GET {{baseUrl}}/dev/config
### 重新加载配置
POST {{baseUrl}}/dev/config/reload
### 验证配置
GET {{baseUrl}}/dev/config/validate
### ===== 错误模拟 =====
### 模拟数据库错误
GET {{baseUrl}}/dev/simulate/db_error
### 模拟文件系统错误
GET {{baseUrl}}/dev/simulate/fs_error
### 模拟内存不足
GET {{baseUrl}}/dev/simulate/memory_error
### ===== 安全测试 =====
### 测试文件路径遍历
GET {{baseUrl}}/dev/tool/exiftool/get_exif?imagePath=../../../etc/passwd
### 测试SQL注入 (应该被阻止)
GET {{apiBase}}/exif/search?q='; DROP TABLE users; --
### 测试XSS (应该被转义)
GET {{apiBase}}/exif/search?q=<script>alert('xss')</script>
### ===== 使用说明 =====
###
### 开发接口仅用于开发和调试环境
### 生产环境应该禁用这些接口
###
### 1. 工具接口用于测试ExifTool功能
### 2. 系统接口用于监控应用状态
### 3. 测试数据接口用于快速生成测试环境
### 4. 性能测试接口用于基准测试
### 5. 安全测试用于验证安全措施
###
### 注意:
### - 替换imagePath为实际存在的图像文件路径
### - 测试数据生成会修改数据库
### - 清理操作不可逆,请谨慎使用
+116
View File
@@ -0,0 +1,116 @@
### Argus 照片管理系统 - EXIF信息接口测试
### 服务器地址
@baseUrl = http://localhost:8080
@apiBase = {{baseUrl}}/api/v1
### 注意:需要先运行图像库索引获得实际的hash值
@sampleHash = sample_hash_12345
### ===== EXIF信息基础查询 =====
### 获取所有EXIF记录
GET {{apiBase}}/exif
### 根据hash获取EXIF信息
GET {{apiBase}}/exif/{{sampleHash}}
### 获取EXIF统计信息
GET {{apiBase}}/exif/statistics
### ===== 相机相关查询 =====
### 获取相机列表
GET {{apiBase}}/exif/cameras
### 获取相机统计
GET {{apiBase}}/exif/cameras/stats
### 根据相机品牌筛选
GET {{apiBase}}/exif/camera?make=Canon
### 根据相机型号筛选
GET {{apiBase}}/exif/camera?model=EOS
### 根据相机品牌和型号筛选
GET {{apiBase}}/exif/camera?make=Canon&model=EOS
### ===== 拍摄参数查询 =====
### 根据ISO筛选
GET {{apiBase}}/exif/iso?min=100&max=800
### 根据ISO范围筛选 (高ISO)
GET {{apiBase}}/exif/iso?min=1600&max=6400
### 根据光圈筛选
GET {{apiBase}}/exif/aperture?min=1.4&max=5.6
### 根据光圈筛选 (大光圈)
GET {{apiBase}}/exif/aperture?min=1.0&max=2.8
### 根据焦距筛选
GET {{apiBase}}/exif/focal?min=85&max=200
### ===== GPS和位置信息 =====
### 获取有GPS信息的照片
GET {{apiBase}}/exif/gps
### 根据GPS坐标范围筛选
GET {{apiBase}}/exif/gps?lat_min=39.0&lat_max=40.0&lng_min=116.0&lng_max=117.0
### ===== 搜索功能 =====
### 搜索EXIF信息 (相机品牌)
GET {{apiBase}}/exif/search?q=Canon
### 搜索EXIF信息 (相机型号)
GET {{apiBase}}/exif/search?q=EOS
### 搜索EXIF信息 (镜头信息)
GET {{apiBase}}/exif/search?q=85mm
### ===== 高级筛选 =====
### 组合查询:特定相机+ISO范围
GET {{apiBase}}/exif?make=Canon&model=EOS&iso_min=100&iso_max=400
### 组合查询:光圈+焦距范围
GET {{apiBase}}/exif?aperture_min=2.8&aperture_max=5.6&focal_min=50&focal_max=100
### 组合查询:带GPS的Canon照片
GET {{apiBase}}/exif?make=Canon&has_gps=true
### ===== 分页和排序 =====
### 分页获取EXIF数据
GET {{apiBase}}/exif?page=1&limit=20
### 按拍摄时间排序
GET {{apiBase}}/exif?sort=datetime&order=desc
### 按ISO排序
GET {{apiBase}}/exif?sort=iso&order=asc
### ===== 错误测试 =====
### 测试不存在的hash
GET {{apiBase}}/exif/nonexistent_hash
### 测试无效的ISO范围
GET {{apiBase}}/exif/iso?min=abc&max=xyz
### 测试无效的光圈值
GET {{apiBase}}/exif/aperture?min=-1&max=100
### 测试无效的GPS坐标
GET {{apiBase}}/exif/gps?lat_min=invalid&lng_max=invalid
### ===== 使用说明 =====
###
### 1. 将 {{sampleHash}} 替换为实际的图像hash
### 2. EXIF接口返回JSON格式的详细信息
### 3. 筛选参数可以组合使用
### 4. 支持分页和排序功能
### 5. GPS查询需要照片包含位置信息
### 6. 搜索功能支持模糊匹配
+39
View File
@@ -0,0 +1,39 @@
### Argus 照片管理系统 - 图像库管理测试
### 服务器地址
@baseUrl = http://localhost:8080
@apiBase = {{baseUrl}}/api/v1
### ===== 图像库管理 =====
### 查看当前图像库
GET {{apiBase}}/library
### 添加图像库路径 (需要修改为实际存在的路径)
POST {{apiBase}}/library
Content-Type: application/json
{
"path": "E:/整合/kkimkkimmy/Pic"
}
### 更新图像库状态
PUT {{apiBase}}/library
Content-Type: application/json
{
"path": "E:/整合/kkimkkimmy/Pic",
"is_enable": true
}
### 开始图像索引 (需要先添加图像库)
POST {{apiBase}}/library/indexed
### 删除图像库
DELETE {{apiBase}}/library?path=D:/Pictures
### ===== 使用说明 =====
###
### 1. 首先添加图像库路径,确保路径存在且包含图像文件
### 2. 启用图像库 (is_enable: true)
### 3. 开始索引获得图像hash值
### 4. 使用获得的hash值进行其他接口测试
+74
View File
@@ -0,0 +1,74 @@
### Argus 照片管理系统 - 照片接口测试
### 服务器地址
@baseUrl = http://localhost:8080
@apiBase = {{baseUrl}}/api/v1
### 注意:需要先运行图像库索引获得实际的hash值
@sampleHash = sample_hash_12345
### ===== 照片文件访问测试 =====
### 获取原图
GET {{apiBase}}/photo/{{sampleHash}}?format=original
### 获取默认尺寸缩略图
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail
### 获取指定尺寸缩略图 (400x400)
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail&size=400x400
### 获取指定尺寸缩略图 (800x600)
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail&size=800x600
### 获取正方形缩略图 (500x500)
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail&size=500x500
### 获取小尺寸缩略图 (200x200)
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail&size=200x200
### 获取高分辨率缩略图 (1920x1080)
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail&size=1920x1080
### ===== 照片详情信息测试 =====
### 获取图像详细信息
GET {{apiBase}}/assets/{{sampleHash}}
### ===== 错误测试 =====
### 测试不存在的hash - 图像文件
GET {{apiBase}}/photo/nonexistent_hash
### 测试不存在的hash - 图像详情
GET {{apiBase}}/assets/nonexistent_hash
### 测试无效的格式参数
GET {{apiBase}}/photo/{{sampleHash}}?format=invalid_format
### 测试无效的尺寸参数
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail&size=invalid_size
### 测试负数尺寸
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail&size=-100x-100
### 测试错误的尺寸格式
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail&size=400x
### 测试空尺寸参数
GET {{apiBase}}/photo/{{sampleHash}}?format=thumbnail&size=
### ===== 性能测试示例 =====
### 并发获取缩略图测试 (可以在终端中使用curl并发执行)
# curl "{{apiBase}}/photo/hash1?format=thumbnail&size=400x400" &
# curl "{{apiBase}}/photo/hash2?format=thumbnail&size=400x400" &
# curl "{{apiBase}}/photo/hash3?format=thumbnail&size=400x400" &
### ===== 使用说明 =====
###
### 1. 将 {{sampleHash}} 替换为实际的图像hash
### 2. 图像文件接口会返回二进制图像数据
### 3. 详情接口会返回JSON格式的完整信息
### 4. 错误情况会返回包含错误信息的JSON
### 5. 缩略图生成可能需要一些时间
### 6. API会自动更新图像的访问计数和访问时间
+159
View File
@@ -0,0 +1,159 @@
### Argus 照片管理系统 - 用户管理接口测试
### 服务器地址
@baseUrl = http://localhost:8080
@apiBase = {{baseUrl}}/api/v1
### ===== 用户管理接口测试 =====
### 获取所有用户
GET {{apiBase}}/users
### 获取指定用户
GET {{apiBase}}/users/1
### 创建新用户
POST {{apiBase}}/users
Content-Type: application/json
{
"username": "testuser",
"email": "test@example.com",
"password": "password123",
"age": 25
}
### 创建新用户 (测试用户2)
POST {{apiBase}}/users
Content-Type: application/json
{
"username": "photographer",
"email": "photo@example.com",
"password": "photo123",
"age": 30
}
### 更新用户信息
PUT {{apiBase}}/users/1
Content-Type: application/json
{
"username": "updateduser",
"email": "updated@example.com",
"age": 26
}
### 更新用户密码
PUT {{apiBase}}/users/1
Content-Type: application/json
{
"password": "newpassword123"
}
### 部分更新用户信息
PATCH {{apiBase}}/users/1
Content-Type: application/json
{
"age": 27
}
### 删除用户
DELETE {{apiBase}}/users/1
### ===== 用户验证和认证 =====
### 用户登录 (如果有认证系统)
POST {{apiBase}}/auth/login
Content-Type: application/json
{
"username": "testuser",
"password": "password123"
}
### 用户注册 (如果有认证系统)
POST {{apiBase}}/auth/register
Content-Type: application/json
{
"username": "newuser",
"email": "new@example.com",
"password": "newpass123",
"age": 28
}
### ===== 用户查询和筛选 =====
### 根据用户名搜索
GET {{apiBase}}/users?username=test
### 根据邮箱搜索
GET {{apiBase}}/users?email=example.com
### 分页获取用户
GET {{apiBase}}/users?page=1&limit=10
### 按年龄范围筛选用户
GET {{apiBase}}/users?age_min=20&age_max=40
### 按创建时间排序
GET {{apiBase}}/users?sort=created_at&order=desc
### ===== 错误测试 =====
### 测试获取不存在的用户
GET {{apiBase}}/users/999
### 测试创建用户 - 缺少必需字段
POST {{apiBase}}/users
Content-Type: application/json
{
"username": "incomplete"
}
### 测试创建用户 - 无效邮箱格式
POST {{apiBase}}/users
Content-Type: application/json
{
"username": "testuser2",
"email": "invalid-email",
"password": "password123",
"age": 25
}
### 测试创建用户 - 重复用户名
POST {{apiBase}}/users
Content-Type: application/json
{
"username": "testuser",
"email": "another@example.com",
"password": "password123",
"age": 25
}
### 测试更新不存在的用户
PUT {{apiBase}}/users/999
Content-Type: application/json
{
"username": "nonexistent",
"email": "none@example.com",
"age": 30
}
### 测试删除不存在的用户
DELETE {{apiBase}}/users/999
### ===== 使用说明 =====
###
### 1. 用户管理接口用于管理系统用户
### 2. 创建用户时确保提供所有必需字段
### 3. 邮箱地址需要符合有效格式
### 4. 用户名在系统中应该是唯一的
### 5. 支持分页、搜索和排序功能
### 6. 删除用户操作不可逆,请谨慎使用