Move translators db->ap to separate module
This commit is contained in:
parent
cfe5047433
commit
d86ad370df
16 changed files with 456 additions and 423 deletions
48
activitypub/translators/accept.go
Normal file
48
activitypub/translators/accept.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package translators
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/config"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||
)
|
||||
|
||||
type ActivityAcceptOut struct {
|
||||
Context any `json:"@context,omitempty"`
|
||||
Id string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Actor string `json:"actor"`
|
||||
Object any `json:"object"`
|
||||
}
|
||||
|
||||
func AcceptFromStorage(ctx context.Context, id string) (*ActivityAcceptOut, error) {
|
||||
a := dbgen.Activity
|
||||
activity, err := a.Where(a.Id.Eq(id), a.Type.Eq(string(models.ActivityAccept))).First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// switch activity.ObjectType {
|
||||
// case models.ActivitystreamsActivityTargetFollow:
|
||||
// default:
|
||||
// return nil, errors.New("unknown activity target type")
|
||||
// }
|
||||
follow, err := FollowFromStorage(ctx, activity.ObjectId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var outId string
|
||||
if strings.HasPrefix(id, "http") {
|
||||
outId = id
|
||||
} else {
|
||||
outId = fmt.Sprintf("%s/api/activitypub/activity/accept/%s", config.GlobalConfig.General.GetFullPublicUrl(), id)
|
||||
}
|
||||
return &ActivityAcceptOut{
|
||||
Id: outId,
|
||||
Actor: follow.Object.(string),
|
||||
Type: "Accept",
|
||||
Object: follow,
|
||||
}, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue