* initial commit * add lists * update permissions * fix waypoint create * needs_full_sync for activitypub trails * fixes build issues * fix list get * further CSRF protection * update API docs * adds rate limiter * fix tiptap mentions * a bit more cleanup of main.go * Fix migration order * fixes reviewed notes * require context for activitpub server calls * improve hashing for identifier * fix copy paste error * fix sync trail/list issues * fix summit log/comment duplicates * adaptions after trail merge * fix dockerignore --------- Co-authored-by: Christian Beutel <> Co-authored-by: slothful-vassal <89943360+slothful-vassal@users.noreply.github.com>
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package hooks
|
|
|
|
import (
|
|
"fmt"
|
|
"pocketbase/util"
|
|
"strings"
|
|
|
|
"github.com/pocketbase/pocketbase/core"
|
|
)
|
|
|
|
func ListFeedHandler() func(e *core.RecordsListRequestEvent) error {
|
|
return func(e *core.RecordsListRequestEvent) error {
|
|
|
|
for _, r := range e.Records {
|
|
var item *core.Record
|
|
var err error
|
|
|
|
typ := r.GetString("type")
|
|
typ = strings.Trim(typ, "\"")
|
|
|
|
itemId := r.GetString("item")
|
|
itemId = strings.Trim(itemId, "\"")
|
|
|
|
switch typ {
|
|
case string(util.TrailFeed):
|
|
item, err = e.App.FindRecordById("trails", itemId)
|
|
case string(util.ListFeed):
|
|
item, err = e.App.FindRecordById("lists", itemId)
|
|
case string(util.SummitLogFeed):
|
|
item, err = e.App.FindRecordById("summit_logs", itemId)
|
|
}
|
|
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
if item == nil {
|
|
continue
|
|
}
|
|
|
|
errs := e.App.ExpandRecord(item, []string{"author"}, nil)
|
|
if len(errs) > 0 {
|
|
return fmt.Errorf("failed to expand author: %v", errs)
|
|
}
|
|
|
|
if typ == string(util.TrailFeed) {
|
|
errs := e.App.ExpandRecord(item, []string{"category"}, nil)
|
|
if len(errs) > 0 {
|
|
return fmt.Errorf("failed to expand category: %v", errs)
|
|
}
|
|
}
|
|
|
|
r.MergeExpand(map[string]any{"item": item})
|
|
}
|
|
return e.Next()
|
|
}
|
|
}
|