Basic admin pages for Uploads and Codes implemented, list only
37
index.js
|
@ -10,6 +10,7 @@ const bodyParser = require('body-parser');
|
|||
const tus = require('tus-node-server');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const path = require('path');
|
||||
const resolvePath = require('resolve-path');
|
||||
|
||||
const webpack = require('webpack');
|
||||
const webpackDevMiddleware = require('webpack-dev-middleware');
|
||||
|
@ -40,11 +41,9 @@ const webpackConfig = require('./webpack.config.js');
|
|||
|
||||
|
||||
|
||||
const loadAPI = (route, name) => { app.use(route, require('./lib/api/' + name)(repository)) }
|
||||
|
||||
loadAPI('/', 'upload');
|
||||
loadAPI('/token', 'token');
|
||||
loadAPI('/admin', 'admin');
|
||||
app.use('/', require('./lib/api/upload')(repository, tusServer));
|
||||
app.use('/token', require('./lib/api/token')(repository));
|
||||
app.use('/admin', require('./lib/api/admin')(repository));
|
||||
|
||||
|
||||
// Frontend
|
||||
|
@ -59,6 +58,33 @@ const webpackConfig = require('./webpack.config.js');
|
|||
app.use(webpackHotMiddleware(compiler));
|
||||
}
|
||||
|
||||
|
||||
// Automatic fallback support for file icons
|
||||
app.get('/images/fileicons/:format/:filename', (req, res) =>
|
||||
{
|
||||
var basePath;
|
||||
var filePath;
|
||||
|
||||
try
|
||||
{
|
||||
basePath = resolvePath('./public/dist/images/fileicons/', req.params.format);
|
||||
filePath = resolvePath(basePath, req.params.filename);
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
res.sendStatus(404);
|
||||
}
|
||||
|
||||
fs.stat(filePath, (err, stat) =>
|
||||
{
|
||||
if (err)
|
||||
res.sendFile(resolvePath(basePath, '_blank.png'));
|
||||
else
|
||||
res.sendFile(filePath);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'custom')));
|
||||
app.use(express.static(path.join(__dirname, 'public', 'dist')));
|
||||
|
||||
|
@ -68,6 +94,7 @@ const webpackConfig = require('./webpack.config.js');
|
|||
app.get('/admin', (req, res) => { res.redirect(301, '/#/admin/') });
|
||||
|
||||
|
||||
|
||||
var server = app.listen(config.port, () => console.log('Recv running on port ' + server.address().port));
|
||||
}
|
||||
catch (e)
|
||||
|
|
|
@ -46,9 +46,35 @@ module.exports = (repository) =>
|
|||
{
|
||||
await checkAuthorization(req, res, async (decoded) =>
|
||||
{
|
||||
res.send(await repository.codes.getCodes(decoded.userId));
|
||||
var codes = await repository.codes.getCodes(decoded.userId);
|
||||
var usernames = await repository.users.getUsernames();
|
||||
|
||||
codes.forEach((item) =>
|
||||
{
|
||||
item.username = usernames[item.userId];
|
||||
});
|
||||
|
||||
res.send(codes);
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
router.get('/uploads', asyncHandler(async (req, res) =>
|
||||
{
|
||||
await checkAuthorization(req, res, async (decoded) =>
|
||||
{
|
||||
var files = await repository.uploads.getUploads(decoded.userId);
|
||||
var usernames = await repository.users.getUsernames();
|
||||
|
||||
files.forEach((item) =>
|
||||
{
|
||||
item.username = usernames[item.userId];
|
||||
});
|
||||
|
||||
res.send(files);
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
return router;
|
||||
}
|
|
@ -47,7 +47,8 @@ module.exports = (repository) =>
|
|||
if (user !== null)
|
||||
{
|
||||
jwt.sign({
|
||||
userId: user.id
|
||||
userId: user.id,
|
||||
auth: user.auth
|
||||
}, config.jwtSecret, (err, token) =>
|
||||
{
|
||||
if (err)
|
||||
|
|
|
@ -38,7 +38,7 @@ async function checkAuthorization(req, res, onVerified)
|
|||
|
||||
|
||||
|
||||
module.exports = (repository) =>
|
||||
module.exports = (repository, tusServer) =>
|
||||
{
|
||||
var router = express.Router();
|
||||
|
||||
|
|
|
@ -97,9 +97,11 @@ class CodeRepository
|
|||
|
||||
getCodes(userId)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
self.store.find({ userId: userId }, (err, docs) =>
|
||||
self.store.find(userId != null ? { userId: userId } : {}, (err, docs) =>
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
const _ = require('lodash');
|
||||
|
||||
|
||||
class Upload
|
||||
{
|
||||
constructor(values)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
self.id = values.id || values._id || null;
|
||||
self.userId = values.userId || null;
|
||||
self.created = values.created || new Date();
|
||||
self.expiration = values.expiration || null;
|
||||
self.files = values.files || [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class UploadRepository
|
||||
{
|
||||
constructor(store)
|
||||
|
@ -39,6 +57,7 @@ class UploadRepository
|
|||
{
|
||||
var upload = {
|
||||
created: new Date(),
|
||||
userId: userId,
|
||||
expiration: expiration,
|
||||
files: _.map(_.filter(files,
|
||||
(file) => file.hasOwnProperty('id') && file.hasOwnProperty('name')),
|
||||
|
@ -64,6 +83,29 @@ class UploadRepository
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
getUploads(userId)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
self.store.find(userId != null ? { userId: userId } : {}, (err, docs) =>
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(docs.map((dbUpload) =>
|
||||
{
|
||||
return new Upload(dbUpload);
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -138,6 +138,32 @@ class UserRepository
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
getUsernames()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
self.store.find({}, (err, docs) =>
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var usernames = {};
|
||||
docs.forEach((dbUser) =>
|
||||
{
|
||||
usernames[dbUser._id] = dbUser.username
|
||||
});
|
||||
|
||||
resolve(usernames);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"description": "Recv - self-hosted web file transfer",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "node index.js",
|
||||
"dev": "supervisor -w index.js,lib index.js",
|
||||
"build": "webpack --mode production",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
@ -21,11 +21,13 @@
|
|||
"debug": "^3.1.0",
|
||||
"express": "^4.16.3",
|
||||
"express-async-handler": "^1.1.2",
|
||||
"js-cookie": "^2.2.0",
|
||||
"jsonwebtoken": "^8.2.0",
|
||||
"lodash": "^4.17.5",
|
||||
"mkdirp": "^0.5.1",
|
||||
"nedb": "^1.8.0",
|
||||
"npm": "^5.8.0",
|
||||
"resolve-path": "^1.4.0",
|
||||
"shortid": "^2.2.8",
|
||||
"tus-node-server": "^0.2.10"
|
||||
},
|
||||
|
|
After Width: | Height: | Size: 446 B |
After Width: | Height: | Size: 710 B |
After Width: | Height: | Size: 726 B |
After Width: | Height: | Size: 684 B |
After Width: | Height: | Size: 742 B |
After Width: | Height: | Size: 715 B |
After Width: | Height: | Size: 708 B |
After Width: | Height: | Size: 554 B |
After Width: | Height: | Size: 592 B |
After Width: | Height: | Size: 683 B |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 595 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 760 B |
After Width: | Height: | Size: 725 B |
After Width: | Height: | Size: 735 B |
After Width: | Height: | Size: 748 B |
After Width: | Height: | Size: 711 B |
After Width: | Height: | Size: 747 B |
After Width: | Height: | Size: 713 B |
After Width: | Height: | Size: 707 B |
After Width: | Height: | Size: 530 B |
After Width: | Height: | Size: 582 B |
After Width: | Height: | Size: 702 B |
After Width: | Height: | Size: 626 B |
After Width: | Height: | Size: 663 B |
After Width: | Height: | Size: 666 B |
After Width: | Height: | Size: 711 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 692 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 726 B |
After Width: | Height: | Size: 730 B |
After Width: | Height: | Size: 718 B |
After Width: | Height: | Size: 730 B |
After Width: | Height: | Size: 652 B |
After Width: | Height: | Size: 585 B |
After Width: | Height: | Size: 584 B |
After Width: | Height: | Size: 544 B |
After Width: | Height: | Size: 596 B |
After Width: | Height: | Size: 559 B |
After Width: | Height: | Size: 710 B |
After Width: | Height: | Size: 625 B |
After Width: | Height: | Size: 713 B |
After Width: | Height: | Size: 678 B |
After Width: | Height: | Size: 778 B |
After Width: | Height: | Size: 691 B |
After Width: | Height: | Size: 723 B |
After Width: | Height: | Size: 728 B |
After Width: | Height: | Size: 650 B |
After Width: | Height: | Size: 588 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 636 B |
After Width: | Height: | Size: 730 B |
After Width: | Height: | Size: 726 B |
After Width: | Height: | Size: 706 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 751 B |
After Width: | Height: | Size: 714 B |
After Width: | Height: | Size: 711 B |
After Width: | Height: | Size: 647 B |
After Width: | Height: | Size: 570 B |
After Width: | Height: | Size: 717 B |
After Width: | Height: | Size: 446 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 592 B |
After Width: | Height: | Size: 711 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 782 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 550 B |
After Width: | Height: | Size: 671 B |
After Width: | Height: | Size: 1001 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |