(app *App, w http.ResponseWriter, r *http.Request)
| 1123 | } |
| 1124 | |
| 1125 | func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error { |
| 1126 | var collID int64 |
| 1127 | var coll *Collection |
| 1128 | var err error |
| 1129 | vars := mux.Vars(r) |
| 1130 | if collAlias := vars["alias"]; collAlias != "" { |
| 1131 | // Fetch collection information, since an alias is provided |
| 1132 | coll, err = app.db.GetCollection(collAlias) |
| 1133 | if err != nil { |
| 1134 | return err |
| 1135 | } |
| 1136 | collID = coll.ID |
| 1137 | } |
| 1138 | |
| 1139 | p, err := app.db.GetPost(vars["post"], collID) |
| 1140 | if err != nil { |
| 1141 | return err |
| 1142 | } |
| 1143 | if coll == nil && p.CollectionID.Valid { |
| 1144 | // Collection post is getting fetched by post ID, not coll alias + post slug, so get coll info now. |
| 1145 | coll, err = app.db.GetCollectionByID(p.CollectionID.Int64) |
| 1146 | if err != nil { |
| 1147 | return err |
| 1148 | } |
| 1149 | } |
| 1150 | if coll != nil { |
| 1151 | coll.hostName = app.cfg.App.Host |
| 1152 | _, err = apiCheckCollectionPermissions(app, r, coll) |
| 1153 | if err != nil { |
| 1154 | return err |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | silenced, err := app.db.IsUserSilenced(p.OwnerID.Int64) |
| 1159 | if err != nil { |
| 1160 | log.Error("fetch post: %v", err) |
| 1161 | } |
| 1162 | if silenced { |
| 1163 | return ErrPostNotFound |
| 1164 | } |
| 1165 | |
| 1166 | p.extractData() |
| 1167 | |
| 1168 | if IsActivityPubRequest(r) { |
| 1169 | if coll == nil { |
| 1170 | // This is a draft post; 404 for now |
| 1171 | // TODO: return ActivityObject |
| 1172 | return impart.HTTPError{http.StatusNotFound, ""} |
| 1173 | } |
| 1174 | |
| 1175 | p.Collection = &CollectionObj{Collection: *coll} |
| 1176 | po := p.ActivityObject(app) |
| 1177 | po.Context = []interface{}{activitystreams.Namespace} |
| 1178 | setCacheControl(w, apCacheTime) |
| 1179 | return impart.RenderActivityJSON(w, po, http.StatusOK) |
| 1180 | } |
| 1181 | |
| 1182 | return impart.WriteSuccess(w, p, http.StatusOK) |
nothing calls this directly
no test coverage detected