forked from taobataoma/meanTorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backup): new module 'Backup' menu, route, controller, policy of …
…server side
- Loading branch information
1 parent
441c327
commit 5a1fe52
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies | ||
*/ | ||
var path = require('path'), | ||
config = require(path.resolve('./config/config')); | ||
|
||
/** | ||
* Module init function. | ||
*/ | ||
module.exports = function (app, db) { | ||
|
||
}; |
39 changes: 39 additions & 0 deletions
39
modules/backup/server/controllers/backup.server.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies | ||
*/ | ||
var path = require('path'), | ||
fs = require('fs'), | ||
config = require(path.resolve('./config/config')), | ||
errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')), | ||
traceLogCreate = require(path.resolve('./config/lib/tracelog')).create; | ||
|
||
var traceConfig = config.meanTorrentConfig.trace; | ||
var backupConfig = config.meanTorrentConfig.backup; | ||
|
||
var mtDebug = require(path.resolve('./config/lib/debug')); | ||
|
||
/** | ||
* List of collections | ||
*/ | ||
exports.list = function (req, res) { | ||
var files = fs.readdirSync(backupConfig.dir); | ||
const response = []; | ||
for (let file of files) { | ||
const fileInfo = fs.statSync(backupConfig.dir + file); | ||
response.push({ | ||
name: file, | ||
size: fileInfo.size, | ||
ctime: fileInfo.ctime | ||
}); | ||
} | ||
res.json(response); | ||
}; | ||
|
||
/** | ||
* Delete an collection | ||
*/ | ||
exports.delete = function (req, res) { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies | ||
*/ | ||
var acl = require('acl'); | ||
|
||
// Using the memory backend | ||
acl = new acl(new acl.memoryBackend()); | ||
|
||
/** | ||
* Invoke Torrents Permissions | ||
*/ | ||
exports.invokeRolesPolicies = function () { | ||
acl.allow( | ||
[ | ||
{ | ||
roles: ['admin', 'oper'], | ||
allows: [ | ||
{resources: '/api/backup', permissions: '*'} | ||
] | ||
} | ||
] | ||
); | ||
}; | ||
|
||
/** | ||
* Check If Articles Policy Allows | ||
*/ | ||
exports.isAllowed = function (req, res, next) { | ||
var roles = (req.user) ? req.user.roles : ['guest']; | ||
|
||
// Check for user roles | ||
acl.areAnyRolesAllowed(roles, req.route.path, req.method.toLowerCase(), function (err, isAllowed) { | ||
if (err) { | ||
// An authorization error occurred | ||
return res.status(500).send('Unexpected authorization error'); | ||
} else { | ||
if (isAllowed) { | ||
// Access granted! Invoke next middleware | ||
return next(); | ||
} else { | ||
return res.status(403).json({ | ||
message: 'User is not authorized' | ||
}); | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies | ||
*/ | ||
var backup = require('../controllers/backup.server.controller'), | ||
backupPolicy = require('../policies/backup.server.policy'); | ||
|
||
|
||
module.exports = function (app) { | ||
app.route('/api/backup').all(backupPolicy.isAllowed) | ||
.get(backup.list) | ||
.delete(backup.delete); | ||
}; |