Added initial files.

This commit is contained in:
Andrew Lalis 2023-07-15 18:22:48 -04:00
parent ddff9d1cf7
commit 401859fa74
6 changed files with 114 additions and 0 deletions

17
.gitignore vendored Normal file
View File

@ -0,0 +1,17 @@
.dub
docs.json
__dummy.html
docs/
/create-schematic-gen-site
create-schematic-gen-site.so
create-schematic-gen-site.dylib
create-schematic-gen-site.dll
create-schematic-gen-site.a
create-schematic-gen-site.lib
create-schematic-gen-site-test-*
*.exe
*.pdb
*.o
*.obj
*.lst
*.jar

13
dub.json Normal file
View File

@ -0,0 +1,13 @@
{
"authors": [
"Andrew Lalis"
],
"copyright": "Copyright © 2023, Andrew Lalis",
"dependencies": {
"handy-httpd": "~>7.6.1",
"slf4d": "~>2.4.1"
},
"description": "HTTP server for generating schematic materials lists.",
"license": "proprietary",
"name": "create-schematic-gen-site"
}

9
dub.selections.json Normal file
View File

@ -0,0 +1,9 @@
{
"fileVersion": 1,
"versions": {
"handy-httpd": "7.6.1",
"httparsed": "1.2.1",
"slf4d": "2.4.1",
"streams": "3.5.0"
}
}

18
site/files.js Normal file
View File

@ -0,0 +1,18 @@
const form = document.getElementById("schematic-form");
form.onsubmit = async (e) => {
e.preventDefault();
console.log(e);
const data = new FormData(form);
console.log(data);
try {
const response = await fetch("/extracts", {
method: "POST",
body: data
});
const result = await response.json();
console.log("Success:", result);
form.reset();
} catch (error) {
console.error("Error: " + error);
}
};

20
site/index.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Schematic Materials Extractor</title>
</head>
<body>
<h1>Create Schematic Materials Extractor</h1>
<p>
Use this site to extract lists of materials from one or more schematics (that were generated by the Create mod), so that you can automatically extract all the materials from an automated storage system.
</p>
<form id="schematic-form">
<input id="schematic-file-input" name="schematics" type="file" multiple accept=".nbt" required/>
<button type="submit">Submit</button>
</form>
<script src="files.js"></script>
</body>
</html>

37
source/app.d Normal file
View File

@ -0,0 +1,37 @@
import handy_httpd;
import handy_httpd.handlers.path_delegating_handler;
import handy_httpd.handlers.file_resolving_handler;
import slf4d;
import slf4d.default_provider;
void main() {
auto provider = new shared DefaultProvider(true, Levels.INFO);
configureLoggingProvider(provider);
ServerConfig config = ServerConfig.defaultValues();
config.workerPoolSize = 3;
config.connectionQueueSize = 10;
config.port = 8100;
PathDelegatingHandler handler = new PathDelegatingHandler();
handler.addMapping("POST", "/extracts", &handleExtract);
handler.addMapping("GET", "/extracts/{extractId:uint}", &getExtract);
FileResolvingHandler fileHandler = new FileResolvingHandler("site", DirectoryResolutionStrategies.serveIndexFiles);
handler.addMapping("/**", fileHandler);
new HttpServer(handler, config).start();
}
void handleExtract(ref HttpRequestContext ctx) {
MultipartFormData data = ctx.request.readBodyAsMultipartFormData();
infoF!"Read %d files: "(data.elements.length);
import std.json;
JSONValue result = JSONValue.emptyObject;
result.object["extractId"] = JSONValue(42);
ctx.response.writeBodyString(result.toJSON(), "application/json");
}
void getExtract(ref HttpRequestContext ctx) {
infoF!"Getting extract: %d"(ctx.request.getPathParamAs!uint("extractId"));
}