MCPcopy
hub / github.com/writefreely/writefreely / handleViewPad

Function handleViewPad

pad.go:23–121  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

21)
22
23func handleViewPad(app *App, w http.ResponseWriter, r *http.Request) error {
24 vars := mux.Vars(r)
25 action := vars["action"]
26 slug := vars["slug"]
27 collAlias := vars["collection"]
28 if app.cfg.App.SingleUser {
29 // TODO: refactor all of this, especially for single-user blogs
30 c, err := app.db.GetCollectionByID(1)
31 if err != nil {
32 return err
33 }
34 collAlias = c.Alias
35 }
36 appData := &struct {
37 page.StaticPage
38 Post *RawPost
39 User *User
40 Blogs *[]Collection
41 Silenced bool
42
43 Editing bool // True if we're modifying an existing post
44 EditCollection *Collection // Collection of the post we're editing, if any
45 }{
46 StaticPage: pageForReq(app, r),
47 Post: &RawPost{Font: "norm"},
48 User: getUserSession(app, r),
49 }
50 var err error
51 if appData.User != nil {
52 appData.Blogs, err = app.db.GetPublishableCollections(appData.User, app.cfg.App.Host)
53 if err != nil {
54 log.Error("Unable to get user's blogs for Pad: %v", err)
55 }
56 appData.Silenced, err = app.db.IsUserSilenced(appData.User.ID)
57 if err != nil {
58 if err == ErrUserNotFound {
59 return err
60 }
61 log.Error("Unable to get user status for Pad: %v", err)
62 }
63 }
64
65 padTmpl := app.cfg.App.Editor
66 if templates[padTmpl] == nil {
67 if padTmpl != "" {
68 log.Info("No template '%s' found. Falling back to default 'pad' template.", padTmpl)
69 }
70 padTmpl = "pad"
71 }
72
73 if action == "" && slug == "" {
74 // Not editing any post; simply render the Pad
75 if err = templates[padTmpl].ExecuteTemplate(w, "pad", appData); err != nil {
76 log.Error("Unable to execute template: %v", err)
77 }
78
79 return nil
80 }

Callers 1

handleViewHomeFunction · 0.85

Calls 8

pageForReqFunction · 0.85
getUserSessionFunction · 0.85
getRawCollectionPostFunction · 0.85
getRawPostFunction · 0.85
IsUserSilencedMethod · 0.80
GetCollectionByIDMethod · 0.65
GetCollectionForPadMethod · 0.65

Tested by

no test coverage detected