Added logging

This commit is contained in:
Borna Rajković 2024-01-04 22:05:02 +01:00
parent dbe068bbcb
commit fdd46f5086
1 changed files with 11 additions and 0 deletions

View File

@ -69,12 +69,15 @@ func HandleUpload(resourceManager resource.Manager) gin.HandlerFunc {
return return
} }
} }
log.Printf("Uploading '%s'...", request.Path)
resourceManager.Upload(resource.UploadRequest{ resourceManager.Upload(resource.UploadRequest{
Buffer: bytes.NewBuffer(content), Buffer: bytes.NewBuffer(content),
Path: request.Path, Path: request.Path,
MimeType: request.Properties.MimeType, MimeType: request.Properties.MimeType,
Overwrite: request.Properties.Overwrite, Overwrite: request.Properties.Overwrite,
}) })
log.Printf("Uploaded '%s'", request.Path)
// we return this as success // we return this as success
c.Status(http.StatusNoContent) c.Status(http.StatusNoContent)
} }
@ -85,10 +88,12 @@ func HandleCopy(resourceManager resource.Manager) gin.HandlerFunc {
from := c.Query("from") from := c.Query("from")
to := c.Query("to") to := c.Query("to")
overwrite := c.Query("overwrite") == "true" 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 { if err := resourceManager.Copy(from, to, overwrite); err != nil {
log.Println(err) log.Println(err)
c.AbortWithStatus(500) c.AbortWithStatus(500)
} else { } else {
log.Printf("Done copyting from '%s' to '%s' (overwrite=%v)", from, to, overwrite)
c.Status(201) c.Status(201)
} }
@ -103,6 +108,8 @@ func HandlePresign(resourceManager resource.Manager) gin.HandlerFunc {
c.AbortWithStatus(404) c.AbortWithStatus(404)
return return
} }
log.Printf("Presigned '%s'", path)
if c.Query("redirect") == "true" { if c.Query("redirect") == "true" {
c.Redirect(http.StatusTemporaryRedirect, url) c.Redirect(http.StatusTemporaryRedirect, url)
} else { } else {
@ -114,8 +121,10 @@ func HandlePresign(resourceManager resource.Manager) gin.HandlerFunc {
func HandleDownload(resourceManager resource.Manager) gin.HandlerFunc { func HandleDownload(resourceManager resource.Manager) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
path := c.Query("path") path := c.Query("path")
log.Printf("Downloading '%s'...", path)
data, err := resourceManager.Download(c, path) data, err := resourceManager.Download(c, path)
if err == nil { if err == nil {
log.Printf("Downloaded '%s'", path)
c.Header("content-disposition", "inline; filename=\""+filename(path)+"\"") c.Header("content-disposition", "inline; filename=\""+filename(path)+"\"")
c.Data(200, readMimeType(path, ""), data) c.Data(200, readMimeType(path, ""), data)
} else { } else {
@ -127,9 +136,11 @@ func HandleDownload(resourceManager resource.Manager) gin.HandlerFunc {
func HandleDelete(resourceManager resource.Manager) gin.HandlerFunc { func HandleDelete(resourceManager resource.Manager) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
path := c.Query("path") path := c.Query("path")
log.Printf("Deleting '%s'...", path)
if err := resourceManager.Delete(path); err != nil { if err := resourceManager.Delete(path); err != nil {
c.AbortWithError(400, err) c.AbortWithError(400, err)
} else { } else {
log.Printf("Deleted '%s'", path)
c.Status(204) c.Status(204)
} }
} }