diff options
author | 2024-05-29 12:56:17 +0200 | |
---|---|---|
committer | 2024-05-29 12:56:17 +0200 | |
commit | f9a4a6120db69e5ead542cb130533b0c20e2cd66 (patch) | |
tree | f2b465c2e79fb63908e8bb7c642f089b0e653020 /internal/api/client/admin/debug_on.go | |
parent | [chore/bugfix] Don't cache MovedTo account (#2939) (diff) | |
download | gotosocial-f9a4a6120db69e5ead542cb130533b0c20e2cd66.tar.xz |
[feature] Debug admin endpoint to clear caches (#2940)
* [feature] Debug admin endpoint to clear caches
* go fmt
Diffstat (limited to 'internal/api/client/admin/debug_on.go')
-rw-r--r-- | internal/api/client/admin/debug_on.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/api/client/admin/debug_on.go b/internal/api/client/admin/debug_on.go index c6dfa11ff..ea42206f8 100644 --- a/internal/api/client/admin/debug_on.go +++ b/internal/api/client/admin/debug_on.go @@ -56,3 +56,27 @@ func (m *Module) DebugAPUrlHandler(c *gin.Context) { c.JSON(http.StatusOK, resp) } + +func (m *Module) DebugClearCachesHandler(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 + } + + // Sweep all caches down to 0 (empty). + m.state.Caches.Sweep(0) + + c.JSON(http.StatusOK, gin.H{"status": "OK"}) +} |