mirror of
https://github.com/FraMecca/Buridans_donkey.git
synced 2024-03-20 11:20:15 +01:00
web version
This commit is contained in:
parent
770ce66a7e
commit
60273209e0
4 changed files with 122 additions and 0 deletions
15
web/.gitignore
vendored
Normal file
15
web/.gitignore
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
.dub
|
||||||
|
docs.json
|
||||||
|
__dummy.html
|
||||||
|
docs/
|
||||||
|
/web
|
||||||
|
web.so
|
||||||
|
web.dylib
|
||||||
|
web.dll
|
||||||
|
web.a
|
||||||
|
web.lib
|
||||||
|
web-test-*
|
||||||
|
*.exe
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.lst
|
8
web/dub.sdl
Normal file
8
web/dub.sdl
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
name "web"
|
||||||
|
description "Asino web version"
|
||||||
|
authors "danseraf"
|
||||||
|
copyright "Copyright © 2019, danseraf"
|
||||||
|
license "GPLv3"
|
||||||
|
dependency "vibe-d" version="~>0.8.5"
|
||||||
|
versions "VibeDefaultMain"
|
||||||
|
dflags "-J view/"
|
19
web/dub.selections.json
Normal file
19
web/dub.selections.json
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"fileVersion": 1,
|
||||||
|
"versions": {
|
||||||
|
"botan": "1.12.10",
|
||||||
|
"botan-math": "1.0.3",
|
||||||
|
"diet-ng": "1.5.0",
|
||||||
|
"eventcore": "0.8.42",
|
||||||
|
"libasync": "0.8.4",
|
||||||
|
"libevent": "2.0.2+2.0.16",
|
||||||
|
"memutils": "0.4.13",
|
||||||
|
"mir-linux-kernel": "1.0.1",
|
||||||
|
"openssl": "1.1.6+1.0.1g",
|
||||||
|
"stdx-allocator": "2.77.5",
|
||||||
|
"sumtype": "0.8.6",
|
||||||
|
"taggedalgebraic": "0.11.4",
|
||||||
|
"vibe-core": "1.6.2",
|
||||||
|
"vibe-d": "0.8.5"
|
||||||
|
}
|
||||||
|
}
|
80
web/source/app.d
Normal file
80
web/source/app.d
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
import vibe.appmain;
|
||||||
|
import vibe.http.server;
|
||||||
|
import std.stdio;
|
||||||
|
import std.range;
|
||||||
|
import std.string;
|
||||||
|
import std.exception;
|
||||||
|
import std.array;
|
||||||
|
import std.random;
|
||||||
|
import std.file;
|
||||||
|
|
||||||
|
const (string[]) shuffle(string[] args, const string t)
|
||||||
|
{
|
||||||
|
if(t == "mt"){
|
||||||
|
Mt19937 gen;
|
||||||
|
gen.seed(unpredictableSeed);
|
||||||
|
args.randomShuffle(gen);
|
||||||
|
} else if (t == "x"){
|
||||||
|
Xorshift32 gen;
|
||||||
|
gen.seed(unpredictableSeed);
|
||||||
|
args.randomShuffle(gen);
|
||||||
|
} else if (t == "du"){
|
||||||
|
auto gen = DevRandomGen!"/dev/urandom"();
|
||||||
|
args.randomShuffle(gen);
|
||||||
|
} else if (t == "dr"){
|
||||||
|
auto gen = DevRandomGen!"/dev/random"();
|
||||||
|
args.randomShuffle(gen);
|
||||||
|
} else {
|
||||||
|
throw new Exception("Wrong arguments");
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template DevRandomGen(string gen)
|
||||||
|
if (gen == "/dev/random" || gen == "/dev/urandom")
|
||||||
|
{
|
||||||
|
struct DevRandomGen
|
||||||
|
{
|
||||||
|
|
||||||
|
alias UIntType = uint;
|
||||||
|
public:
|
||||||
|
enum bool isUniformRandom = true;
|
||||||
|
enum empty = false;
|
||||||
|
/// Smallest generated value.
|
||||||
|
enum UIntType min = 0;
|
||||||
|
/// Largest generated value.
|
||||||
|
enum UIntType max = ubyte.max;
|
||||||
|
string src = gen;
|
||||||
|
|
||||||
|
void seed(UIntType x0) @safe pure nothrow @nogc {}
|
||||||
|
void popFront() @safe pure nothrow @nogc {}
|
||||||
|
|
||||||
|
@property
|
||||||
|
UIntType front() const { return (cast(ubyte[])(src.read(ubyte.sizeof)))[0]; }
|
||||||
|
|
||||||
|
@property
|
||||||
|
typeof(this) save() @safe pure nothrow @nogc { return this; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res)
|
||||||
|
{
|
||||||
|
immutable path = req.requestPath.bySegment.array;
|
||||||
|
enforce(path.length == 3); // path[0] == ""
|
||||||
|
auto engine = path[1].toString;
|
||||||
|
auto args = path[2].toString.split(",");
|
||||||
|
const result = shuffle(args, engine);
|
||||||
|
immutable body = "Asino says:</br><ul>" ~ "<li>" ~ result.join("</li><li>") ~ "</ul>";
|
||||||
|
res.headers["Content-Type"] = "text/html";
|
||||||
|
res.writeBody(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
shared static this()
|
||||||
|
{
|
||||||
|
auto settings = new HTTPServerSettings;
|
||||||
|
settings.port = 8080;
|
||||||
|
settings.bindAddresses = ["::1", "127.0.0.1"];
|
||||||
|
|
||||||
|
listenHTTP(settings, &handleRequest);
|
||||||
|
}
|
Loading…
Reference in a new issue