From 724ec5751faeace01ce1a37031bab4d1f937e754 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 29 Sep 2024 11:59:18 +0200 Subject: [PATCH] fix(attachment): do not use image previews Image previews were partially backported from main which caused error messages because some parts are missing. Resolved https://community.vikunja.io/t/preview-size-is-not-defined/2843 --- pkg/routes/api/v1/task_attachment.go | 32 +--------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/pkg/routes/api/v1/task_attachment.go b/pkg/routes/api/v1/task_attachment.go index dcf1979f0..1fec91527 100644 --- a/pkg/routes/api/v1/task_attachment.go +++ b/pkg/routes/api/v1/task_attachment.go @@ -17,14 +17,11 @@ package v1 import ( - "net/http" - "strings" - "code.vikunja.io/api/pkg/db" - "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/models" auth2 "code.vikunja.io/api/pkg/modules/auth" "code.vikunja.io/api/pkg/web/handler" + "net/http" "github.com/labstack/echo/v4" ) @@ -117,8 +114,6 @@ func UploadTaskAttachment(c echo.Context) error { // @Produce octet-stream // @Param id path int true "Task ID" // @Param attachmentID path int true "Attachment ID" -// @Param preview query string false "If set to true, a preview image will be returned if the attachment is an image." -// @Param size query string false "The size of the preview image. Can be sm = 100px, md = 200px, lg = 400px or xl = 800px." // @Security JWTKeyAuth // @Success 200 {file} blob "The attachment file." // @Failure 403 {object} models.Message "No access to this task." @@ -157,23 +152,6 @@ func GetTaskAttachment(c echo.Context) error { return handler.HandleHTTPError(err) } - // Reading the 'preview' query parameter - preview := c.QueryParam("preview") == "true" - previewSize := models.PreviewSize(c.QueryParam("size")) - if previewSize == "" { - previewSize = models.PreviewMedium - } - - // If the preview query parameter is set and the preview was already generated and cached, return the cached preview image - if preview && strings.HasPrefix(taskAttachment.File.Mime, "image") { - previewFileBytes := taskAttachment.GetPreviewFromCache(previewSize) - if previewFileBytes != nil { - log.Debugf("Cached attachment image preview found for task attachment %v", taskAttachment.ID) - - return c.Blob(http.StatusOK, "image/png", previewFileBytes) - } - } - // Open and send the file to the client err = taskAttachment.File.LoadFileByID() if err != nil { @@ -186,14 +164,6 @@ func GetTaskAttachment(c echo.Context) error { return handler.HandleHTTPError(err) } - // If a preview is requested and the preview was not cached, we create the preview and cache it - if preview { - previewFileBytes := taskAttachment.GenerateAndSavePreviewToCache(previewSize) - if previewFileBytes != nil { - return c.Blob(http.StatusOK, "image/png", previewFileBytes) - } - } - http.ServeContent(c.Response(), c.Request(), taskAttachment.File.Name, taskAttachment.File.Created, taskAttachment.File.File) return nil }