* initial commit * update api docs * adds search token versioning * make id filterable * isLocal -> is_local * add iri to actor index * update gitignore * Merge remote-tracking branch 'origin/main' into feat-add-actors-to-meilisearch * fix sharing for newly discovered actors * fix ActorSearchResult type --------- Co-authored-by: Christian Beutel <>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
"pocketbase/util"
|
|
|
|
"github.com/meilisearch/meilisearch-go"
|
|
"github.com/pocketbase/pocketbase/core"
|
|
)
|
|
|
|
func SearchToken(client meilisearch.ServiceManager) func(e *core.RequestEvent) error {
|
|
return func(e *core.RequestEvent) error {
|
|
searchRules := map[string]interface{}{
|
|
"lists": map[string]string{"filter": "public = true"},
|
|
"trails": map[string]string{"filter": "public = true"},
|
|
}
|
|
|
|
if e.Auth != nil {
|
|
userActor, err := e.App.FindFirstRecordByData("activitypub_actors", "user", e.Auth.Id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
searchRules = map[string]any{
|
|
"lists": map[string]string{
|
|
"filter": "public = true OR author = " + userActor.Id + " OR shares = " + userActor.Id,
|
|
},
|
|
"trails": map[string]string{
|
|
"filter": "public = true OR author = " + userActor.Id + " OR shares = " + userActor.Id,
|
|
},
|
|
"actors": map[string]string{},
|
|
}
|
|
}
|
|
|
|
token, err := util.GenerateMeilisearchToken(searchRules, client)
|
|
if err != nil {
|
|
return e.InternalServerError("Failed to generate search token", err)
|
|
}
|
|
|
|
return e.JSON(http.StatusOK, map[string]string{
|
|
"token": token,
|
|
})
|
|
}
|
|
}
|