26 | 26 |
user <- Web.getUser c (lookup HTTP.hCookie (W.requestHeaders req))
|
27 | 27 |
case (W.requestMethod req, W.pathInfo req) of
|
28 | 28 |
("GET", []) -> do
|
29 | |
post <- DB.runDB DB.newestPostRef c
|
| 29 |
post <- DB.runDB c DB.newestPostRef
|
30 | 30 |
Web.redirect (postRefURL post)
|
31 | 31 |
|
32 | 32 |
("POST", []) ->
|
|
50 | 50 |
Log.error [ "bad input data somehow" ]
|
51 | 51 |
Web.redirect "/"
|
52 | 52 |
Just rp -> do
|
53 | |
DB.runDB (DB.submitPost (User u) rp) c
|
| 53 |
DB.runDB c (DB.submitPost (User u) rp)
|
54 | 54 |
Web.redirect "/newest"
|
55 | 55 |
|
56 | 56 |
("GET", ["auth"]) -> do
|
|
58 | 58 |
Web.ok user "login" password
|
59 | 59 |
|
60 | 60 |
("GET", ["archive"]) -> do
|
61 | |
posts <- DB.runDB DB.allPostRefs c
|
| 61 |
posts <- DB.runDB c DB.allPostRefs
|
62 | 62 |
contents <- Template.list posts
|
63 | 63 |
Web.ok user "Past Entries" contents
|
64 | 64 |
|
|
70 | 70 |
Web.ok user "New Post" contents
|
71 | 71 |
|
72 | 72 |
("GET", [y, m, s]) -> do
|
73 | |
(post, cached) <- flip DB.runDB c $ do
|
| 73 |
(post, cached) <- DB.runDB c $ do
|
74 | 74 |
ps <- DB.postByDateAndSlug y m s
|
75 | 75 |
ch <- DB.cachedMarkup (postId ps)
|
76 | 76 |
pure (ps, ch)
|
|
79 | 79 |
Web.ok user (T.fromStrict (postTitle post)) cache
|
80 | 80 |
Nothing -> do
|
81 | 81 |
contents <- Template.post user post
|
82 | |
DB.runDB (DB.storeCachedMarkup (postId post) contents) c
|
| 82 |
DB.runDB c (DB.storeCachedMarkup (postId post) contents)
|
83 | 83 |
Web.ok user (T.fromStrict (postTitle post)) contents
|
84 | 84 |
|
85 | 85 |
("POST", [y, m, s]) ->
|
|
89 | 89 |
Web.redirect "/"
|
90 | 90 |
Just u -> do
|
91 | 91 |
formData <- Web.formData req
|
92 | |
oldPost <- DB.runDB (DB.postByDateAndSlug y m s) c
|
| 92 |
oldPost <- DB.runDB c (DB.postByDateAndSlug y m s)
|
93 | 93 |
let rpMb = do
|
94 | 94 |
title <- join (lookup "title" formData)
|
95 | 95 |
contents <- join (lookup "contents" formData)
|
|
104 | 104 |
Log.error [ "bad input data somehow" ]
|
105 | 105 |
Web.redirect "/"
|
106 | 106 |
Just rp -> do
|
107 | |
DB.runDB (DB.submitPost (User u) rp) c
|
| 107 |
DB.runDB c (DB.submitPost (User u) rp)
|
108 | 108 |
Web.redirect (postURL oldPost)
|
109 | 109 |
|
110 | 110 |
("GET", [y, m, s, "edit"]) ->
|
|
113 | 113 |
Log.error [ "non-logged-in user attempted to edit post" ]
|
114 | 114 |
Web.redirect "/"
|
115 | 115 |
Just {} -> do
|
116 | |
oldPost <- DB.runDB (DB.postByDateAndSlug y m s) c
|
| 116 |
oldPost <- DB.runDB c (DB.postByDateAndSlug y m s)
|
117 | 117 |
contents <- Template.edit (postURL oldPost) (postToRawPost oldPost)
|
118 | 118 |
Web.ok user (T.fromStrict (postTitle oldPost)) contents
|
119 | 119 |
|
|
122 | 122 |
Nothing -> Web.redirect "/"
|
123 | 123 |
Just _ -> do
|
124 | 124 |
Log.warn [ "deleting post:", show (y, m, s) ]
|
125 | |
flip DB.runDB c $ do
|
| 125 |
DB.runDB c $ do
|
126 | 126 |
post <- DB.postByDateAndSlug y m s
|
127 | 127 |
DB.deletePost (postToRawPost post)
|
128 | 128 |
Web.redirect "/"
|
|
131 | 131 |
case user of
|
132 | 132 |
Nothing -> Web.redirect "/"
|
133 | 133 |
Just _ -> do
|
134 | |
post <- DB.runDB (DB.postByDateAndSlug y m s) c
|
| 134 |
post <- DB.runDB c (DB.postByDateAndSlug y m s)
|
135 | 135 |
contents <- Template.delete post
|
136 | 136 |
Web.ok user "Delete Post?" contents
|
137 | 137 |
|
|
156 | 156 |
Web.redirectWithCookies "/" [("USERDATA", "")]
|
157 | 157 |
|
158 | 158 |
("GET", ["newest"]) -> do
|
159 | |
post <- DB.runDB DB.newestPostRef c
|
| 159 |
post <- DB.runDB c DB.newestPostRef
|
160 | 160 |
Web.redirect (postRefURL post)
|
161 | 161 |
|
162 | 162 |
("GET", ["oldest"]) -> do
|
163 | |
post <- DB.runDB DB.oldestPostRef c
|
| 163 |
post <- DB.runDB c DB.oldestPostRef
|
164 | 164 |
Web.redirect (postRefURL post)
|
165 | 165 |
|
166 | 166 |
("GET", ["static", fp]) ->
|
|
168 | 168 |
in pure (W.responseFile HTTP.status200 [] path Nothing)
|
169 | 169 |
|
170 | 170 |
("GET", ["rss"]) -> do
|
171 | |
posts <- DB.runDB DB.allPosts c
|
| 171 |
posts <- DB.runDB c DB.allPosts
|
172 | 172 |
feed <- Feed.renderFeed posts
|
173 | 173 |
Web.atomFeed feed
|
174 | 174 |
|
175 | 175 |
("GET", [pagename]) -> do
|
176 | |
pg <- DB.runDB (DB.staticPage pagename) c
|
| 176 |
pg <- DB.runDB c (DB.staticPage pagename)
|
177 | 177 |
contents <- Template.page (pageText pg)
|
178 | 178 |
Web.ok user (T.fromStrict pagename) contents
|
179 | 179 |
|