From a2af6ba59ed1e67f6a2445d74716c9088c8930a8 Mon Sep 17 00:00:00 2001 From: daniel-j Date: Wed, 4 Mar 2020 13:18:40 +0100 Subject: [PATCH] prettier upload page --- download.html | 35 +---------------------------------- index.js | 26 +++++++++++++------------- style.css | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ upload.html | 28 +++++++++++++++++++++------- 4 files changed, 83 insertions(+), 54 deletions(-) create mode 100644 style.css diff --git a/download.html b/download.html index 7e8f5f0..28feb5a 100644 --- a/download.html +++ b/download.html @@ -4,40 +4,7 @@ Send To Kobo - + diff --git a/index.js b/index.js index 7590219..9b19236 100644 --- a/index.js +++ b/index.js @@ -11,9 +11,10 @@ const { spawn } = require('child_process') const expireDelay = 20 const port = 3001 +const maxFileSize = 1024 * 1024 * 400 -const uniqueRandom = (minimum, maximum) => { - let previousValue; +function uniqueRandom (minimum, maximum) { + let previousValue return function random() { const number = Math.floor( (Math.random() * (maximum - minimum + 1)) + minimum @@ -51,10 +52,9 @@ function expireKey (key) { return timer } - const random = uniqueRandom(1000, 9999) - const app = new Koa() +app.context.keys = new Map() const router = new Router() const upload = multer({ storage: multer.diskStorage({ @@ -68,7 +68,7 @@ const upload = multer({ } }), limits: { - fileSize: 1024 * 1024 * 400, + fileSize: maxFileSize, files: 1 }, fileFilter: (req, file, cb) => { @@ -87,9 +87,6 @@ const upload = multer({ } }) -app.context.keys = new Map() - - router.get('/generate', async ctx => { const agent = ctx.get('user-agent') if (!agent.includes('Kobo')) { @@ -121,7 +118,6 @@ router.get('/generate', async ctx => { ctx.body = key }) - router.get('/download/:key', async ctx => { const key = ctx.params.key const info = ctx.keys.get(key) @@ -138,7 +134,6 @@ router.get('/download/:key', async ctx => { ctx.attachment(info.file.name) }) - router.post('/upload', upload.single('file'), async ctx => { const key = ctx.request.body.key @@ -225,6 +220,10 @@ router.get('/status/:key', async ctx => { } }) +router.get('/style.css', async ctx => { + await sendfile(ctx, 'style.css') +}) + router.get('/', async ctx => { const agent = ctx.get('user-agent') console.log(agent) @@ -237,7 +236,8 @@ app.use(router.allowedMethods()) fs.rmdir('uploads', {recursive: true}, (err) => { if (err) throw err - mkdirp.sync('uploads') - app.listen(port) - console.log('server is listening on port ' + port) + mkdirp('uploads').then (() => { + app.listen(port) + console.log('server is listening on port ' + port) + }) }) diff --git a/style.css b/style.css new file mode 100644 index 0000000..39adbe7 --- /dev/null +++ b/style.css @@ -0,0 +1,48 @@ + +.wrapper { + margin: 0 auto; + padding: 0 20px; + max-width: 600px; +} +h1 { + font-weight: normal; + font-style: italic; +} +#key { + font-size: 3.5em; + display: block; + letter-spacing: 0.1em; + margin: 10px 0; +} +.center { + text-align: center; +} +.right { + text-align: right; +} +#keygen, #downloadlink { + background: #CCC; + border: none; + color: black; + font-style: italic; + padding: 0.6em 1.3em; + line-height: 1.6; + display: inline-block; +} +#keygen:focus { + background: black; + color: white; +} +#downloads { + display: none; +} + + + + +#keyinput { + font-size: 3.5em; + width: 4em; + text-align: center; + font-family: serif; +} \ No newline at end of file diff --git a/upload.html b/upload.html index 3cbc7d3..8034c0d 100644 --- a/upload.html +++ b/upload.html @@ -4,17 +4,31 @@ Send To Kobo + -

Send to Kobo

+
+

Send to Kobo

-
-
-
-
- -
+
+ + + + + +
Unique key
EPUB file
+
+
+
+

Go this this page on your Kobo ereader and you see a unique key. Enter it in this form and upload an ebook and it will appear as a download link on the ereader. Your ebook will be stored on the server as long as the Kobo is viewing the unique key and is connected to wifi. It will be deleted when the key expires about 30 seconds after you close the browser/generate a new key/disable wifi on your Kobo.

+

By using this tool you agree that the ebook you upload is processed on the server and stored for a short time.

+
+
+
+ Created by djazz. Powered by Koa and Kepubify. +
+