feat(handler):lab4 add AttachmentHandler.Content without redirect
This commit is contained in:
@@ -71,3 +71,28 @@ func (h *AttachmentHandler) Get(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, dto.AttachmentFromDomain(a))
|
||||
}
|
||||
|
||||
func (h *AttachmentHandler) Content(c *gin.Context) {
|
||||
me := middleware.CurrentUser(c)
|
||||
|
||||
attachmentID, err := parseUUIDPathParam(c, "attachment_id")
|
||||
if err != nil {
|
||||
respondError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
variant := c.DefaultQuery("variant", "original")
|
||||
if variant != "original" {
|
||||
respondError(c, &domain.NotFoundError{Entity: "variant", ID: variant})
|
||||
return
|
||||
}
|
||||
|
||||
rc, size, contentType, err := h.svc.Download(c.Request.Context(), me.ID, attachmentID)
|
||||
if err != nil {
|
||||
respondError(c, err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = rc.Close() }()
|
||||
|
||||
c.DataFromReader(http.StatusOK, size, contentType, rc, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user