From 4344bf841cb06e4905dcd036741acf40f7d1212d Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Tue, 28 Sep 2021 16:04:18 +0200 Subject: [PATCH] id parse on object get and put --- internal/httpserver/httpServer.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/httpserver/httpServer.go b/internal/httpserver/httpServer.go index 2cebd68..887c6ab 100644 --- a/internal/httpserver/httpServer.go +++ b/internal/httpserver/httpServer.go @@ -112,12 +112,21 @@ func httpGetFile(ctx context.Context, rw http.ResponseWriter, r *http.Request) { } s3Client := ctx.Value("s3Client").(*minio.Client) - id := r.URL.Query().Get("id") + idString := r.URL.Query().Get("id") + + id := types.ParseID(idString) + + if id == nil { + // Failed to parse ID + rw.WriteHeader(http.StatusBadRequest) + return + } log.Debug("S3 call 'StatObject': ", id) - objInfo, err := s3Client.StatObject(context.Background(), "dev", id, minio.GetObjectOptions{}) + objInfo, err := s3Client.StatObject(context.Background(), id.Bucket, id.Key, minio.GetObjectOptions{}) if err != nil { + log.Error("Failed to get object info: ", err) rw.WriteHeader(http.StatusInternalServerError) return } @@ -129,9 +138,10 @@ func httpGetFile(ctx context.Context, rw http.ResponseWriter, r *http.Request) { } log.Debug("S3 call 'GetObject': ", id) - obj, err := s3Client.GetObject(context.Background(), "dev", id, minio.GetObjectOptions{}) + obj, err := s3Client.GetObject(context.Background(), id.Bucket, id.Key, minio.GetObjectOptions{}) if err != nil { + log.Error("Failed to get object: ", err) rw.WriteHeader(http.StatusInternalServerError) return }