package activitypub import ( "encoding/json" "fmt" "net/http" 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/activitypub/translators" "git.mstar.dev/mstar/linstrom/storage-new" ) func activityFollow(w http.ResponseWriter, r *http.Request) { log := hlog.FromRequest(r) id := r.PathValue("id") activity, err := translators.FollowFromStorage(r.Context(), id) switch err { case gorm.ErrRecordNotFound: _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) case nil: activity.Context = activitypub.BaseLdContext data, err := json.Marshal(activity) if err != nil { log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity") _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) return } w.Header().Add("Content-Type", "application/activity+json") _, _ = fmt.Fprint(w, string(data)) default: if storage.HandleReconnectError(err) { log.Error().Err(err).Msg("Connection failed, restart attempt started") } else { log.Error().Err(err).Msg("Failed to get create activity from db") } _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) } }