From f087e9a29f9eff24d9b119ec642f5cf337155923 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 16 Mar 2023 12:49:27 +0100 Subject: [PATCH] feat!(backend): move /auth/export to /users/@me/export --- backend/routes/auth/routes.go | 5 ----- backend/routes/{auth => user}/export.go | 2 +- backend/routes/user/routes.go | 12 +++++++++++- frontend/src/routes/settings/export/+page.svelte | 2 +- frontend/src/routes/settings/export/+page.ts | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) rename backend/routes/{auth => user}/export.go (99%) diff --git a/backend/routes/auth/routes.go b/backend/routes/auth/routes.go index f18144f..452d240 100644 --- a/backend/routes/auth/routes.go +++ b/backend/routes/auth/routes.go @@ -18,7 +18,6 @@ type Server struct { RequireInvite bool BaseURL string - ExporterPath string } type userResponse struct { @@ -57,7 +56,6 @@ func Mount(srv *server.Server, r chi.Router) { Server: srv, RequireInvite: os.Getenv("REQUIRE_INVITE") == "true", BaseURL: os.Getenv("BASE_URL"), - ExporterPath: "http://127.0.0.1:" + os.Getenv("EXPORTER_PORT"), } r.Route("/auth", func(r chi.Router) { @@ -92,9 +90,6 @@ func Mount(srv *server.Server, r chi.Router) { r.With(server.MustAuth).Post("/tokens", server.WrapHandler(s.createToken)) r.With(server.MustAuth).Delete("/tokens/{id}", server.WrapHandler(s.deleteToken)) - r.With(server.MustAuth).Get("/export/start", server.WrapHandler(s.startExport)) - r.With(server.MustAuth).Get("/export", server.WrapHandler(s.getExport)) - // cancel user delete // uses a special token, so handled in the function itself r.Get("/cancel-delete", server.WrapHandler(s.cancelDelete)) diff --git a/backend/routes/auth/export.go b/backend/routes/user/export.go similarity index 99% rename from backend/routes/auth/export.go rename to backend/routes/user/export.go index 7454eef..c1588e0 100644 --- a/backend/routes/auth/export.go +++ b/backend/routes/user/export.go @@ -1,4 +1,4 @@ -package auth +package user import ( "net/http" diff --git a/backend/routes/user/routes.go b/backend/routes/user/routes.go index 550fa75..2324d7c 100644 --- a/backend/routes/user/routes.go +++ b/backend/routes/user/routes.go @@ -1,16 +1,23 @@ package user import ( + "os" + "codeberg.org/u1f320/pronouns.cc/backend/server" "github.com/go-chi/chi/v5" ) type Server struct { *server.Server + + ExporterPath string } func Mount(srv *server.Server, r chi.Router) { - s := &Server{srv} + s := &Server{ + Server: srv, + ExporterPath: "http://127.0.0.1:" + os.Getenv("EXPORTER_PORT"), + } r.Route("/users", func(r chi.Router) { r.Get("/{userRef}", server.WrapHandler(s.getUser)) @@ -19,6 +26,9 @@ func Mount(srv *server.Server, r chi.Router) { r.Get("/@me", server.WrapHandler(s.getMeUser)) r.Patch("/@me", server.WrapHandler(s.patchUser)) r.Delete("/@me", server.WrapHandler(s.deleteUser)) + + r.Get("/export/start", server.WrapHandler(s.startExport)) + r.Get("/export", server.WrapHandler(s.getExport)) }) }) } diff --git a/frontend/src/routes/settings/export/+page.svelte b/frontend/src/routes/settings/export/+page.svelte index b167e92..6e491bf 100644 --- a/frontend/src/routes/settings/export/+page.svelte +++ b/frontend/src/routes/settings/export/+page.svelte @@ -23,7 +23,7 @@ const requestExport = async () => { try { - await apiFetchClient("/auth/export/start"); + await apiFetchClient("/users/@me/export/start"); addToast({ header: "Export in progress", diff --git a/frontend/src/routes/settings/export/+page.ts b/frontend/src/routes/settings/export/+page.ts index 625cff1..9ba40c1 100644 --- a/frontend/src/routes/settings/export/+page.ts +++ b/frontend/src/routes/settings/export/+page.ts @@ -4,7 +4,7 @@ import { error } from "@sveltejs/kit"; export const load = async () => { try { - const data = await apiFetchClient("/auth/export"); + const data = await apiFetchClient("/users/@me/export"); return { exportData: data }; } catch (e) { if ((e as APIError).code === ErrorCode.NotFound) return { exportData: null };