Fix empty hostname when fetching AS post via ID

Previously, fetching ActivityStreams data about a post via
/api/posts/ID, instead of /api/collections/ALIAS/posts/SLUG wouldn't
include the instance's base URL. This fixes that.
pull/214/head
Matt Baer 5 years ago
parent 8d8e671a07
commit c81927a69f
  1. 28
      posts.go

@ -1048,11 +1048,6 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error {
if err != nil { if err != nil {
return err return err
} }
coll.hostName = app.cfg.App.Host
_, err = apiCheckCollectionPermissions(app, r, coll)
if err != nil {
return err
}
collID = coll.ID collID = coll.ID
} }
@ -1060,12 +1055,26 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error {
if err != nil { if err != nil {
return err return err
} }
if coll == nil && p.CollectionID.Valid {
// Collection post is getting fetched by post ID, not coll alias + post slug, so get coll info now.
coll, err = app.db.GetCollectionByID(p.CollectionID.Int64)
if err != nil {
return err
}
}
if coll != nil {
coll.hostName = app.cfg.App.Host
_, err = apiCheckCollectionPermissions(app, r, coll)
if err != nil {
return err
}
}
suspended, err := app.db.IsUserSuspended(p.OwnerID.Int64) suspended, err := app.db.IsUserSuspended(p.OwnerID.Int64)
if err != nil { if err != nil {
log.Error("fetch post: %v", err) log.Error("fetch post: %v", err)
return ErrInternalGeneral return ErrInternalGeneral
} }
if suspended { if suspended {
return ErrPostNotFound return ErrPostNotFound
} }
@ -1074,13 +1083,6 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error {
accept := r.Header.Get("Accept") accept := r.Header.Get("Accept")
if strings.Contains(accept, "application/activity+json") { if strings.Contains(accept, "application/activity+json") {
// Fetch information about the collection this belongs to
if coll == nil && p.CollectionID.Valid {
coll, err = app.db.GetCollectionByID(p.CollectionID.Int64)
if err != nil {
return err
}
}
if coll == nil { if coll == nil {
// This is a draft post; 404 for now // This is a draft post; 404 for now
// TODO: return ActivityObject // TODO: return ActivityObject

Loading…
Cancel
Save