MCPcopy
hub / github.com/writefreely/writefreely / fetchCollectionPosts

Function fetchCollectionPosts

collections.go:585–628  ·  view source on GitHub ↗

fetchCollectionPosts handles an API endpoint for retrieving a collection's posts.

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

Source from the content-addressed store, hash-verified

583// fetchCollectionPosts handles an API endpoint for retrieving a collection's
584// posts.
585func fetchCollectionPosts(app *App, w http.ResponseWriter, r *http.Request) error {
586 vars := mux.Vars(r)
587 alias := vars["alias"]
588
589 c, err := app.db.GetCollection(alias)
590 if err != nil {
591 return err
592 }
593 c.hostName = app.cfg.App.Host
594
595 // Check permissions
596 userID, err := apiCheckCollectionPermissions(app, r, c)
597 if err != nil {
598 return err
599 }
600 isCollOwner := userID == c.OwnerID
601
602 // Get page
603 page := 1
604 if p := r.FormValue("page"); p != "" {
605 pInt, _ := strconv.Atoi(p)
606 if pInt > 0 {
607 page = pInt
608 }
609 }
610
611 ps, err := app.db.GetPosts(app.cfg, c, page, isCollOwner, false, false, "")
612 if err != nil {
613 return err
614 }
615 coll := &CollectionObj{Collection: *c, Posts: ps}
616 app.db.GetPostsCount(coll, isCollOwner)
617 // Strip non-public information
618 coll.Collection.ForPublic()
619
620 // Transform post bodies if needed
621 if r.FormValue("body") == "html" {
622 for _, p := range *coll.Posts {
623 p.Content = posts.ApplyMarkdown([]byte(p.Content))
624 }
625 }
626
627 return impart.WriteSuccess(w, coll, http.StatusOK)
628}
629
630type CollectionPage struct {
631 page.StaticPage

Callers

nothing calls this directly

Calls 5

ForPublicMethod · 0.80
GetCollectionMethod · 0.65
GetPostsMethod · 0.65
GetPostsCountMethod · 0.65

Tested by

no test coverage detected