the big refactor 2: return of the ID struct

This commit is contained in:
2021-09-27 01:59:32 +02:00
parent 91e217e472
commit 74037dfab5
8 changed files with 238 additions and 151 deletions

View File

@@ -157,7 +157,17 @@ func httpPostFile(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
}
id.Normalize()
log.Debug("Upload file: ", id)
@@ -165,7 +175,7 @@ func httpPostFile(ctx context.Context, rw http.ResponseWriter, r *http.Request)
mimeType, _, _ := mime.ParseMediaType(contentType)
log.Debug("S3 call 'PutObject': ", id)
info, err := s3Client.PutObject(context.Background(), "dev", id, r.Body, r.ContentLength, minio.PutObjectOptions{
_, err := s3Client.PutObject(context.Background(), id.Bucket, id.Key, r.Body, r.ContentLength, minio.PutObjectOptions{
ContentType: mimeType,
})
@@ -175,7 +185,7 @@ func httpPostFile(ctx context.Context, rw http.ResponseWriter, r *http.Request)
}
// Invalidate cache
helper.InvalidateCache(ctx, info.Key)
helper.InvalidateCache(ctx, *id)
rw.WriteHeader(http.StatusCreated)
}