增加文本中转功能
This commit is contained in:
@@ -22,7 +22,9 @@ type PickupResponse struct {
|
||||
ExpireType string `json:"expire_type"`
|
||||
DownloadCount int `json:"download_count"`
|
||||
MaxDownloads int `json:"max_downloads"`
|
||||
Files []model.FileItem `json:"files"`
|
||||
Type string `json:"type"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Files []model.FileItem `json:"files,omitempty"`
|
||||
}
|
||||
|
||||
// DownloadBatch 批量下载文件 (ZIP)
|
||||
@@ -107,6 +109,8 @@ func (h *PickupHandler) Pickup(c *gin.Context) {
|
||||
ExpireType: batch.ExpireType,
|
||||
DownloadCount: batch.DownloadCount,
|
||||
MaxDownloads: batch.MaxDownloads,
|
||||
Type: batch.Type,
|
||||
Content: batch.Content,
|
||||
Files: batch.FileItems,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -94,3 +94,60 @@ func (h *UploadHandler) Upload(c *gin.Context) {
|
||||
BatchID: batch.ID,
|
||||
}))
|
||||
}
|
||||
|
||||
type UploadTextRequest struct {
|
||||
Content string `json:"content" binding:"required" example:"这是一段长文本内容..."`
|
||||
Remark string `json:"remark" example:"文本备注"`
|
||||
ExpireType string `json:"expire_type" example:"time"`
|
||||
ExpireDays int `json:"expire_days" example:"7"`
|
||||
MaxDownloads int `json:"max_downloads" example:"5"`
|
||||
}
|
||||
|
||||
// UploadText 发送长文本并生成取件码
|
||||
// @Summary 发送长文本
|
||||
// @Description 中转一段长文本内容并创建一个提取批次
|
||||
// @Tags Public
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body UploadTextRequest true "文本内容及配置"
|
||||
// @Success 200 {object} model.Response{data=UploadResponse}
|
||||
// @Failure 400 {object} model.Response
|
||||
// @Failure 500 {object} model.Response
|
||||
// @Router /api/upload/text [post]
|
||||
func (h *UploadHandler) UploadText(c *gin.Context) {
|
||||
var req UploadTextRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, model.ErrorResponse(model.CodeBadRequest, err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if req.ExpireType == "" {
|
||||
req.ExpireType = "time"
|
||||
}
|
||||
|
||||
var expireValue interface{}
|
||||
switch req.ExpireType {
|
||||
case "time":
|
||||
if req.ExpireDays <= 0 {
|
||||
req.ExpireDays = config.GlobalConfig.Upload.MaxRetentionDays
|
||||
}
|
||||
expireValue = req.ExpireDays
|
||||
case "download":
|
||||
if req.MaxDownloads <= 0 {
|
||||
req.MaxDownloads = 1
|
||||
}
|
||||
expireValue = req.MaxDownloads
|
||||
}
|
||||
|
||||
batch, err := h.uploadService.CreateTextBatch(c.Request.Context(), req.Content, req.Remark, req.ExpireType, expireValue)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, model.ErrorResponse(model.CodeInternalError, err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, model.SuccessResponse(UploadResponse{
|
||||
PickupCode: batch.PickupCode,
|
||||
ExpireAt: batch.ExpireAt,
|
||||
BatchID: batch.ID,
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user