luci-app-alist: add support for custom log file path

Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
sbwml 2024-11-12 20:35:54 +08:00
parent f65f4e5c00
commit ec64d9eccd
5 changed files with 25 additions and 9 deletions

View File

@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-alist PKG_NAME:=luci-app-alist
PKG_VERSION:=1.1.1 PKG_VERSION:=1.1.2
PKG_RELEASE:=1 PKG_RELEASE:=1
LUCI_TITLE:=LuCI support for alist LUCI_TITLE:=LuCI support for alist

View File

@ -170,7 +170,12 @@ return view.extend({
o.default = 1; o.default = 1;
o.rmempty = false; o.rmempty = false;
o = s.option(form.Value, 'log_max_size', _('Max Size')); o = s.option(form.Value, 'log_path', _('Log path'));
o.default = '/var/log/alist.log';
o.rmempty = false;
o.depends('log', '1');
o = s.option(form.Value, 'log_max_size', _('Max Size (MB)'));
o.datatype = 'uinteger'; o.datatype = 'uinteger';
o.default = '10'; o.default = '10';
o.rmempty = false; o.rmempty = false;

View File

@ -2,15 +2,21 @@
'require dom'; 'require dom';
'require fs'; 'require fs';
'require poll'; 'require poll';
'require uci';
'require view'; 'require view';
var scrollPosition = 0; var scrollPosition = 0;
var userScrolled = false; var userScrolled = false;
var logTextarea; var logTextarea;
var log_path;
uci.load('alist').then(function() {
log_path = uci.get('alist', '@alist[0]', 'log_path') || '/var/log/alist.log';
});
function pollLog() { function pollLog() {
return Promise.all([ return Promise.all([
fs.read_direct('/var/log/alist.log', 'text').then(function (res) { fs.read_direct(log_path, 'text').then(function (res) {
return res.trim().split(/\n/).join('\n').replace(/\u001b\[33mWARN\u001b\[0m/g, '').replace(/\u001b\[36mINFO\u001b\[0m/g, '').replace(/\u001b\[31mERRO\u001b\[0m/g, ''); return res.trim().split(/\n/).join('\n').replace(/\u001b\[33mWARN\u001b\[0m/g, '').replace(/\u001b\[36mINFO\u001b\[0m/g, '').replace(/\u001b\[31mERRO\u001b\[0m/g, '');
}), }),
]).then(function (data) { ]).then(function (data) {
@ -26,7 +32,7 @@ function pollLog() {
return view.extend({ return view.extend({
handleCleanLogs: function () { handleCleanLogs: function () {
return fs.write('/var/log/alist.log', '') return fs.write(log_path, '')
.catch(function (e) { ui.addNotification(null, E('p', e.message)) }); .catch(function (e) { ui.addNotification(null, E('p', e.message)) });
}, },
@ -45,7 +51,9 @@ return view.extend({
var log_textarea_wrapper = E('div', { 'id': 'log_textarea' }, logTextarea); var log_textarea_wrapper = E('div', { 'id': 'log_textarea' }, logTextarea);
setTimeout(function () {
poll.add(pollLog); poll.add(pollLog);
}, 100);
var clear_logs_button = E('input', { 'class': 'btn cbi-button-action', 'type': 'button', 'style': 'margin-left: 10px; margin-top: 10px;', 'value': _('Clear logs') }); var clear_logs_button = E('input', { 'class': 'btn cbi-button-action', 'type': 'button', 'style': 'margin-left: 10px; margin-top: 10px;', 'value': _('Clear logs') });
clear_logs_button.addEventListener('click', this.handleCleanLogs.bind(this)); clear_logs_button.addEventListener('click', this.handleCleanLogs.bind(this));

View File

@ -80,8 +80,11 @@ msgstr "允许从外网访问"
msgid "Enable Logs" msgid "Enable Logs"
msgstr "启用日志" msgstr "启用日志"
msgid "Max Size" msgid "Log path"
msgstr "日志文大小" msgstr "日志文件路径"
msgid "Max Size (MB)"
msgstr "日志文件大小MB"
msgid "Max backups" msgid "Max backups"
msgstr "日志备份数量" msgstr "日志备份数量"

View File

@ -4,7 +4,7 @@
"read": { "read": {
"file": { "file": {
"/usr/bin/alist": [ "exec" ], "/usr/bin/alist": [ "exec" ],
"/var/log/alist.log": [ "read" ] "/*": [ "read" ]
}, },
"ubus": { "ubus": {
"service": [ "list" ] "service": [ "list" ]
@ -13,7 +13,7 @@
}, },
"write": { "write": {
"file": { "file": {
"/var/log/alist.log": [ "write" ] "/*": [ "write" ]
}, },
"uci": [ "alist" ] "uci": [ "alist" ]
} }