From fdd46f50863f204c04598e23a7e528f418dbdb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borna=20Rajkovi=C4=87?= Date: Thu, 4 Jan 2024 22:05:02 +0100 Subject: [PATCH] Added logging --- api/api.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/api.go b/api/api.go index 88f9bc8..98ad926 100644 --- a/api/api.go +++ b/api/api.go @@ -69,12 +69,15 @@ func HandleUpload(resourceManager resource.Manager) gin.HandlerFunc { return } } + log.Printf("Uploading '%s'...", request.Path) + resourceManager.Upload(resource.UploadRequest{ Buffer: bytes.NewBuffer(content), Path: request.Path, MimeType: request.Properties.MimeType, Overwrite: request.Properties.Overwrite, }) + log.Printf("Uploaded '%s'", request.Path) // we return this as success c.Status(http.StatusNoContent) } @@ -85,10 +88,12 @@ func HandleCopy(resourceManager resource.Manager) gin.HandlerFunc { from := c.Query("from") to := c.Query("to") overwrite := c.Query("overwrite") == "true" + log.Printf("Copying from '%s' to '%s' (overwrite=%v)...", from, to, overwrite) if err := resourceManager.Copy(from, to, overwrite); err != nil { log.Println(err) c.AbortWithStatus(500) } else { + log.Printf("Done copyting from '%s' to '%s' (overwrite=%v)", from, to, overwrite) c.Status(201) } @@ -103,6 +108,8 @@ func HandlePresign(resourceManager resource.Manager) gin.HandlerFunc { c.AbortWithStatus(404) return } + log.Printf("Presigned '%s'", path) + if c.Query("redirect") == "true" { c.Redirect(http.StatusTemporaryRedirect, url) } else { @@ -114,8 +121,10 @@ func HandlePresign(resourceManager resource.Manager) gin.HandlerFunc { func HandleDownload(resourceManager resource.Manager) gin.HandlerFunc { return func(c *gin.Context) { path := c.Query("path") + log.Printf("Downloading '%s'...", path) data, err := resourceManager.Download(c, path) if err == nil { + log.Printf("Downloaded '%s'", path) c.Header("content-disposition", "inline; filename=\""+filename(path)+"\"") c.Data(200, readMimeType(path, ""), data) } else { @@ -127,9 +136,11 @@ func HandleDownload(resourceManager resource.Manager) gin.HandlerFunc { func HandleDelete(resourceManager resource.Manager) gin.HandlerFunc { return func(c *gin.Context) { path := c.Query("path") + log.Printf("Deleting '%s'...", path) if err := resourceManager.Delete(path); err != nil { c.AbortWithError(400, err) } else { + log.Printf("Deleted '%s'", path) c.Status(204) } }