working demo

pull/12/head
tycrek 4 years ago
parent e2183dfb52
commit 5d72b45715
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -0,0 +1 @@
PORT=40115

9
.gitignore vendored

@ -102,3 +102,12 @@ dist
# TernJS port file
.tern-port
# tokens
auth.json
# data
data.json
# uploads
uploads/

@ -1,2 +1,12 @@
# anssxustawai
A Not Shitty ShareX Upload Server That Actually Works As Intended (Pronounced "an-zoo-sta-why")
### Todo
- [ ] Token authorization via HTTP headers
- [ ] Upload images
- [ ] Upload videos
- [ ] Upload files
- [ ] Thumbnail support
- [ ] Delete support
- [ ] Multiple database types (JSON, Mongo, MySQL, PostgreSQL, etc.)

@ -0,0 +1,56 @@
require('dotenv').config();
const fs = require('fs-extra');
const path = require('path');
const uuid = require('uuid').v4;
const express = require('express');
const multer = require('multer');
const zws = require('./zws');
//#region Variables?
const app = express();
const upload = multer({ dest: 'uploads/' });
const resourceIdSize = 8;
var tokens = [];
var data = {};
preStartup();
startup();
function preStartup() {
// Make sure .env exists
if (!fs.existsSync(path.join(__dirname, '.env'))) fs.copyFileSync(path.join(__dirname, '.env.example'), path.join(__dirname, '.env'));
// Make sure data.json exists
if (!fs.existsSync(path.join(__dirname, 'data.json'))) fs.writeJsonSync(path.join(__dirname, 'data.json'), data, { spaces: 4 });
// Make sure auth.json exists and generate the first key
if (!fs.existsSync(path.join(__dirname, 'auth.json'))) {
tokens.push(uuid().replace(/-/g, ''));
fs.writeJsonSync(path.join(__dirname, 'auth.json'), { tokens }, { spaces: 4 });
console.log('!! Important: save this token in a secure spot: ' + tokens[0]);
}
// Read tokens and data
tokens = fs.readJsonSync(path.join(__dirname, 'auth.json')).tokens;
data = fs.readJsonSync(path.join(__dirname, 'data.json'));
}
function startup() {
app.post('/', upload.single('file'), (req, res, next) => {
if (!req.headers.authorization || !tokens.includes(req.headers.authorization)) return res.sendStatus(401);
let resourceId = zws(resourceIdSize);
data[resourceId] = req.file;
res.type('text').send(`http://lh:${process.env.PORT}/${resourceId}`);
});
app.get('/:resourceId', (req, res) => {
let resourceId = req.params.resourceId;
console.log(data);
if (data[resourceId]) res.type(data[resourceId].mimetype).sendFile(path.join(__dirname, data[resourceId].path));
});
app.listen(process.env.PORT, () => console.log(`Server started on port ${process.env.PORT}`));
}

1332
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,32 @@
{
"name": "anssxustawai",
"version": "1.0.0",
"description": "A Not Shitty ShareX Upload Server That Actually Works As Intended",
"main": "ass.js",
"scripts": {
"start": "node ass.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tycrek/anssxustawai.git"
},
"keywords": [
"sharex",
"sharex-server"
],
"author": "tycrek",
"license": "ISC",
"bugs": {
"url": "https://github.com/tycrek/anssxustawai/issues"
},
"homepage": "https://github.com/tycrek/anssxustawai#readme",
"dependencies": {
"crypto-random-string": "^4.0.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"fs-extra": "^9.1.0",
"multer": "^1.4.2",
"uuid": "^8.3.2"
}
}

@ -0,0 +1,11 @@
const { randomBytes } = require('crypto');
const zeroWidthCap = '\u200B';
const zeroWidthChars = [
zeroWidthCap,
'\u200C',
'\u200D',
'\u2060',
'\u180E'
];
module.exports = (size) => [...randomBytes(size)].map(byte => zeroWidthChars[+byte % zeroWidthChars.length]).join('').slice(1) + zeroWidthCap;
Loading…
Cancel
Save