From 401859fa74217c5a0031271dccaaf5fe274ae261 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 15 Jul 2023 18:22:48 -0400 Subject: [PATCH] Added initial files. --- .gitignore | 17 +++++++++++++++++ dub.json | 13 +++++++++++++ dub.selections.json | 9 +++++++++ site/files.js | 18 ++++++++++++++++++ site/index.html | 20 ++++++++++++++++++++ source/app.d | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+) create mode 100644 .gitignore create mode 100644 dub.json create mode 100644 dub.selections.json create mode 100644 site/files.js create mode 100644 site/index.html create mode 100644 source/app.d diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ded541e --- /dev/null +++ b/.gitignore @@ -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 diff --git a/dub.json b/dub.json new file mode 100644 index 0000000..ce30453 --- /dev/null +++ b/dub.json @@ -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" +} \ No newline at end of file diff --git a/dub.selections.json b/dub.selections.json new file mode 100644 index 0000000..cda082b --- /dev/null +++ b/dub.selections.json @@ -0,0 +1,9 @@ +{ + "fileVersion": 1, + "versions": { + "handy-httpd": "7.6.1", + "httparsed": "1.2.1", + "slf4d": "2.4.1", + "streams": "3.5.0" + } +} diff --git a/site/files.js b/site/files.js new file mode 100644 index 0000000..3139f49 --- /dev/null +++ b/site/files.js @@ -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); + } +}; \ No newline at end of file diff --git a/site/index.html b/site/index.html new file mode 100644 index 0000000..5cc0148 --- /dev/null +++ b/site/index.html @@ -0,0 +1,20 @@ + + + + + Schematic Materials Extractor + + + +

Create Schematic Materials Extractor

+

+ 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. +

+
+ + +
+ + + + \ No newline at end of file diff --git a/source/app.d b/source/app.d new file mode 100644 index 0000000..c46acbf --- /dev/null +++ b/source/app.d @@ -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")); +}