diff options
author | FChannel <> | 2022-06-13 17:58:26 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 5cff4d3740eb8b9f67de9713124e84109d04cff8 (patch) | |
tree | 8940203f84ef45e36d3cea414c40ace47152a8ce | |
parent | cc3e8e57154409469267b0526807a907d5166147 (diff) |
admin reported management improvements
-rw-r--r-- | db/report.go | 19 | ||||
-rw-r--r-- | route/routes/admin.go | 39 | ||||
-rw-r--r-- | route/routes/api.go | 2 | ||||
-rw-r--r-- | route/structs.go | 1 | ||||
-rw-r--r-- | route/util.go | 7 | ||||
-rw-r--r-- | views/admin.html | 25 | ||||
-rw-r--r-- | views/manage.html | 9 |
7 files changed, 93 insertions, 9 deletions
diff --git a/db/report.go b/db/report.go index f5569fd..52e303a 100644 --- a/db/report.go +++ b/db/report.go @@ -1,6 +1,7 @@ package db import ( + "github.com/FChannel0/FChannel-Server/activitypub" "github.com/FChannel0/FChannel-Server/config" "github.com/FChannel0/FChannel-Server/util" ) @@ -8,6 +9,9 @@ import ( type Reports struct { ID string Count int + Actor activitypub.Actor + Object activitypub.ObjectBase + OP string Reason []string } @@ -102,12 +106,27 @@ func GetLocalReport(board string) (map[string]Reports, error) { continue } + var obj = activitypub.ObjectBase{Id: r.ID} + + col, _ := obj.GetCollectionFromPath() + + OP, _ := obj.GetOP() + reported[r.ID] = Reports{ ID: r.ID, Count: 1, + Object: col.OrderedItems[0], + OP: OP, + Actor: activitypub.Actor{Name: board, Outbox: config.Domain + "/" + board + "/outbox"}, Reason: []string{r.Reason}, } } return reported, nil } + +type ReportsSortDesc []Reports + +func (a ReportsSortDesc) Len() int { return len(a) } +func (a ReportsSortDesc) Less(i, j int) bool { return a[i].Object.Updated.After(a[j].Object.Updated) } +func (a ReportsSortDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } diff --git a/route/routes/admin.go b/route/routes/admin.go index 1576a3a..a2b4ad5 100644 --- a/route/routes/admin.go +++ b/route/routes/admin.go @@ -6,6 +6,8 @@ import ( "errors" "io/ioutil" "net/http" + "regexp" + "sort" "time" "github.com/FChannel0/FChannel-Server/activitypub" @@ -119,6 +121,24 @@ func AdminIndex(ctx *fiber.Ctx) error { var adminData route.AdminPage adminData.Following = following adminData.Followers = followers + + var reported = make(map[string][]db.Reports) + + for _, e := range following { + re := regexp.MustCompile(`.*/(.+)$`) + boards := re.FindStringSubmatch(e) + reports, _ := db.GetLocalReport(boards[1]) + + for _, k := range reports { + reported[k.Actor.Name] = append(reported[k.Actor.Name], k) + } + } + + for k, e := range reported { + sort.Sort(db.ReportsSortDesc(e)) + reported[k] = e + } + adminData.Actor = actor.Id adminData.Key = config.Key adminData.Domain = config.Domain @@ -140,7 +160,8 @@ func AdminIndex(ctx *fiber.Ctx) error { adminData.Themes = &config.Themes return ctx.Render("admin", fiber.Map{ - "page": adminData, + "page": adminData, + "reports": reported, }, "layouts/main") } @@ -248,10 +269,21 @@ func AdminActorIndex(ctx *fiber.Ctx) error { data.Following = following data.Followers = followers - data.Reported, _ = db.GetLocalReport(actor.Name) + + reports, _ := db.GetLocalReport(actor.Name) + + var reported = make(map[string][]db.Reports) + for _, k := range reports { + reported[k.Actor.Name] = append(reported[k.Actor.Name], k) + } + + for k, e := range reported { + sort.Sort(db.ReportsSortDesc(e)) + reported[k] = e + } + data.Domain = config.Domain data.IsLocal, _ = actor.IsLocal() - data.Title = "Manage /" + actor.Name + "/" data.Boards = webfinger.Boards data.Board.Name = actor.Name @@ -286,6 +318,7 @@ func AdminActorIndex(ctx *fiber.Ctx) error { return ctx.Render("manage", fiber.Map{ "page": data, "jannies": jannies, + "reports": reported, }, "layouts/main") } diff --git a/route/routes/api.go b/route/routes/api.go index 49c2623..70607e9 100644 --- a/route/routes/api.go +++ b/route/routes/api.go @@ -30,7 +30,7 @@ func RouteImages(ctx *fiber.Ctx, media string) error { resp, err := client.Do(req) if err != nil { - return util.MakeError(err, "RouteImages") + return nil } defer resp.Body.Close() diff --git a/route/structs.go b/route/structs.go index 601943c..17deb25 100644 --- a/route/structs.go +++ b/route/structs.go @@ -38,7 +38,6 @@ type AdminPage struct { Boards []webfinger.Board Following []string Followers []string - Reported map[string]db.Reports Domain string IsLocal bool PostBlacklist []util.PostBlacklist diff --git a/route/util.go b/route/util.go index 131cf5a..74926b4 100644 --- a/route/util.go +++ b/route/util.go @@ -374,6 +374,13 @@ func TemplateFunctions(engine *html.Engine) { return returnString }) + engine.AddFunc("parseLinkTitle", func(board string, op string, content string) string { + nContent := post.ParseLinkTitle(board, op, content) + nContent = strings.ReplaceAll(nContent, `/\<`, ">") + + return nContent + }) + engine.AddFunc("parseLink", func(board activitypub.Actor, link string) string { var obj = activitypub.ObjectBase{ Id: link, diff --git a/views/admin.html b/views/admin.html index 2b733b5..3444657 100644 --- a/views/admin.html +++ b/views/admin.html @@ -14,10 +14,10 @@ </select> </form> <ul style="display: inline-block; padding: 0;"> + <li style="display: inline-block;">[<a href="#reported">Reported</a>]</li> <li style="display: inline-block;">[<a href="#news">Create News</a>]</li> <li style="display: inline-block;">[<a href="#regex">Post Blacklist</a>]</li> <!-- <li style="display: inline-block;"><a href="javascript:show('followers')">Followers</a></li> --> - <!-- <li style="display: inline-block;"><a href="#reported">Reported</a></li> --> </ul> </div> @@ -45,6 +45,29 @@ </ul> </div> +<div id="reported" class="box2" style="margin-bottom: 25px; padding: 12px;"> + <h4 style="margin: 0; margin-bottom: 5px;">Reported</h4> + <ul style="display: inline-block; padding: 0; margin: 0; list-style-type: none;"> + {{ $domain := .page.Domain }} + {{ range .reports }} + <h4 style="margin: 0;"><a href="{{ print $domain "/" (index . 0).Actor.Name }}">/{{ (index . 0).Actor.Name }}/</a></h4> + {{ range . }} + <li style="padding: 12px;"> + <div style="margin-bottom: 5px;">{{ .Object.Updated | timeToReadableLong }}</div> + <a id="rpost" post="{{ .ID }}" title="{{ parseLinkTitle .Actor.Outbox .OP .Object.Content}}" href="/{{ parseLink .Actor .ID }}">{{ shortURL .Actor.Outbox .ID }}</a> - <b>{{ .Count }}</b> [<a href="/delete?id={{ .ID }}&board={{ .Actor.Name }}&manage=t">Remove Post</a>] {{ if (index .Object.Attachment 0).Id }} [<a href="/banmedia?id={{ .ID }}&board={{ .Actor.Name }}">Ban Media</a>] [<a href="/deleteattach?id={{ .ID }}&board={{ .Actor.Name }}&manage=t">Remove Attachment</a>]{{ end }} [<a href="/report?id={{ .ID }}&close=1&board={{ .Actor.Name }}">Close</a>] + <ul> + {{ range .Reason }} + <li> + <span>"{{ . }}" </span> + </li> + {{ end }} + </ul> + </li> + {{ end }} + {{ end }} + </ul> +</div> + <div class="box2" style="margin-bottom: 25px; padding: 12px;"> <h3>Create News</h3> <form id="news" action="/{{ .page.Key }}/newspost" method="post" enctype="application/x-www-form-urlencoded"> diff --git a/views/manage.html b/views/manage.html index e51644e..7db9d01 100644 --- a/views/manage.html +++ b/views/manage.html @@ -47,9 +47,11 @@ <h4 style="margin: 0; margin-bottom: 5px;">Reported</h4> <ul style="display: inline-block; padding: 0; margin: 0; list-style-type: none;"> {{ $domain := .page.Domain }} - {{ range .page.Reported }} - <li> - <a id="rpost" post="{{ .ID }}" href="/{{ parseLink $board.Actor .ID }}">{{ shortURL $board.Actor.Outbox .ID }}</a> - <b>{{ .Count }}</b> [<a href="/delete?id={{ .ID }}&board={{ $board.Name }}&manage=t">Remove Post</a>] [<a href="/deleteattach?id={{ .ID }}&board={{ $board.Name }}&manage=t">Remove Attachment</a>] [<a href="/report?id={{ .ID }}&close=1&board={{ $board.Name }}">Close</a>] + {{ range .reports }} + {{ range . }} + <li style="padding: 12px;"> + <div style="margin-bottom: 5px;">{{ .Object.Updated | timeToReadableLong }}</div> + <a id="rpost" post="{{ .ID }}" title="{{ parseLinkTitle .Actor.Outbox .OP .Object.Content}}" href="/{{ parseLink .Actor .ID }}">{{ shortURL .Actor.Outbox .ID }}</a> - <b>{{ .Count }}</b> [<a href="/delete?id={{ .ID }}&board={{ .Actor.Name }}&manage=t">Remove Post</a>] {{ if (index .Object.Attachment 0).Id }} [<a href="/banmedia?id={{ .ID }}&board={{ .Actor.Name }}">Ban Media</a>] [<a href="/deleteattach?id={{ .ID }}&board={{ .Actor.Name }}&manage=t">Remove Attachment</a>]{{ end }} [<a href="/report?id={{ .ID }}&close=1&board={{ .Actor.Name }}">Close</a>] <ul> {{ range .Reason }} <li> @@ -59,6 +61,7 @@ </ul> </li> {{ end }} + {{ end }} </ul> </div> |