summaryrefslogtreecommitdiff
path: root/internal/api/client/admin/debug_on.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-11-27 15:02:52 +0100
committerLibravatar GitHub <noreply@github.com>2023-11-27 14:02:52 +0000
commit5eddef6c9b66fd35dc9473578d4e1a3b1b8d7b08 (patch)
treeee67f8a683a351580bc0b6365067001c34ff1cc1 /internal/api/client/admin/debug_on.go
parent[performance] http response encoding / writing improvements (#2374) (diff)
downloadgotosocial-5eddef6c9b66fd35dc9473578d4e1a3b1b8d7b08.tar.xz
[feature] Add `/api/v1/admin/debug/apurl` endpoint (#2359)
Diffstat (limited to 'internal/api/client/admin/debug_on.go')
-rw-r--r--internal/api/client/admin/debug_on.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/api/client/admin/debug_on.go b/internal/api/client/admin/debug_on.go
new file mode 100644
index 000000000..c6dfa11ff
--- /dev/null
+++ b/internal/api/client/admin/debug_on.go
@@ -0,0 +1,58 @@
+// GoToSocial
+// Copyright (C) GoToSocial Authors admin@gotosocial.org
+// SPDX-License-Identifier: AGPL-3.0-or-later
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//go:build debug || debugenv
+// +build debug debugenv
+
+package admin
+
+import (
+ "fmt"
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+ apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
+ "github.com/superseriousbusiness/gotosocial/internal/oauth"
+)
+
+func (m *Module) DebugAPUrlHandler(c *gin.Context) {
+ authed, err := oauth.Authed(c, true, true, true, true)
+ if err != nil {
+ apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
+ return
+ }
+
+ if !*authed.User.Admin {
+ err := fmt.Errorf("user %s not an admin", authed.User.ID)
+ apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
+ return
+ }
+
+ if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
+ apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
+ return
+ }
+
+ resp, errWithCode := m.processor.Admin().DebugAPUrl(c.Request.Context(), authed.Account, c.Query("url"))
+ if errWithCode != nil {
+ apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
+ return
+ }
+
+ c.JSON(http.StatusOK, resp)
+}