diff --git a/pkg/internal/http/admin/fediverse_api.go b/pkg/internal/http/admin/fediverse_api.go new file mode 100644 index 0000000..b0c874e --- /dev/null +++ b/pkg/internal/http/admin/fediverse_api.go @@ -0,0 +1,17 @@ +package admin + +import ( + "git.solsynth.dev/hypernet/interactive/pkg/internal/services" + "git.solsynth.dev/hypernet/nexus/pkg/nex/sec" + "github.com/gofiber/fiber/v2" +) + +func adminTriggerFediverseFetch(c *fiber.Ctx) error { + if err := sec.EnsureGrantedPerm(c, "AdminTriggerFediverseFetch", true); err != nil { + return err + } + + go services.FetchFediverseTimedTask() + + return c.SendStatus(fiber.StatusOK) +} diff --git a/pkg/internal/http/admin/index.go b/pkg/internal/http/admin/index.go new file mode 100644 index 0000000..63e8fa7 --- /dev/null +++ b/pkg/internal/http/admin/index.go @@ -0,0 +1,10 @@ +package admin + +import "github.com/gofiber/fiber/v2" + +func MapControllers(app *fiber.App, baseURL string) { + admin := app.Group(baseURL) + { + admin.Post("/fediverse", adminTriggerFediverseFetch) + } +} diff --git a/pkg/internal/http/api/index.go b/pkg/internal/http/api/index.go index 2dd2098..4e30cb7 100644 --- a/pkg/internal/http/api/index.go +++ b/pkg/internal/http/api/index.go @@ -4,7 +4,7 @@ import ( "github.com/gofiber/fiber/v2" ) -func MapAPIs(app *fiber.App, baseURL string) { +func MapControllers(app *fiber.App, baseURL string) { api := app.Group(baseURL).Name("API") { api.Get("/webfinger", getWebfinger) diff --git a/pkg/internal/http/server.go b/pkg/internal/http/server.go index 7c7b1c9..5bb4cb6 100644 --- a/pkg/internal/http/server.go +++ b/pkg/internal/http/server.go @@ -1,10 +1,12 @@ package http import ( - "git.solsynth.dev/hypernet/nexus/pkg/nex/sec" - "git.solsynth.dev/hypernet/passport/pkg/authkit" "strings" + "git.solsynth.dev/hypernet/nexus/pkg/nex/sec" + "git.solsynth.dev/hypernet/passport/pkg/authkit" + + "git.solsynth.dev/hypernet/interactive/pkg/internal/http/admin" "git.solsynth.dev/hypernet/interactive/pkg/internal/http/api" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" @@ -59,7 +61,8 @@ func NewServer() *App { app.Use(sec.ContextMiddleware(IReader)) app.Use(authkit.ParseAccountMiddleware) - api.MapAPIs(app, "/api") + api.MapControllers(app, "/api") + admin.MapControllers(app, "/api/admin") return &App{ app: app,