Conversation
internal/model/red_envelopes.go
Outdated
| Greeting string `json:"greeting" gorm:"size:100"` | ||
| Status RedEnvelopeStatus `json:"status" gorm:"type:varchar(20);not null"` | ||
| CoverImage string `json:"cover_image,omitempty" gorm:"size:500"` | ||
| HeterotypicImage string `json:"heterotypic_image,omitempty" gorm:"size:500"` |
internal/apps/redenvelope/routers.go
Outdated
| } | ||
|
|
||
| // validateImageURL 验证图片URL的安全性 | ||
| func validateImageURL(url string) error { |
There was a problem hiding this comment.
validateImageURL方法 可以放到 utils里或 logic验证能重复利用放 internal/util 下,routers 只放接口。
There was a problem hiding this comment.
uploads/redenvelope 使用常量里面的,重复的可以定义到公共常量里
… infinite redirect in upload folder
|
@yyg-max 改好了,麻烦佬再看看 owo 现在改成了上传文件时会同时返回URL和ID,前端发红包时只传图片的文件ID,也就不需要 其他的都修改了一下,现在红包表里面只存放ID了,具体URL到Upload表里面找 www |
internal/apps/upload/tasks.go
Outdated
| for _, upload := range unusedUploads { | ||
| totalProcessed++ | ||
|
|
||
| tx := db.DB(ctx).Begin() |
There was a problem hiding this comment.
用 if err := db.DB(c.Request.Context()).Transaction(func(tx *gorm.DB) error {} 吧,比较清晰点
internal/model/uploads.go
Outdated
| MimeType string `json:"mime_type" gorm:"size:100;not null"` // MIME类型 | ||
| Purpose string `json:"purpose" gorm:"size:50;not null;index"` // 用途 (red_envelope_cover, red_envelope_heterotypic) | ||
| Status UploadStatus `json:"status" gorm:"type:varchar(20);not null;index"` // 状态 | ||
| CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;index"` |
There was a problem hiding this comment.
使用了主键索引 Status CreatedAt 索引先不加
internal/apps/upload/routers.go
Outdated
| filename := fmt.Sprintf("%d_%s_%s_%d%s", currentUser.ID, coverType, md5Sum[:8], timestamp, safeExt) | ||
|
|
||
| // 创建上传目录 (使用更安全的权限) | ||
| uploadPath := filepath.Join(UploadDir, time.Now().Format("2006/01")) |
There was a problem hiding this comment.
这个改成年月日了,上面那个猫猫明天再看看 owo
okok w 猫猫想了一下,是不是意思是需要在/admin/task/routers.go,DispatchTask里面允许手动触发这个清理任务?猫猫加一下 owo |
是的,只需要加个任务标识就行了 |
加好了 www y佬再看看 owo |
|
任务没啥问题,再看看上面的问题 |
|
改好了应该,你看看还有没有缺少的 w |
…for cropping and an updated image upload interface.
…handling for red envelope covers.
| FileSize int64 `json:"file_size" gorm:"not null"` // 文件大小(字节) | ||
| MimeType string `json:"mime_type" gorm:"size:100;not null"` // MIME类型 | ||
| Purpose string `json:"purpose" gorm:"size:50;not null;index"` // 用途 (red_envelope_cover, red_envelope_heterotypic) | ||
| Status UploadStatus `json:"status" gorm:"type:varchar(20);not null"` // 状态 |
There was a problem hiding this comment.
这个状态没有必要使用,删除使用单独的DeletedAt字段覆盖
internal/apps/upload/constants.go
Outdated
|
|
||
| const ( | ||
| // 上传目录 | ||
| UploadDir = "uploads/redenvelope" |
There was a problem hiding this comment.
upload 如果是一个通用的模块,上传目录为什么带有 redenvelope 这个路径
internal/apps/upload/constants.go
Outdated
| UploadDir = "uploads/redenvelope" | ||
|
|
||
| // 允许的图片类型 | ||
| AllowedImageTypes = "image/jpeg,image/png,image/jpg,image/webp" |
internal/apps/upload/constants.go
Outdated
| MaxFileSize = 2 * 1024 * 1024 | ||
|
|
||
| // 最大图片尺寸 | ||
| MaxImageWidth = 4096 |
internal/apps/upload/routers.go
Outdated
| ID uint64 `json:"id,string"` | ||
| URL string `json:"url"` | ||
| Filename string `json:"filename,omitempty"` | ||
| Size int64 `json:"size,omitempty"` |
There was a problem hiding this comment.
response需要提供size width height吗?
internal/apps/upload/routers.go
Outdated
| currentUser, _ := util.GetFromContext[*model.User](c, oauth.UserObjKey) | ||
|
|
||
| coverType := c.Query("type") | ||
| purpose, ok := purposeMap[coverType] |
internal/apps/upload/routers.go
Outdated
| return | ||
| } | ||
|
|
||
| // 按 file_url 去重 |
internal/apps/upload/routers.go
Outdated
|
|
||
| response := UploadResponse{ | ||
| ID: recordID, | ||
| URL: urlPath, |
| ) | ||
|
|
||
| // HandleCleanupUnusedUploads 处理清理未使用上传文件的定时任务 | ||
| func HandleCleanupUnusedUploads(ctx context.Context, t *asynq.Task) error { |
There was a problem hiding this comment.
这个前面说了,因为上传和发红包是两个逻辑,如果上传了被当作图床了就不好了 www
internal/apps/redenvelope/routers.go
Outdated
| // RedEnvelopeView 红包视图(包含上传URL) | ||
| type RedEnvelopeView struct { | ||
| model.RedEnvelope | ||
| CoverImageURL string `json:"cover_image_url,omitempty"` |
There was a problem hiding this comment.
不建议后端来拼接,应该是后端提供一个 common api,比如 /f/:id,前端拿到 id直接访问
5bd1305 to
acd59b9
Compare


例行检查
变更内容
红包功能扩展,添加红包封面及异形红包设置。
新增功能
由于考虑到上传图片和引用是分开的操作,为避免服务器被当作图床使用,对于红包未引用的图片,添加了对应的cron计划任务,这些图片会在2h后自动删除。
变更原因
红包功能完善。