summaryrefslogtreecommitdiff
path: root/internal/web/domain-blocklist.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/domain-blocklist.go')
-rw-r--r--internal/web/domain-blocklist.go49
1 files changed, 28 insertions, 21 deletions
diff --git a/internal/web/domain-blocklist.go b/internal/web/domain-blocklist.go
index 8a88a0932..5d631e0f7 100644
--- a/internal/web/domain-blocklist.go
+++ b/internal/web/domain-blocklist.go
@@ -18,14 +18,14 @@
package web
import (
+ "context"
"fmt"
- "net/http"
"github.com/gin-gonic/gin"
+ apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/oauth"
)
const (
@@ -33,37 +33,44 @@ const (
)
func (m *Module) domainBlockListGETHandler(c *gin.Context) {
- authed, err := oauth.Authed(c, false, false, false, false)
- if err != nil {
- apiutil.WebErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
+ instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context())
+ if errWithCode != nil {
+ apiutil.WebErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
- if !config.GetInstanceExposeSuspendedWeb() && (authed.Account == nil || authed.User == nil) {
- err := fmt.Errorf("this instance does not expose the list of suspended domains publicly")
- apiutil.WebErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
+ // Return instance we already got from the db,
+ // don't try to fetch it again when erroring.
+ instanceGet := func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode) {
+ return instance, nil
+ }
+
+ // We only serve text/html at this endpoint.
+ if _, err := apiutil.NegotiateAccept(c, apiutil.TextHTML); err != nil {
+ apiutil.WebErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), instanceGet)
return
}
- instance, err := m.processor.InstanceGetV1(c.Request.Context())
- if err != nil {
- apiutil.WebErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
+ if !config.GetInstanceExposeSuspendedWeb() {
+ err := fmt.Errorf("this instance does not publicy expose its blocklist")
+ apiutil.WebErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), instanceGet)
return
}
domainBlocks, errWithCode := m.processor.InstancePeersGet(c.Request.Context(), true, false, false)
if errWithCode != nil {
- apiutil.WebErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
+ apiutil.WebErrorHandler(c, errWithCode, instanceGet)
return
}
- c.HTML(http.StatusOK, "domain-blocklist.tmpl", gin.H{
- "instance": instance,
- "ogMeta": ogBase(instance),
- "blocklist": domainBlocks,
- "stylesheets": []string{
- assetsPathPrefix + "/Fork-Awesome/css/fork-awesome.min.css",
- },
- "javascript": []string{distPathPrefix + "/frontend.js"},
- })
+ page := apiutil.WebPage{
+ Template: "domain-blocklist.tmpl",
+ Instance: instance,
+ OGMeta: apiutil.OGBase(instance),
+ Stylesheets: []string{cssFA},
+ Javascript: []string{jsFrontend},
+ Extra: map[string]any{"blocklist": domainBlocks},
+ }
+
+ apiutil.TemplateWebPage(c, page)
}