aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-07-20 13:01:32 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-07-20 13:01:32 -0400
commit33a759d08dc1d1119699fffc7c35efc8e031778d (patch)
treeb15e9df3442cae02a7ef946aa5334091bb485b32 /source
parenta8c7b3c928a220565a34d2d3a6ffc4f69d9e10ae (diff)
downloadjdtalk_web-33a759d08dc1d1119699fffc7c35efc8e031778d.tar.gz
Implement "salad" mode
Diffstat (limited to 'source')
-rw-r--r--source/app.d17
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)) {