|
|
|
@@ -203,6 +203,12 @@ func GetPresignedPutObjectURL(ctx *context.Context) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
err := upload.VerifyFileType(ctx.Params("file_type"), strings.Split(setting.Attachment.AllowedTypes, ",")) |
|
|
|
if err != nil { |
|
|
|
ctx.Error(400, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if setting.Attachment.StoreType == storage.MinioStorageType { |
|
|
|
uuid := gouuid.NewV4().String() |
|
|
|
url, err := storage.Attachments.PresignedPutURL(models.AttachmentRelativePath(uuid)) |
|
|
|
@@ -219,6 +225,35 @@ func GetPresignedPutObjectURL(ctx *context.Context) { |
|
|
|
ctx.Error(404, "storage type is not enabled") |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// AddAttachment response for add attachment record |
|
|
|
func AddAttachment(ctx *context.Context) { |
|
|
|
uuid := ctx.Query("uuid") |
|
|
|
has,err := storage.Attachments.HasObject(models.AttachmentRelativePath(uuid)) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("HasObject", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if !has { |
|
|
|
ctx.Error(404, "attachment has not been uploaded") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
_, err = models.InsertAttachment(&models.Attachment{ |
|
|
|
UUID: uuid, |
|
|
|
UploaderID: ctx.User.ID, |
|
|
|
Name: ctx.Query("file_name"), |
|
|
|
Size: ctx.QueryInt64("size"), |
|
|
|
}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
ctx.Error(500, fmt.Sprintf("InsertAttachment: %v", err)) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
ctx.JSON(200, map[string]string{ |
|
|
|
"result_code": "0", |
|
|
|
}) |
|
|
|
} |