diff --git a/activitypub/importNote.go b/activitypub/importNote.go index b451a1d..5f71bae 100644 --- a/activitypub/importNote.go +++ b/activitypub/importNote.go @@ -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 } diff --git a/activitypub/translators/media.go b/activitypub/translators/media.go index 2ca177d..654f591 100644 --- a/activitypub/translators/media.go +++ b/activitypub/translators/media.go @@ -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 } diff --git a/activitypub/translators/user.go b/activitypub/translators/user.go index 4083c7e..a240a77 100644 --- a/activitypub/translators/user.go +++ b/activitypub/translators/user.go @@ -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 { diff --git a/storage-new/models/Role.go b/storage-new/models/Role.go index eb7dc71..44f6145 100644 --- a/storage-new/models/Role.go +++ b/storage-new/models/Role.go @@ -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 diff --git a/storage-new/models/RolesDefaults.go b/storage-new/models/RolesDefaults.go index f5b0479..6d55b50 100644 --- a/storage-new/models/RolesDefaults.go +++ b/storage-new/models/RolesDefaults.go @@ -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, diff --git a/web/debug/posts.go b/web/debug/posts.go index 75f0bff..f32680c 100644 --- a/web/debug/posts.go +++ b/web/debug/posts.go @@ -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), diff --git a/web/public/api/activitypub/activityLike.go b/web/public/api/activitypub/activityLike.go index 7c30024..a7dfd70 100644 --- a/web/public/api/activitypub/activityLike.go +++ b/web/public/api/activitypub/activityLike.go @@ -1 +1,5 @@ package activitypub + +import "net/http" + +func activityLike(w http.ResponseWriter, r *http.Request) {} diff --git a/web/public/api/activitypub/objectEmote.go b/web/public/api/activitypub/objectEmote.go new file mode 100644 index 0000000..df2c00a --- /dev/null +++ b/web/public/api/activitypub/objectEmote.go @@ -0,0 +1,5 @@ +package activitypub + +import "net/http" + +func objectEmote(w http.ResponseWriter, r *http.Request) {} diff --git a/web/public/api/activitypub/server.go b/web/public/api/activitypub/server.go index bc9fbd4..fbc6335 100644 --- a/web/public/api/activitypub/server.go +++ b/web/public/api/activitypub/server.go @@ -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 } diff --git a/web/shared/clientRfc9421.go b/web/shared/clientRfc9421.go index c306611..7b142a8 100644 --- a/web/shared/clientRfc9421.go +++ b/web/shared/clientRfc9421.go @@ -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 {