From aad953f0b5d62cc7afd64297e863edf7d1c09908 Mon Sep 17 00:00:00 2001 From: grngxd <36968271+grngxd@users.noreply.github.com> Date: Mon, 5 May 2025 14:43:21 +0100 Subject: [PATCH 1/2] feat: upload route --- .air.toml | 52 +++++++++++++++++++++++++++++++++++ .gitignore | 3 +- internal/api/api.go | 2 +- internal/api/routes/ping.go | 13 --------- internal/api/routes/upload.go | 24 ++++++++++++++++ 5 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 .air.toml delete mode 100644 internal/api/routes/ping.go create mode 100644 internal/api/routes/upload.go diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..6b2c951 --- /dev/null +++ b/.air.toml @@ -0,0 +1,52 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + args_bin = [] + bin = "tmp\\main.exe" + cmd = "go build -o ./tmp/main.exe ." + delay = 1000 + exclude_dir = ["assets", "tmp", "vendor", "testdata"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + post_cmd = [] + pre_cmd = [] + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + silent = false + time = false + +[misc] + clean_on_exit = false + +[proxy] + app_port = 0 + enabled = false + proxy_port = 0 + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/.gitignore b/.gitignore index 2eea525..0efc5d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.env \ No newline at end of file +.env +tmp \ No newline at end of file diff --git a/internal/api/api.go b/internal/api/api.go index 874dbec..7c5945b 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -8,5 +8,5 @@ import ( func Register(cfg *types.StereoConfig) { api := cfg.Router.Group("/api") - routes.RegisterPingRoutes(api) + routes.RegisterUploadRoutes(cfg, api) } diff --git a/internal/api/routes/ping.go b/internal/api/routes/ping.go deleted file mode 100644 index b3289c1..0000000 --- a/internal/api/routes/ping.go +++ /dev/null @@ -1,13 +0,0 @@ -package routes - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -func RegisterPingRoutes(api *gin.RouterGroup) { - api.GET("/ping", func(c *gin.Context) { - c.String(http.StatusOK, "Pong!") - }) -} diff --git a/internal/api/routes/upload.go b/internal/api/routes/upload.go new file mode 100644 index 0000000..0c8c5be --- /dev/null +++ b/internal/api/routes/upload.go @@ -0,0 +1,24 @@ +package routes + +import ( + "path/filepath" + + "github.com/gin-gonic/gin" + "stereo.cat/backend/internal/types" +) + +func RegisterUploadRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) { + api.POST("/upload", func(c *gin.Context) { + file, err := c.FormFile("file") + if err != nil { + c.JSON(400, gin.H{"error": "file is required"}) + return + } + + filePath := filepath.Join(cfg.ImagePath, file.Filename) + if err := c.SaveUploadedFile(file, filePath); err != nil { + c.JSON(500, gin.H{"error": "failed to save file"}) + return + } + }) +} -- 2.47.2 From 3cb5682f6294d31c5cef6ff75e5695fcd36cbbb0 Mon Sep 17 00:00:00 2001 From: grngxd <36968271+grngxd@users.noreply.github.com> Date: Mon, 5 May 2025 14:50:40 +0100 Subject: [PATCH 2/2] a --- internal/api/api.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/api/api.go b/internal/api/api.go index 7c5945b..6aecb5b 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -7,6 +7,5 @@ import ( func Register(cfg *types.StereoConfig) { api := cfg.Router.Group("/api") - routes.RegisterUploadRoutes(cfg, api) } -- 2.47.2