增加更多分辨率图像的拉取

This commit is contained in:
2026-01-27 15:34:38 +08:00
parent 9c2a5d5cd8
commit d757dbd39d
16 changed files with 587 additions and 97 deletions

View File

@@ -86,12 +86,29 @@ func GetImageByDate(date string) (*model.Image, error) {
return &img, err
}
func GetImageList(limit int) ([]model.Image, error) {
func GetImageList(limit int, offset int, month string) ([]model.Image, error) {
var images []model.Image
db := repo.DB.Order("date desc").Preload("Variants")
if limit > 0 {
db = db.Limit(limit)
tx := repo.DB.Model(&model.Image{})
if month != "" {
// 增强过滤:确保只处理 YYYY-MM 格式,防止注入或非法字符
// 这里简单处理:只要不为空就增加 LIKE 过滤
util.Logger.Debug("Filtering images by month", zap.String("month", month))
tx = tx.Where("date LIKE ?", month+"%")
}
tx = tx.Order("date desc").Preload("Variants")
if limit > 0 {
tx = tx.Limit(limit)
}
if offset > 0 {
tx = tx.Offset(offset)
}
err := tx.Find(&images).Error
if err != nil {
util.Logger.Error("Failed to get image list", zap.Error(err), zap.String("month", month))
}
err := db.Find(&images).Error
return images, err
}