Work on AP-ing media and extending likes and whatnot
All checks were successful
/ docker (push) Successful in 1m56s

Also added two fields to roles model, but haven't ran the various
generators yet
This commit is contained in:
Melody Becker 2025-06-18 17:01:31 +02:00
parent 1fcf47bffc
commit 81a01fbf8b
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
10 changed files with 59 additions and 4 deletions

View file

@ -177,6 +177,12 @@ func importRemoteNoteRecursive(
// In which case, you need to remove tags that don't exist anymore
// and only create the ones not yet stored
err = dbgen.NoteToPing.Save(pings...)
if err != nil {
return "", err
}
err = dbgen.NoteTag.Save(hashtags...)
if err != nil {
return "", err
}
return dbNote.ID, nil
}

View file

@ -2,7 +2,9 @@ package translators
import (
"context"
"strings"
"git.mstar.dev/mstar/linstrom/config"
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
)
@ -10,17 +12,39 @@ type Media struct {
Type string `json:"type"`
Url string `json:"url"`
MediaType string `json:"mediaType"`
Name string `json:"name"`
Summary string `json:"summary"`
Sensitive bool `json:"sensitive"`
}
func MediaFromStorage(ctx context.Context, id string) (*Media, error) {
metadata, err := dbgen.MediaMetadata.Where(dbgen.MediaMetadata.ID.Eq(id)).First()
metadata, err := dbgen.MediaMetadata.Where(dbgen.MediaMetadata.ID.Eq(id), dbgen.MediaMetadata.Remote.Is(false)).
First()
if err != nil {
return nil, err
}
data := Media{
Type: "Image", // FIXME: Change this to a sort of dynamic detection based on mimetype
MediaType: metadata.Type,
Url: metadata.Location,
Url: config.GlobalConfig.General.GetFullPublicUrl() + "/media/" + id,
Name: metadata.AltText,
Summary: metadata.AltText,
Sensitive: metadata.Blurred,
}
switch strings.SplitN(metadata.Type, "/", 2)[0] {
case "audio":
data.Type = "Audio"
case "application":
data.Type = "Document"
case "image":
data.Type = "Image"
case "video":
data.Type = "Video"
case "text":
data.Type = "Document"
case "font":
data.Type = "Document"
default:
data.Type = "Document"
}
return &data, nil
}

View file

@ -51,6 +51,9 @@ func UserFromStorage(ctx context.Context, id string) (*User, error) {
Preload(dbgen.User.Icon).Preload(dbgen.User.Banner).
Preload(dbgen.User.BeingTypes).
First()
if err != nil {
return nil, err
}
err = storage.EnsureLocalUserIdHasLinks(id)
if err != nil {

View file

@ -85,6 +85,9 @@ type Role struct {
HasMentionCountLimit *bool // Local & remote
MentionLimit *uint32 // Local & remote
MaxIndividualFileSize *uint64 // Local
MaxTotalFileSize *uint64 // Local
// CanViewBoosts *bool
// CanViewQuotes *bool
// CanViewMedia *bool

View file

@ -42,6 +42,9 @@ var DefaultUserRole = Role{
uint32(math.MaxUint32),
), // Set this to max, even if not used due to *HasMentionCountLimit == false
MaxIndividualFileSize: other.IntoPointer(uint64(10 << 20)), // 10 MB
MaxTotalFileSize: other.IntoPointer(uint64(500 << 20)), // 500 MB
AutoNsfwMedia: other.IntoPointer(false),
AutoCwPosts: other.IntoPointer(false),
AutoCwPostsText: nil,

View file

@ -122,6 +122,11 @@ func postAs(w http.ResponseWriter, r *http.Request) {
return
}
err = tx.NoteToPing.Create(dbPings...)
if err != nil {
log.Error().Err(err).Msg("Failed to create note pings in db")
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
activity := models.Activity{
Id: shared.NewId(),
Type: string(models.ActivityCreate),

View file

@ -1 +1,5 @@
package activitypub
import "net/http"
func activityLike(w http.ResponseWriter, r *http.Request) {}

View file

@ -0,0 +1,5 @@
package activitypub
import "net/http"
func objectEmote(w http.ResponseWriter, r *http.Request) {}

View file

@ -16,7 +16,9 @@ func BuildActivitypubRouter() http.Handler {
router.HandleFunc("GET /activity/reject/{id}", activityReject)
router.HandleFunc("GET /activity/update/{id}", activityUpdate)
router.HandleFunc("GET /activity/follow/{id}", activityFollow)
router.HandleFunc("GET /activity/like/{id}", activityLike)
router.HandleFunc("GET /note/{id}", objectNote)
router.HandleFunc("GET /note/{id}/reactions", noteReactions)
router.HandleFunc("GET /emote/{id}", objectEmote)
return router
}

View file

@ -236,7 +236,7 @@ func postPostRequest(resp *http.Response, reqErr error, dbId uint64) {
// If response status is ok (< 400) delete entry in db to not process it again
if resp.StatusCode < 400 {
update = false
fr.Where(fr.Id.Eq(dbId)).Delete()
_, _ = fr.Where(fr.Id.Eq(dbId)).Delete()
return
}
if resp.StatusCode == 429 {