Basic admin pages for Uploads and Codes implemented, list only

This commit is contained in:
Mark van Renswoude 2018-04-26 14:08:08 +02:00
parent f9923b7813
commit 0e10f38383
214 changed files with 654 additions and 84 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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)

View File

@ -38,7 +38,7 @@ async function checkAuthorization(req, res, onVerified)
module.exports = (repository) =>
module.exports = (repository, tusServer) =>
{
var router = express.Router();

View File

@ -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)
{

View File

@ -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);
}));
});
});
}
}

View File

@ -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);
});
});
}
}

View File

@ -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"
},

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

BIN
public/dist/images/fileicons/16px/ai.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

BIN
public/dist/images/fileicons/16px/c.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 683 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 735 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

BIN
public/dist/images/fileicons/16px/h.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 702 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

BIN
public/dist/images/fileicons/16px/js.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

BIN
public/dist/images/fileicons/16px/py.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 B

BIN
public/dist/images/fileicons/16px/qt.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

BIN
public/dist/images/fileicons/16px/rb.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 647 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
public/dist/images/fileicons/32px/ai.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
public/dist/images/fileicons/32px/c.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
public/dist/images/fileicons/32px/h.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1001 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Some files were not shown because too many files have changed in this diff Show More