MCPcopy
hub / github.com/writefreely/writefreely / handlePostIDRedirect

Function handlePostIDRedirect

read.go:267–289  ·  view source on GitHub ↗

handlePostIDRedirect handles a route where a post ID is given and redirects the user to the canonical post URL.

(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

265// handlePostIDRedirect handles a route where a post ID is given and redirects
266// the user to the canonical post URL.
267func handlePostIDRedirect(app *App, w http.ResponseWriter, r *http.Request) error {
268 vars := mux.Vars(r)
269 postID := vars["post"]
270 p, err := app.db.GetPost(postID, 0)
271 if err != nil {
272 return err
273 }
274
275 if !p.CollectionID.Valid {
276 // No collection; send to normal URL
277 // NOTE: not handling single user blogs here since this handler is only used for the Reader
278 return impart.HTTPError{http.StatusFound, app.cfg.App.Host + "/" + postID + ".md"}
279 }
280
281 c, err := app.db.GetCollectionBy("id = ?", fmt.Sprintf("%d", p.CollectionID.Int64))
282 if err != nil {
283 return err
284 }
285 c.hostName = app.cfg.App.Host
286
287 // Retrieve collection information and send user to canonical URL
288 return impart.HTTPError{http.StatusFound, c.CanonicalURL() + p.Slug.String}
289}
290
291func viewLocalTimelineFeed(app *App, w http.ResponseWriter, req *http.Request) error {
292 if !app.cfg.App.LocalTimeline {

Callers

nothing calls this directly

Calls 3

GetPostMethod · 0.65
GetCollectionByMethod · 0.65
CanonicalURLMethod · 0.45

Tested by

no test coverage detected