add Cloudflare R2 storage integration and update bug report handling
Some checks failed
Build & Publish Docker Image / build-and-push (push) Failing after 11s
Some checks failed
Build & Publish Docker Image / build-and-push (push) Failing after 11s
This commit is contained in:
@@ -5,13 +5,14 @@ import (
|
||||
"time"
|
||||
|
||||
"emly-api-go/internal/handlers"
|
||||
"emly-api-go/internal/storage"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/httprate"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
func registerBugReports(r chi.Router, db *sqlx.DB, dbName string) {
|
||||
func registerBugReports(r chi.Router, db *sqlx.DB, dbName string, s3conn *storage.S3Connector) {
|
||||
r.Route("/bug-reports", func(r chi.Router) {
|
||||
// API key only: submit a report and check count
|
||||
r.Group(func(r chi.Router) {
|
||||
@@ -19,7 +20,7 @@ func registerBugReports(r chi.Router, db *sqlx.DB, dbName string) {
|
||||
r.Use(httprate.LimitByIP(30, time.Minute))
|
||||
|
||||
r.Get("/count", handlers.GetReportsCount(db, dbName))
|
||||
r.Post("/", handlers.CreateBugReport(db, dbName))
|
||||
r.Post("/", handlers.CreateBugReport(db, dbName, s3conn))
|
||||
})
|
||||
|
||||
// API key + admin key: full read/write access
|
||||
@@ -32,10 +33,10 @@ func registerBugReports(r chi.Router, db *sqlx.DB, dbName string) {
|
||||
r.Get("/{id}", handlers.GetBugReportByID(db, dbName))
|
||||
r.Get("/{id}/status", handlers.GetReportStatusByID(db, dbName))
|
||||
r.Get("/{id}/files", handlers.GetReportFilesByReportID(db, dbName))
|
||||
r.Get("/{id}/files/{file_id}", handlers.GetReportFileByFileID(db, dbName))
|
||||
r.Get("/{id}/download", handlers.GetBugReportZipById(db, dbName))
|
||||
r.Get("/{id}/files/{file_id}", handlers.GetReportFileByFileID(db, dbName, s3conn))
|
||||
r.Get("/{id}/download", handlers.GetBugReportZipByID(db, dbName))
|
||||
r.Patch("/{id}/status", handlers.PatchBugReportStatus(db, dbName))
|
||||
r.Delete("/{id}", handlers.DeleteBugReportByID(db, dbName))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,14 @@ import (
|
||||
|
||||
"emly-api-go/internal/config"
|
||||
"emly-api-go/internal/handlers"
|
||||
"emly-api-go/internal/storage"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// NewRouter returns a chi.Router with all /v1 routes mounted.
|
||||
// Add new API versions by creating an analogous package (e.g. v2) and
|
||||
// mounting it alongside this one in internal/routes/routes.go.
|
||||
func NewRouter(db *sqlx.DB) http.Handler {
|
||||
func NewRouter(db *sqlx.DB, s3conn *storage.S3Connector) http.Handler {
|
||||
r := chi.NewRouter()
|
||||
|
||||
rl := emlyMiddleware.NewRateLimiter(config.Load())
|
||||
@@ -33,7 +32,7 @@ func NewRouter(db *sqlx.DB) http.Handler {
|
||||
|
||||
r.Route("/api", func(r chi.Router) {
|
||||
registerAdmin(r, db)
|
||||
registerBugReports(r, db, config.Load().Database)
|
||||
registerBugReports(r, db, config.Load().Database, s3conn)
|
||||
})
|
||||
|
||||
return r
|
||||
|
||||
Reference in New Issue
Block a user