diff options
| author | 2019-11-23 20:05:07 -0500 | |
|---|---|---|
| committer | 2019-11-23 20:05:07 -0500 | |
| commit | 0d81239425a20554e7f0ec2169c1d55947edc57f (patch) | |
| tree | 7cd7aa9278f644467778d00fa5febab0c33d706f | |
| parent | Move function definition to zsh style (diff) | |
Remove D stuff
| -rw-r--r-- | dub.sdl | 8 | ||||
| -rw-r--r-- | dub.selections.json | 18 | ||||
| -rw-r--r-- | source/app.d | 32 | ||||
| -rw-r--r-- | source/hash.d | 19 | ||||
| -rw-r--r-- | source/storage.d | 36 | ||||
| -rw-r--r-- | source/web.d | 86 | ||||
| -rw-r--r-- | views/code.dt | 19 | ||||
| -rw-r--r-- | views/index.dt | 41 | ||||
| -rw-r--r-- | views/layout.dt | 27 |
9 files changed, 0 insertions, 286 deletions
diff --git a/dub.sdl b/dub.sdl deleted file mode 100644 index d0ec058..0000000 --- a/dub.sdl +++ /dev/null @@ -1,8 +0,0 @@ -name "brpaste" -description "A pastebin server so fast, it burns rubber." -authors "Chloe Kudryavtsev" -copyright "Copyright © 2019, Chloe Kudryavtsev" -license "MIT" -dependency "vibe-d" version="~>0.8.6-beta" - -versions "VibeDefaultMain" diff --git a/dub.selections.json b/dub.selections.json deleted file mode 100644 index 742ef3a..0000000 --- a/dub.selections.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "fileVersion": 1, - "versions": { - "botan": "1.12.10", - "botan-math": "1.0.3", - "diet-ng": "1.5.0", - "eventcore": "0.8.43", - "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", - "taggedalgebraic": "0.11.4", - "vibe-core": "1.7.0-beta.2", - "vibe-d": "0.8.6-beta.1" - } -} diff --git a/source/app.d b/source/app.d deleted file mode 100644 index bf9af1b..0000000 --- a/source/app.d +++ /dev/null @@ -1,32 +0,0 @@ -import brpaste.web; - -import vibe.d; - -shared static this() { - // HTTP settings - auto settings = new HTTPServerSettings; - settings.port = 8080; - settings.bindAddresses = []; - - readOption("bind|b", &settings.bindAddresses, "Sets the addresses to bind to [127.0.0.1 ::1]"); - readOption("port|p", &settings.port, "Sets the port to listen on [8080]"); - if(settings.bindAddresses.empty) settings.bindAddresses = [ "127.0.0.1", "::1" ]; - - // setup router - auto router = new URLRouter; - - router.match(HTTPMethod.REPORT, "/health", &health); - router.get("/health", &health); - - router.get("/", staticTemplate!"index.dt"); - - router.post("/", &post); - router.put("/:id", &put); - - router.get("/:id/raw", &idRaw); - router.get("/:id/:lang", &idLng); - router.get("/:id", &idLng); - router.get("/raw/:id", &idRaw); // DEPRECATED - - listenHTTP(settings, router); -} diff --git a/source/hash.d b/source/hash.d deleted file mode 100644 index 5a3028e..0000000 --- a/source/hash.d +++ /dev/null @@ -1,19 +0,0 @@ -module brpaste.hash; - -pure string hash(T)(T data) { - import std.base64; - import std.digest.murmurhash; - auto hash = digest!(MurmurHash3!32)(data); - return Base64URLNoPadding.encode(hash); -} - -pure string hash(T : string)(T data) { - import std.string; - return hash(data.representation); -} - -unittest { - immutable(ubyte)[] a = [ 'b', 'r', 'p', 'a', 's', 't', 'e' ]; - string s = "brpaste"; - assert(a.hash == s.hash); -} diff --git a/source/storage.d b/source/storage.d deleted file mode 100644 index 2cfea93..0000000 --- a/source/storage.d +++ /dev/null @@ -1,36 +0,0 @@ -module brpaste.storage; - -import vibe.vibe; - -class RedisStorage { - private RedisDatabase client; - - this(URL url = URL("redis://127.0.0.1")) { - client = connectRedisDB(url); - } - - void isDown() { - enforceHTTP(healthy, HTTPStatus.serviceUnavailable, "Redis is down."); - } - - bool healthy() { - try { - client.client.ping; - } catch (Exception e) { - return false; - } - return true; - } - - auto get(in string key) { - isDown; - enforceHTTP(client.exists(key), HTTPStatus.notFound, key ~ " not found."); - return client.get(key); - } - - void put(in string key, in string data, in bool collision = false) { - isDown; - if(collision) enforceHTTP(! client.exists(key), HTTPStatus.unprocessableEntity, key ~ " already exists."); - client.set(key, data); - } -} diff --git a/source/web.d b/source/web.d deleted file mode 100644 index cc08bb4..0000000 --- a/source/web.d +++ /dev/null @@ -1,86 +0,0 @@ -module brpaste.web; - -import brpaste.hash; -import brpaste.storage; - -import vibe.vibe; - -import std.functional; -import std.regex; - -RedisStorage store; - -alias put = partial!(insert, true); -alias post = partial!(insert, false); -alias idLng = partial!(id, true); -alias idRaw = partial!(id, false); - -void id(bool highlight, HTTPServerRequest req, HTTPServerResponse res) { - string id = req.params["id"]; - auto data = store.get(id); - - if(!highlight) { - res.contentType = "text/plain"; - res.writeBody(data); - return; - } - - string language = "none"; - if ("lang" in req.params) language = req.params["lang"]; - else if ("lang" in req.query) language = req.query["lang"]; // DEPRECATED - else if (req.query.length > 0) language = req.query.byKey.front; // ditto - - render!("code.dt", data, language)(res); -} - -void insert(bool put, HTTPServerRequest req, HTTPServerResponse res) { - import std.encoding; - - enforceHTTP("data" in req.form, HTTPStatus.badRequest, "Missing data field."); - string data = req.form["data"]; - enforceHTTP(data.isValid, HTTPStatus.unsupportedMediaType, "Content contains binary."); - auto hash = put ? req.params["id"] : data.hash; - store.put(hash, data, put); - - auto ua = req.headers.get("User-Agent", ""); - if(ua.isBrowser) { - // TODO: eventually move back to registerWebInterface for redirect() - res.statusCode = HTTPStatus.seeOther; - res.headers["Location"] = "/%s".format(hash); - res.writeBody(""); - } else { - res.statusCode = HTTPStatus.created; - res.writeBody(hash); - } -} - -void health(HTTPServerRequest req, HTTPServerResponse res) { - res.statusCode = HTTPStatus.noContent; - scope(success) res.writeBody(""); - - // Redis - store.isDown; -} - -// tries to match User-Agent against known browsers -static bool isBrowser(string ua) { - foreach (r; [ - "Firefox/", - "Chrome/", - "Safari/", - "OPR/", - "Edge/", - "Trident/" - ]) { - if(ua.matchFirst(r)) return true; - } - return false; -} - -shared static this() { - // setup redis - string path; - readOption("redis|r", &path, "The URL to use to connect to redis"); - store = path.empty ? new RedisStorage : new RedisStorage(URL(path)); -} - diff --git a/views/code.dt b/views/code.dt deleted file mode 100644 index 7479ce1..0000000 --- a/views/code.dt +++ /dev/null @@ -1,19 +0,0 @@ -extends layout - -block css -block scripts - - string prefix = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.15.0"; - link(rel='stylesheet', crossorigin='anonymous', - href='#{prefix}/themes/prism.min.css') -block bodyscripts - script( - src='#{prefix}/prism.min.js') - - if(language != "none") - script( - src='#{prefix}/components/prism-#{language}.min.js') - -block content - pre - code(class='language-#{language}')= data - -//- vim: ft=pug diff --git a/views/index.dt b/views/index.dt deleted file mode 100644 index 1049f1c..0000000 --- a/views/index.dt +++ /dev/null @@ -1,41 +0,0 @@ -extends layout - -block content - h1 Burning Rubber Paste - h2 Usage - table(border='1') - thead: tr - th Method - Endpoint - th Effect - tbody - tr - td: pre: code POST / data=foo - td Pastebin foo - tr - td: pre: code PUT /id data=foo - td Write foo into /id. Collisions disallowed. If a POST id coincides with your PUT content, it will be overwritten. - tr - td: pre: code GET /id - td Read paste with ID "id" - tr - td: pre: code GET /id/raw - td Get the raw contents of paste with ID "id" - tr - td: pre: code GET /id/lang - td Read paste with ID "id", and highlight it as "lang" - h2 Examples - pre: code(class='language-sh') - | http -f https://brpaste.example.com data=@file.txt - | http -f https://brpaste.example.com data=abcd - | http -f PUT https://brpaste.example.com/myPaste data=contents - | http https://brpaste.example.com/some_id/raw - | xdg-open https://brpaste.example.com/some_id/cpp - h2 Paste from a browser - form(action='/', method='post') - textarea(name='data', autocomplete='off', - required, autofocus, - cols='80', rows='27') - br - button(type='submit') Paste it! - -//- vim: ft=pug diff --git a/views/layout.dt b/views/layout.dt deleted file mode 100644 index 6b213a6..0000000 --- a/views/layout.dt +++ /dev/null @@ -1,27 +0,0 @@ -doctype html -html(lang='en') - head - meta(charset='utf-8') - meta(name='viewport', content='width=device-width, initial-scale=1') - block css - :css - body { - margin: 40px auto; - max-width: 650px; - line-height: 1.6; - font-size: 18px; - color: #444; - padding: 0 10px - } - h1,h2,h3 { line-height:1.2; } - td { text-align: left; } - block scripts - block title - title Burning Rubber Paste - body - #main - block content - p I'm not sure how you got here, but you shouldn't be here. - block bodyscripts - -//- vim: ft=pug |
