feat!(backend): move /auth/export to /users/@me/export

This commit is contained in:
Sam 2023-03-16 12:49:27 +01:00
parent 17f6ac4d23
commit f087e9a29f
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
5 changed files with 14 additions and 9 deletions

View file

@ -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))

View file

@ -1,4 +1,4 @@
package auth
package user
import (
"net/http"

View file

@ -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))
})
})
}

View file

@ -23,7 +23,7 @@
const requestExport = async () => {
try {
await apiFetchClient<any>("/auth/export/start");
await apiFetchClient<any>("/users/@me/export/start");
addToast({
header: "Export in progress",

View file

@ -4,7 +4,7 @@ import { error } from "@sveltejs/kit";
export const load = async () => {
try {
const data = await apiFetchClient<ExportResponse>("/auth/export");
const data = await apiFetchClient<ExportResponse>("/users/@me/export");
return { exportData: data };
} catch (e) {
if ((e as APIError).code === ErrorCode.NotFound) return { exportData: null };