|
|
5 月之前 | |
|---|---|---|
| script | 5 月之前 | |
| src | 5 月之前 | |
| .gitignore | 5 月之前 | |
| API-USAGE.md | 5 月之前 | |
| ENVIRONMENT-CONFIG.md | 5 月之前 | |
| README.md | 5 月之前 | |
| pom.xml | 5 月之前 |
基于 Kotlin + Solon Boot + Thumbnailator 的高性能缩略图生成服务。
# 使用启动脚本(推荐)
start-dev.bat
# 或者使用 Maven 命令
mvn clean compile
mvn exec:java -Dexec.mainClass="com.yujin.thumbnail.ThumbnailApplicationKt" -Dspring.profiles.active=dev
# 使用启动脚本
start-test.bat
# 或者使用 Maven 命令
mvn exec:java -Dexec.mainClass="com.yujin.thumbnail.ThumbnailApplicationKt" -Dspring.profiles.active=test
# 使用启动脚本
start-prod.bat
# 或者使用 Maven 命令
mvn exec:java -Dexec.mainClass="com.yujin.thumbnail.ThumbnailApplicationKt" -Dspring.profiles.active=prod
项目支持多环境配置,使用YAML格式:
application.yml - 主配置文件application-dev.yml - 开发环境配置application-test.yml - 测试环境配置application-prod.yml - 生产环境配置详细配置说明请参考:环境配置文档
接口: GET /api/thumbnail/generate
参数:
path: 相对文件路径 (必需)w: 目标宽度,默认 200pxh: 目标高度,默认 200px响应: 返回生成的缩略图文件 (JPG格式)
功能特性:
原文件名_w_h.jpg示例:
# 生成 300x300 的缩略图
curl "http://localhost:8080/api/thumbnail/generate?path=photos/sunset.jpg&w=300&h=300" \
--output thumbnail_300_300.jpg
接口: POST /api/thumbnail/batch
参数:
file: 上传的图片文件 (form-data)请求体 (JSON):
{
"sizes": [
{"width": 100, "height": 100},
{"width": 200, "height": 200},
{"width": 300, "height": 300}
],
"quality": 0.8,
"format": "jpg"
}
响应: 返回包含所有尺寸缩略图的 ZIP 文件
接口: GET /api/thumbnail/formats
响应:
{
"success": true,
"message": "获取支持格式成功",
"data": ["jpg", "jpeg", "png", "webp"],
"timestamp": 1699123456789
}
接口: GET /api/thumbnail/health
响应:
{
"success": true,
"message": "服务正常运行",
"data": "OK",
"timestamp": 1699123456789
}
项目使用YAML格式的配置文件,支持多环境配置。
application.ymlspring:
profiles:
active: dev # 默认激活开发环境
server:
host: 0.0.0.0
# 通用配置...
application-dev.yml)D:/dev/images/application-test.yml)/app/test/images/application-prod.yml)/data/images/src/main/kotlin/com/yujin/thumbnail/
├── ThumbnailApplication.kt # 主应用程序类
├── controller/
│ └── ThumbnailController.kt # REST 控制器
├── service/
│ └── ThumbnailService.kt # 缩略图生成服务
├── dto/
│ └── ThumbnailDto.kt # 数据传输对象
└── config/
└── GlobalExceptionHandler.kt # 全局异常处理器
src/main/resources/
├── application.properties # 配置文件
└── static/
└── index.html # 测试页面
所有 API 接口都包含统一的错误处理:
{
"success": false,
"message": "错误信息",
"data": null,
"timestamp": 1699123456789
}
常见错误类型:
可以考虑添加的功能:
MIT License