summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-aria2/htdocs/luci-static/resources/view/aria2/files.js
diff options
context:
space:
mode:
authorVan Waholtz <vanwaholtz@gmail.com>2020-07-28 07:14:52 -0700
committerVan Waholtz <vanwaholtz@gmail.com>2021-11-17 15:36:41 +0800
commit9dda104ee7136d805dfb3ab965f020b21cdea3bc (patch)
tree05134587d021211a6dff4d197b95f064c736fcb7 /applications/luci-app-aria2/htdocs/luci-static/resources/view/aria2/files.js
parent8d35d78c61782b393e2f0a9aebb9ae91abca3a2c (diff)
luci-app-aria2: convert to client side
Signed-off-by: Van Waholtz <vanwaholtz@gmail.com>
Diffstat (limited to 'applications/luci-app-aria2/htdocs/luci-static/resources/view/aria2/files.js')
-rw-r--r--applications/luci-app-aria2/htdocs/luci-static/resources/view/aria2/files.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/applications/luci-app-aria2/htdocs/luci-static/resources/view/aria2/files.js b/applications/luci-app-aria2/htdocs/luci-static/resources/view/aria2/files.js
new file mode 100644
index 0000000000..c86c794a93
--- /dev/null
+++ b/applications/luci-app-aria2/htdocs/luci-static/resources/view/aria2/files.js
@@ -0,0 +1,55 @@
+'use strict';
+'require fs';
+'require view';
+
+return view.extend({
+ load: function() {
+ var list_files = ['conf', 'session'],
+ actions = [];
+ for (var index = 0; index < list_files.length; ++index) {
+ actions.push(
+ fs.exec_direct('/usr/libexec/aria2-call', [ 'cat', list_files[index] ])
+ .then(function(json) {
+ var res = {};
+
+ try { res = JSON.parse(json); }
+ catch(err) {}
+
+ res.file = res.file || '';
+ res.content = 'content' in res ? res.content.trim() : '';
+ res.rows = res.content.split('\n', 20).length;
+ return res;
+ })
+ );
+ }
+ return Promise.all(actions);
+ },
+
+ render: function(data) {
+ var textareaEl = function(id, data, descr) {
+ return E('div', {'class': 'cbi-section'}, [
+ E('div', {'class': 'cbi-section-descr'}, descr.format(data.file)),
+ E('div', { 'id' : id},
+ E('textarea', {
+ 'id': 'widget.' + id,
+ 'style': 'width: 100%',
+ 'readonly': true,
+ 'wrap': 'off',
+ 'rows': data.rows >= 20 ? 20 : data.rows + 1
+ }, data.content)
+ )
+ ]);
+ };
+
+ return E('div', {'class': 'cbi-map'}, [
+ E('h2', {'name': 'content'}, '%s - %s'.format(_('Aria2'), _('Files'))),
+ E('div', {'class': 'cbi-map-descr'}, _('Here shows the files used by aria2.')),
+ textareaEl('config_area', data[0], _('Content of config file: <code>%s</code>')),
+ textareaEl('session_area', data[1], _('Content of session file: <code>%s</code>'))
+ ]);
+ },
+
+ handleSave: null,
+ handleSaveApply: null,
+ handleReset: null
+});