mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-05-07 14:56:22 +02:00
feat(core): server config online
This commit is contained in:
14
config/env/torrents.js
vendored
14
config/env/torrents.js
vendored
@@ -2,7 +2,12 @@
|
||||
|
||||
module.exports = {
|
||||
|
||||
//[!config_content]//
|
||||
/**------------------------------------------------------------------------------------------------
|
||||
* !IMPORTANT
|
||||
* MEANTORRENT CONFIG START
|
||||
* PLEASE DO NOT MODIFY THE ABOVE LINES !!!
|
||||
--------------------------------------------------------------------------------------------------*/
|
||||
|
||||
meanTorrentConfig: {
|
||||
/**
|
||||
* @app
|
||||
@@ -1220,5 +1225,10 @@ module.exports = {
|
||||
]
|
||||
}
|
||||
}
|
||||
//[!config_content]//
|
||||
|
||||
/**------------------------------------------------------------------------------------------------
|
||||
* !IMPORTANT
|
||||
* MEANTORRENT CONFIG START
|
||||
* PLEASE DO NOT MODIFY THE FOLLOWING LINES !!!
|
||||
--------------------------------------------------------------------------------------------------*/
|
||||
};
|
||||
|
||||
@@ -1259,7 +1259,14 @@
|
||||
//systems control panel
|
||||
SYSTEMS: {
|
||||
TORRENTS_CONFIG: 'System configure',
|
||||
TEMPLATE_EDIT: 'Template editor'
|
||||
TEMPLATE_EDIT: 'Template editor',
|
||||
|
||||
CONFIG_BLUR_CONFIRM_CANCEL: 'Cancel',
|
||||
CONFIG_BLUR_CONFIRM_SAVE: 'Save',
|
||||
CONFIG_BLUR_HEADER_TEXT: 'Configure was changed',
|
||||
CONFIG_BLUR_BODY_TEXT: 'Configure was changed, are you sure to quit and don`t save it?',
|
||||
CONFIG_SAVE_SUCCESSFULLY: 'Configure save successfully',
|
||||
CONFIG_SAVE_FAILED: 'Configure save failed'
|
||||
},
|
||||
|
||||
/////////////////////////resources tag fields///////////////////////////////////
|
||||
|
||||
@@ -1259,7 +1259,14 @@
|
||||
//systems control panel
|
||||
SYSTEMS: {
|
||||
TORRENTS_CONFIG: '系统配置调整',
|
||||
TEMPLATE_EDIT: '模板在线编辑'
|
||||
TEMPLATE_EDIT: '模板在线编辑',
|
||||
|
||||
CONFIG_BLUR_CONFIRM_CANCEL: '取消',
|
||||
CONFIG_BLUR_CONFIRM_SAVE: '保存',
|
||||
CONFIG_BLUR_HEADER_TEXT: '系统配置已更改',
|
||||
CONFIG_BLUR_BODY_TEXT: '系统配置已被修改, 您确定要退出并放弃保存吗?',
|
||||
CONFIG_SAVE_SUCCESSFULLY: '系统配置保存成功',
|
||||
CONFIG_SAVE_FAILED: '系统配置保存失败'
|
||||
},
|
||||
|
||||
/////////////////////////resources tag fields///////////////////////////////////
|
||||
|
||||
@@ -5,21 +5,71 @@
|
||||
.module('systems')
|
||||
.controller('SystemConfigController', SystemConfigController);
|
||||
|
||||
SystemConfigController.$inject = ['$scope', '$state', '$timeout', '$translate', 'Authentication', 'SystemsService'];
|
||||
SystemConfigController.$inject = ['$scope', '$state', '$timeout', '$translate', 'Authentication', 'SystemsService', 'ModalConfirmService', 'NotifycationService'];
|
||||
|
||||
function SystemConfigController($scope, $state, $timeout, $translate, Authentication, SystemsService) {
|
||||
function SystemConfigController($scope, $state, $timeout, $translate, Authentication, SystemsService, ModalConfirmService, NotifycationService) {
|
||||
var vm = this;
|
||||
vm.user = Authentication.user;
|
||||
|
||||
vm.cmOption = {
|
||||
lineNumbers: true,
|
||||
mode: {name: 'javascript', json: true},
|
||||
tabSize: 2,
|
||||
onLoad: function (_cm) {
|
||||
vm.initConfigContent = function (value) {
|
||||
_cm.setOption('value', value);
|
||||
vm.contentChanged = false;
|
||||
};
|
||||
|
||||
_cm.on('change', function () {
|
||||
vm.contentChanged = true;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* remove side_overlay background
|
||||
*/
|
||||
$scope.$on('$stateChangeStart', function () {
|
||||
if (vm.contentChanged) {
|
||||
var modalOptions = {
|
||||
closeButtonText: $translate.instant('SYSTEMS.CONFIG_BLUR_CONFIRM_CANCEL'),
|
||||
actionButtonText: $translate.instant('SYSTEMS.CONFIG_BLUR_CONFIRM_SAVE'),
|
||||
headerText: $translate.instant('SYSTEMS.CONFIG_BLUR_HEADER_TEXT'),
|
||||
bodyText: $translate.instant('SYSTEMS.CONFIG_BLUR_BODY_TEXT')
|
||||
};
|
||||
|
||||
ModalConfirmService.showModal({}, modalOptions)
|
||||
.then(function (result) {
|
||||
vm.saveConfigContent();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* getConfigFile
|
||||
*/
|
||||
vm.getConfigFile = function () {
|
||||
SystemsService.getSystemConfig(function (res) {
|
||||
vm.systemConfigContent = res.configContent;
|
||||
vm.initConfigContent(res.configContent);
|
||||
// vm.systemConfigContent = res.configContent;
|
||||
}, function (err) {
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* saveConfigContent
|
||||
*/
|
||||
vm.saveConfigContent = function () {
|
||||
var sc = new SystemsService({
|
||||
content: vm.systemConfigContent
|
||||
});
|
||||
sc.$setSystemConfig(function (res) {
|
||||
console.log(res);
|
||||
// NotifycationService.showSuccessNotify('SYSTEMS.CONFIG_SAVE_SUCCESSFULLY');
|
||||
// vm.contentChanged = false;
|
||||
});
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -15,11 +15,9 @@
|
||||
height: 100px;
|
||||
}
|
||||
.panel-body {
|
||||
padding: 5px;
|
||||
.config-content {
|
||||
min-height: 400px;
|
||||
max-height: 800px;
|
||||
resize: vertical;
|
||||
padding: 0;
|
||||
.CodeMirror {
|
||||
min-height: 500px;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,10 @@
|
||||
getSystemConfig: {
|
||||
method: 'GET',
|
||||
url: '/api/systems/systemConfig'
|
||||
},
|
||||
setSystemConfig: {
|
||||
method: 'PUT',
|
||||
url: '/api/systems/systemConfig'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
<div class="panel panel-default system-panel" ng-controller="SystemConfigController as vm" ng-init="vm.getConfigFile()">
|
||||
<div class="panel-heading">{{'SYSTEMS.TORRENTS_CONFIG' | translate}} - <small>/config/env/torrent.js</small></div>
|
||||
<div class="panel-heading">{{'SYSTEMS.TORRENTS_CONFIG' | translate}} -
|
||||
<small>/config/env/torrent.js</small>
|
||||
</div>
|
||||
<div class="panel-desc">
|
||||
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<textarea class="form-control config-content" id="configContent" name="configContent" ng-model="vm.systemConfigContent"></textarea>
|
||||
<textarea class="form-control config-content" id="configContent" name="configContent" ng-model="vm.systemConfigContent"
|
||||
ui-codemirror="vm.cmOption"></textarea>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<div class="text-right">
|
||||
<button class="btn btn-success btn-width-100">{{'BUTTON_SAVE' | translate}}</button>
|
||||
<button class="btn btn-success btn-width-100" ng-disabled="!vm.contentChanged"
|
||||
ng-click="vm.saveConfigContent()">{{'BUTTON_SAVE' | translate}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -23,7 +23,35 @@ var serverNoticeConfig = config.meanTorrentConfig.serverNotice;
|
||||
*/
|
||||
exports.getSystemConfig = function (req, res) {
|
||||
var config = shell.cat(path.resolve('./config/env/torrents.js'));
|
||||
res.json({
|
||||
configContent: config
|
||||
});
|
||||
|
||||
if (req.user.isAdmin) {
|
||||
res.json({
|
||||
configContent: config
|
||||
});
|
||||
} else {
|
||||
return res.status(403).json({
|
||||
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* setSystemConfig
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
exports.setSystemConfig = function (req, res) {
|
||||
// eslint-disable-next-line new-cap
|
||||
var cc = shell.ShellString(req.body.content);
|
||||
|
||||
if (req.user.isAdmin) {
|
||||
cc.to('./config/env/torrents.js');
|
||||
res.json({
|
||||
message: 'SERVER.TORRENT_CONFIG_SAVE_SUCCESSFULLY'
|
||||
});
|
||||
} else {
|
||||
return res.status(403).json({
|
||||
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,5 +8,6 @@ var systemsPolicy = require('../policies/systems.server.policy'),
|
||||
|
||||
module.exports = function (app) {
|
||||
app.route('/api/systems/systemConfig').all(systemsPolicy.isAllowed)
|
||||
.get(systems.getSystemConfig);
|
||||
.get(systems.getSystemConfig)
|
||||
.put(systems.setSystemConfig);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user