mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-07 07:42:45 +01:00
13
file.go
13
file.go
@@ -30,11 +30,13 @@ func tusdUpload(db *database.Database, bus *bus.Bus, client *s3.S3, external str
|
||||
ticketID := chi.URLParam(r, "ticketID")
|
||||
if ticketID == "" {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, errors.New("ticketID not given"))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err := storage.CreateBucket(client, ticketID); err != nil {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, fmt.Errorf("could not create bucket: %w", err))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -50,6 +52,7 @@ func tusdUpload(db *database.Database, bus *bus.Bus, client *s3.S3, external str
|
||||
})
|
||||
if err != nil {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, fmt.Errorf("could not create tusd handler: %w", err))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -73,6 +76,7 @@ func tusdUpload(db *database.Database, bus *bus.Bus, client *s3.S3, external str
|
||||
doc, err := db.AddFile(ctx, id, file)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -92,7 +96,6 @@ func tusdUpload(db *database.Database, bus *bus.Bus, client *s3.S3, external str
|
||||
default:
|
||||
api.JSONErrorStatus(w, http.StatusInternalServerError, errors.New("unknown method"))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,18 +104,21 @@ func upload(db *database.Database, client *s3.S3, uploader *s3manager.Uploader)
|
||||
ticketID := chi.URLParam(r, "ticketID")
|
||||
if ticketID == "" {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, errors.New("ticketID not given"))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
file, header, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, err)
|
||||
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if err := storage.CreateBucket(client, ticketID); err != nil {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, fmt.Errorf("could not create bucket: %w", err))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -123,12 +129,14 @@ func upload(db *database.Database, client *s3.S3, uploader *s3manager.Uploader)
|
||||
})
|
||||
if err != nil {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
id, err := strconv.ParseInt(ticketID, 10, 64)
|
||||
if err != nil {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -138,6 +146,7 @@ func upload(db *database.Database, client *s3.S3, uploader *s3manager.Uploader)
|
||||
})
|
||||
if err != nil {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, err)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -148,12 +157,14 @@ func download(downloader *s3manager.Downloader) http.HandlerFunc {
|
||||
ticketID := chi.URLParam(r, "ticketID")
|
||||
if ticketID == "" {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, errors.New("ticketID not given"))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
key := chi.URLParam(r, "key")
|
||||
if key == "" {
|
||||
api.JSONErrorStatus(w, http.StatusBadRequest, errors.New("key not given"))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user