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
|
@ -1,35 +1,23 @@
|
|||
package activitypub
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
webutils "git.mstar.dev/mstar/goutils/http"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/activitypub"
|
||||
"git.mstar.dev/mstar/linstrom/config"
|
||||
"git.mstar.dev/mstar/linstrom/activitypub/translators"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new"
|
||||
"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 activityAccept(w http.ResponseWriter, r *http.Request) {
|
||||
log := hlog.FromRequest(r)
|
||||
id := r.PathValue("id")
|
||||
activity, err := CreateFromStorage(r.Context(), id)
|
||||
activity, err := translators.CreateFromStorage(r.Context(), id)
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
|
@ -52,32 +40,3 @@ func activityAccept(w http.ResponseWriter, r *http.Request) {
|
|||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
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