handleViewCollection displays the requested Collection
(app *App, w http.ResponseWriter, r *http.Request)
| 855 | |
| 856 | // handleViewCollection displays the requested Collection |
| 857 | func 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) |
no test coverage detected