diff --git a/README.md b/README.md index cb77c19..db026ef 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Source: ```Bash EBPASS=changeme EBPORT=4000 -EBSECRET=4jkdmakl2l #jwt session secret +EBAPI_KEY=changeme #ShareX support $ npm install $ node db.js @@ -25,9 +25,34 @@ $ npm start ``` Default username is admin with the password being whatever EBPASS is -Docker +ShareX support is enabled at "/upload", requires auth with key +JSON ``` -docker run -d -p "4000:4000" -e EBPORT=4000 -e EBPASS=pass -e EBSECRET=4jkdmakl2l waveringana/embedder:latest +{ + "Version": "14.1.0", + "Name": "embedder", + "DestinationType": "ImageUploader, FileUploader", + "RequestMethod": "POST", + "RequestURL": "http://localhost:3000/sharex", + "Headers": { + "key": "changeme" + }, + "Body": "MultipartFormData", + "Arguments": { + "fileupload": null + }, + "FileFormName": "fileupload", + "URL": null, + "ThumbnailURL": null, + "DeletionURL": null, + "ErrorMessage": null + } +] +``` + +Docker config +``` +docker run -d -p "4000:4000" -e EBPORT=4000 -e EBPASS=changeme -e EBAPI_KEY=changeme waveringana/embedder:latest ``` Docker Compose @@ -40,7 +65,7 @@ services: environment: - EBPORT=4000 - EBPASS=changeme - - EBSECRET=4jkdmakl2l + - EBAPI_KEY=changeme volumes: - embedderdb:/var/db - embedderuploads:/uploads diff --git a/public/android-chrome-192x192.png b/public/android-chrome-192x192.png new file mode 100644 index 0000000..b73f78e Binary files /dev/null and b/public/android-chrome-192x192.png differ diff --git a/public/android-chrome-512x512.png b/public/android-chrome-512x512.png new file mode 100644 index 0000000..7a3c0a8 Binary files /dev/null and b/public/android-chrome-512x512.png differ diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 0000000..9ca1f30 Binary files /dev/null and b/public/apple-touch-icon.png differ diff --git a/public/favicon-16x16.png b/public/favicon-16x16.png new file mode 100644 index 0000000..941b672 Binary files /dev/null and b/public/favicon-16x16.png differ diff --git a/public/favicon-32x32.png b/public/favicon-32x32.png new file mode 100644 index 0000000..77795c4 Binary files /dev/null and b/public/favicon-32x32.png differ diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..766fbe3 Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/site.webmanifest b/public/site.webmanifest new file mode 100644 index 0000000..45dc8a2 --- /dev/null +++ b/public/site.webmanifest @@ -0,0 +1 @@ +{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 9fb22ca..6f36625 100644 --- a/routes/index.js +++ b/routes/index.js @@ -73,6 +73,26 @@ function fetchMedia(req, res, next) { }); } +function checkAuth(req, res, next) { + let auth = process.env.EBAPI_KEY || process.env.EBPASS || 'pleaseSetAPI_KEY'; + let key = null; + + if (req.headers['key']) { + key = req.headers['key']; + } else { + return res.status(400).send('{success: false, message: "No key provided", fix: "Provide a key"}'); + } + + if (auth != key) { + return res.status(401).send('{success: false, message: "Invalid key", fix: "Provide a valid key"}'); + } + + shortKey = key.substr(0, 3) + '...'; + console.log('Authenicated user with key: ' + shortKey); + + next(); +} + let router = express.Router(); router.get('/', function (req, res, next) { @@ -91,7 +111,8 @@ router.post('/', upload.array('fileupload'), function(req, res, next) { for (file in req.files) { db.run('INSERT INTO media (path) VALUES (?)', [req.files[file].filename], function (err) { - if (err) { console.log(err) + if (err) { + console.log(err); return next(err); } return res.redirect('/'); @@ -99,6 +120,24 @@ router.post('/', upload.array('fileupload'), function(req, res, next) { } }); +router.post('/sharex', [checkAuth, upload.array('fileupload')], function(req, res, next) { + if (!req.files || Object.keys(req.files).length === 0) { + console.log(req); + return res.status(400).send('No files were uploaded.'); + } + + for (file in req.files) { + db.run('INSERT INTO media (path) VALUES (?)', [req.files[file].filename], function (err) { + if (err) { + console.log(err); + return next(err); + } + return res.send('Upload successful, path: /uploads/' + req.files[file].filename); + }); + } +}); + + router.post('/:id(\\d+)/delete', function(req, res, next) { db.all('SELECT path FROM media WHERE id = ?', [ req.params.id ], function(err, path) { if (err) { return next(err); } diff --git a/views/home.ejs b/views/home.ejs index d16f560..9ad55f2 100644 --- a/views/home.ejs +++ b/views/home.ejs @@ -7,7 +7,11 @@ - + + + + +
diff --git a/views/index.ejs b/views/index.ejs index cc6ffa8..a91f993 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -7,6 +7,10 @@ + + + + <% function extension(string) { return string.slice((string.lastIndexOf(".") - 2 >>> 0) + 2); diff --git a/views/login.ejs b/views/login.ejs index 69edd80..f727a96 100644 --- a/views/login.ejs +++ b/views/login.ejs @@ -7,7 +7,11 @@ - + + + + +

Embedder