Move translators db->ap to separate module

This commit is contained in:
Melody Becker 2025-06-13 13:42:56 +02:00
parent cfe5047433
commit d86ad370df
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
16 changed files with 456 additions and 423 deletions

View file

@ -0,0 +1,58 @@
package translators
import (
"context"
"git.mstar.dev/mstar/linstrom/config"
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
"git.mstar.dev/mstar/linstrom/storage-new/models"
)
type ActivityCreate struct {
Context any `json:"@context,omitempty"`
Id string `json:"id"`
Type string `json:"type"`
Actor string `json:"actor"`
Object any `json:"object"`
}
// Find a create activity from the db and format it for activitypub reads
// Does not set the context for the activity, in case the activity is embedded
// in another activity or object. That's the responsibility of the handler
// getting the final result
func CreateFromStorage(ctx context.Context, id string) (*ActivityCreate, error) {
// log := log.Ctx(ctx)
a := dbgen.Activity
activity, err := a.Where(a.Type.Eq(string(models.ActivityCreate))).
Where(a.Id.Eq(id)).
First()
if err != nil {
return nil, err
}
switch models.ActivitystreamsActivityTargetType(activity.ObjectType) {
case models.ActivitystreamsActivityTargetNote:
note, err := NoteFromStorage(ctx, activity.ObjectId)
if err != nil {
return nil, err
}
out := ActivityCreate{
Id: config.GlobalConfig.General.GetFullPublicUrl() + "/api/activitypub/create/" + id,
Type: "Create",
Actor: note.AttributedTo,
Object: note,
}
return &out, nil
case models.ActivitystreamsActivityTargetBoost:
panic("Not implemented")
case models.ActivitystreamsActivityTargetReaction:
panic("Not implemented")
case models.ActivitystreamsActivityTargetActivity:
panic("Not implemented")
case models.ActivitystreamsActivityTargetUser:
panic("Not implemented")
case models.ActivitystreamsActivityTargetUnknown:
panic("Not implemented")
default:
panic("Not implemented")
}
}