summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChloe Kudryavtsev <toast@toastin.space>2019-03-17 01:33:02 -0400
committerChloe Kudryavtsev <toast@toastin.space>2019-03-17 01:33:02 -0400
commit81fcc472297bf5fbf46e9a7093e9049223f2c144 (patch)
tree526cf6df746e7e63c5fff9c18e1bab3b6bf549a5
parent[hash] Add unit test (diff)
Unify id and rawId
Treat them the same as put/post -> insert.
-rw-r--r--source/app.d4
-rw-r--r--source/web.d26
2 files changed, 14 insertions, 16 deletions
diff --git a/source/app.d b/source/app.d
index ea53f6f..1115524 100644
--- a/source/app.d
+++ b/source/app.d
@@ -23,8 +23,8 @@ shared static this() {
router.post("/", &post);
router.put("/:id", &put);
- router.get("/:id", &id);
- router.get("/raw/:id", &rawId);
+ router.get("/:id", &idLng);
+ router.get("/raw/:id", &idRaw);
listenHTTP(settings, router);
}
diff --git a/source/web.d b/source/web.d
index d7cd30b..c71f592 100644
--- a/source/web.d
+++ b/source/web.d
@@ -9,31 +9,29 @@ import std.functional;
RedisStorage store;
-alias put = partial!(insert, true);
-alias post = partial!(insert, false);
+alias put = partial!(insert, true);
+alias post = partial!(insert, false);
+alias idLng = partial!(id, true);
+alias idRaw = partial!(id, false);
-string idCommon(in HTTPServerRequest req) {
+void id(bool highlight, HTTPServerRequest req, HTTPServerResponse res) {
string id = req.params["id"];
- return store.get(id);
-}
+ auto data = store.get(id);
+
+ if(!highlight) {
+ res.contentType = "text/plain";
+ res.writeBody(data);
+ return;
+ }
-void id(HTTPServerRequest req, HTTPServerResponse res) {
string language = "none";
// TODO: rewrite the next two lines once #2273 is resolved
if ("lang" in req.query) language = req.query["lang"];
else if (req.query.length > 0) language = req.query.byKey.front;
- auto data = idCommon(req);
render!("code.dt", data, language)(res);
}
-void rawId(HTTPServerRequest req, HTTPServerResponse res) {
- res.contentType = "text/plain";
-
- auto data = idCommon(req);
- res.writeBody(data);
-}
-
void insert(bool put, HTTPServerRequest req, HTTPServerResponse res) {
import std.encoding;