MCPcopy Index your code
hub / github.com/writefreely/writefreely / handleViewCollection

Function handleViewCollection

collections.go:857–1005  ·  view source on GitHub ↗

handleViewCollection displays the requested Collection

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

Source from the content-addressed store, hash-verified

855
856// handleViewCollection displays the requested Collection
857func handleViewCollection(app *App, w http.ResponseWriter, r *http.Request) error {
858 vars := mux.Vars(r)
859 cr := &collectionReq{}
860
861 err := processCollectionRequest(cr, vars, w, r)
862 if err != nil {
863 return err
864 }
865
866 u, err := checkUserForCollection(app, cr, r, false)
867 if err != nil {
868 return err
869 }
870
871 page := getCollectionPage(vars)
872
873 c, err := processCollectionPermissions(app, cr, u, w, r)
874 if c == nil || err != nil {
875 return err
876 }
877 c.hostName = app.cfg.App.Host
878
879 silenced, err := app.db.IsUserSilenced(c.OwnerID)
880 if err != nil {
881 log.Error("view collection: %v", err)
882 return ErrInternalGeneral
883 }
884
885 // Serve ActivityStreams data now, if requested
886 if IsActivityPubRequest(r) {
887 ac := c.PersonObject()
888 setCacheControl(w, apCacheTime)
889 return impart.RenderActivityJSON(w, ac, http.StatusOK)
890 }
891
892 // Fetch extra data about the Collection
893 // TODO: refactor out this logic, shared in collection.go:fetchCollection()
894 coll, err := newDisplayCollection(c, cr, page)
895 if err != nil {
896 return err
897 }
898
899 var ct PostType
900 if isArchiveView(r) {
901 ct = postArch
902 }
903
904 // FIXME: this number will be off when user has pinned posts but isn't a Pro user
905 ppp := coll.Format.PostsPerPage()
906 if ct == postArch {
907 ppp = postsPerArchPage
908 }
909
910 coll.TotalPages = int(math.Ceil(float64(coll.TotalPosts) / float64(ppp)))
911 if coll.TotalPages > 0 && page > coll.TotalPages {
912 redirURL := fmt.Sprintf("/page/%d", coll.TotalPages)
913 if !app.cfg.App.SingleUser {
914 redirURL = fmt.Sprintf("/%s%s%s", cr.prefix, coll.Alias, redirURL)

Callers 1

handleViewHomeFunction · 0.85

Calls 15

HoneypotFieldNameFunction · 0.92
processCollectionRequestFunction · 0.85
checkUserForCollectionFunction · 0.85
getCollectionPageFunction · 0.85
IsActivityPubRequestFunction · 0.85
setCacheControlFunction · 0.85
newDisplayCollectionFunction · 0.85
isArchiveViewFunction · 0.85
pageForReqFunction · 0.85
getSessionFlashesFunction · 0.85
canUserInviteFunction · 0.85

Tested by

no test coverage detected