MCPcopy
hub / github.com/writefreely/writefreely / handleGopherCollection

Function handleGopherCollection

gopher.go:76–129  ·  view source on GitHub ↗
(app *App, w gopher.ResponseWriter, r *gopher.Request)

Source from the content-addressed store, hash-verified

74}
75
76func handleGopherCollection(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
77 var collAlias, slug string
78 var c *Collection
79 var err error
80 var baseSel = "/"
81
82 parts := strings.Split(r.Selector, "/")
83 if app.cfg.App.SingleUser {
84 // sanity check
85 slug = parts[1]
86 if slug != "" {
87 return handleGopherCollectionPost(app, w, r)
88 }
89
90 c, err = app.db.GetCollectionByID(1)
91 if err != nil {
92 return err
93 }
94 } else {
95 collAlias = parts[1]
96 slug = parts[2]
97 if slug != "" {
98 return handleGopherCollectionPost(app, w, r)
99 }
100
101 c, err = app.db.GetCollection(collAlias)
102 if err != nil {
103 return err
104 }
105 baseSel = "/" + c.Alias + "/"
106 }
107 c.hostName = app.cfg.App.Host
108
109 w.WriteInfo(c.DisplayTitle())
110 if c.Description != "" {
111 w.WriteInfo(c.Description)
112 }
113
114 posts, err := app.db.GetPosts(app.cfg, c, 0, false, false, false, "")
115 if err != nil {
116 return err
117 }
118
119 for _, p := range *posts {
120 w.WriteItem(&gopher.Item{
121 Port: app.cfg.Server.GopherPort,
122 Host: stripHostProtocol(app),
123 Type: gopher.FILE,
124 Description: p.CreatedDate() + " - " + p.DisplayTitle(),
125 Selector: baseSel + p.Slug.String,
126 })
127 }
128 return w.End()
129}
130
131func handleGopherCollectionPost(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
132 var collAlias, slug string

Callers 1

handleGopherFunction · 0.85

Calls 8

DisplayTitleMethod · 0.95
stripHostProtocolFunction · 0.85
CreatedDateMethod · 0.80
GetCollectionByIDMethod · 0.65
GetCollectionMethod · 0.65
GetPostsMethod · 0.65
DisplayTitleMethod · 0.45

Tested by

no test coverage detected