diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-07-20 13:01:32 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-07-20 13:01:32 -0400 |
commit | 33a759d08dc1d1119699fffc7c35efc8e031778d (patch) | |
tree | b15e9df3442cae02a7ef946aa5334091bb485b32 | |
parent | a8c7b3c928a220565a34d2d3a6ffc4f69d9e10ae (diff) | |
download | jdtalk_web-33a759d08dc1d1119699fffc7c35efc8e031778d.tar.gz |
Implement "salad" mode
-rw-r--r-- | source/app.d | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/source/app.d b/source/app.d index 7d557c9..b3f0c09 100644 --- a/source/app.d +++ b/source/app.d @@ -10,6 +10,7 @@ import std.conv : to; enum MAX_LIMIT = 100_000; enum MAX_LIMIT_PATTERN = 100; +enum MAX_LIMIT_SALAD = 512; __gshared string dataRoot; __gshared dict_t dicts; @@ -20,10 +21,17 @@ void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res) auto limit = req.query.get("limit", "1").to!long; auto pattern = req.query.get("pattern", null); auto exactMatch = req.query.get("exact", "false").to!bool; + auto salad = req.query.get("salad", "0").to!int; auto rCase = req.query.get("rcase", "false").to!bool; auto hCase = req.query.get("hcase", "false").to!bool; auto haxor = req.query.get("leet", "false").to!bool; + if (salad > MAX_LIMIT_SALAD) { + res.bodyWriter.write(format("Requested too much salad: %d (MAX: %d)\n", + salad, MAX_LIMIT_SALAD)); + return; + } + if (pattern is null && limit > MAX_LIMIT) { res.bodyWriter.write(format("Requested too many: %d (MAX: %d)\n", limit, MAX_LIMIT)); @@ -41,7 +49,14 @@ void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res) } while(true) { - string output = talk(dicts); + string output; + + if (salad) { + output = talkSalad(dicts, salad); + } + else { + output = talk(dicts); + } if (pattern !is null) { if (exactMatch && !hasWord(pattern, output)) { |