mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-13 20:08:05 +08:00
🎈 Sync 2026-10-28 12:40:08
This commit is contained in:
1 parent
d42296f292
commit
cfb89528fa
20 files changed
+1459
-766
No files matched your search
@@ -22,11 +22,11 @@ PKG_NAME:=luci-app-amlogic
|
||||
# DD = day (01 = 1st)
|
||||
# NN = daily release sequence (01 = first release of the day, 02 = second, ...)
|
||||
# Example below: 26.10.0101 = October 1, 2026, 1st release of the day
|
||||
PKG_VERSION:=26.10.2501
|
||||
PKG_VERSION:=26.10.2801
|
||||
# PKG_RELEASE marks the LuCI variant; onekey-install.sh relies on it (do NOT bump)
|
||||
# 1 = Lua version (lua branch) → tag: 26.10.0101
|
||||
# 2 = JS version (main branch) → tag: 26.10.0101-js
|
||||
PKG_RELEASE:=26
|
||||
PKG_RELEASE:=27
|
||||
|
||||
PKG_LICENSE:=GPL-2.0 License
|
||||
PKG_MAINTAINER:=ophub <https://github.com/ophub/luci-app-amlogic>
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
'require fs';
|
||||
'require view.amlogic.shared as amlogicShared';
|
||||
|
||||
// Generate one openwrt_config.tar.gz on the server and return its path so the
|
||||
// frontend can stream it back via fs.read_direct.
|
||||
const callBackup = rpc.declare({ object: 'luci.amlogic', method: 'backup_create' });
|
||||
// Generate one openwrt_config.tar.gz on the server (background) so the
|
||||
// frontend can stream it back via fs.read_direct once backup_status is done.
|
||||
const callBackup = rpc.declare({ object: 'luci.amlogic', method: 'backup_create' });
|
||||
const callBackupStatus = rpc.declare({ object: 'luci.amlogic', method: 'backup_status' });
|
||||
// List existing snapshot names (e.g. etc-000 / etc-001 / etc-202401...).
|
||||
const callSnapList = rpc.declare({ object: 'luci.amlogic', method: 'snapshot_list',
|
||||
expect: { names: [] } });
|
||||
@@ -69,17 +70,11 @@ return view.extend({
|
||||
const btn = ev.currentTarget;
|
||||
btn.disabled = true;
|
||||
btn.value = _('Generating...');
|
||||
// Step 1: ask the server to pack /etc into openwrt_config.tar.gz.
|
||||
return callBackup().then(function (r) {
|
||||
if (!r || !r.ok) {
|
||||
downloadStatus.textContent = _("Couldn't open file:") + ' ' + (r ? r.path : '');
|
||||
return;
|
||||
}
|
||||
// Switch to success color before streaming the blob
|
||||
downloadStatus.className = 'amlogic-status-ok';
|
||||
downloadStatus.textContent = _('The file Will download automatically.') + ' ' + r.path;
|
||||
// Fetch the file blob via fs.read_direct and trigger browser download.
|
||||
return fs.read_direct(r.path, 'blob').then(function (blob) {
|
||||
downloadStatus.className = 'amlogic-status-err';
|
||||
downloadStatus.textContent = '';
|
||||
|
||||
function downloadFile(path) {
|
||||
return fs.read_direct(path, 'blob').then(function (blob) {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
@@ -89,6 +84,27 @@ return view.extend({
|
||||
document.body.removeChild(a);
|
||||
setTimeout(function () { URL.revokeObjectURL(url); }, 10000);
|
||||
});
|
||||
}
|
||||
|
||||
function pollStatus(deadline) {
|
||||
return callBackupStatus().then(function (s) {
|
||||
if (s && s.status === 'done' && s.size > 0) {
|
||||
downloadStatus.className = 'amlogic-status-ok';
|
||||
downloadStatus.textContent = _('The file Will download automatically.') + ' ' + s.path;
|
||||
return downloadFile(s.path);
|
||||
}
|
||||
if (s && s.status === 'failed')
|
||||
throw new Error(_("Couldn't open file:") + ' ' + (s.path || ''));
|
||||
if (Date.now() > deadline)
|
||||
throw new Error(_('Backup generation timed out.'));
|
||||
return new Promise(function (resolve) { setTimeout(resolve, 1500); })
|
||||
.then(function () { return pollStatus(deadline); });
|
||||
});
|
||||
}
|
||||
|
||||
// Step 1: kick off the background pack job, then poll until done.
|
||||
return callBackup().then(function () {
|
||||
return pollStatus(Date.now() + 300000);
|
||||
}).catch(function (e) {
|
||||
downloadStatus.textContent = _('Create upload file error.') +
|
||||
' ' + (e && e.message ? e.message : '');
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
"list_uploads",
|
||||
"read_log_tail",
|
||||
"read_log_full",
|
||||
"cpu_policies"
|
||||
"cpu_policies",
|
||||
"backup_status"
|
||||
]
|
||||
},
|
||||
"uci": [ "amlogic" ],
|
||||
|
||||
@@ -18,6 +18,7 @@ const LOG_PLUGIN = LOG_DIR + '/amlogic_check_plugin.log';
|
||||
const LOG_KERNEL = LOG_DIR + '/amlogic_check_kernel.log';
|
||||
const LOG_FIRMWARE = LOG_DIR + '/amlogic_check_firmware.log';
|
||||
const LOG_RESCUE = LOG_DIR + '/amlogic_check_rescue.log';
|
||||
const BACKUP_STATUS = LOG_DIR + '/amlogic_backup_status.log';
|
||||
const UPLOAD_TMP = '/tmp/upload';
|
||||
const PKG_NAME = 'luci-app-amlogic';
|
||||
const BACKUP_LIST = '/etc/amlogic_backup_list.conf';
|
||||
@@ -681,13 +682,29 @@ function m_install_upload(req) {
|
||||
return { error: 'unsupported file type' };
|
||||
}
|
||||
|
||||
// Kick off openwrt-backup -b in the background; the resulting tarball can be
|
||||
// fetched via fs.read_direct once backup_status reports done. Packing /etc
|
||||
// (docker, openclash rules, etc.) often exceeds the ~20s ubus RPC timeout, so
|
||||
// this must not block the rpcd thread.
|
||||
function m_backup_create() {
|
||||
ensure_dirs();
|
||||
shcall('chmod +x /usr/sbin/openwrt-backup');
|
||||
shcall('/usr/sbin/openwrt-backup -b > ' + LOG_FILE + ' && sync');
|
||||
writefile(BACKUP_STATUS, 'running\n');
|
||||
shbg('/usr/sbin/openwrt-backup -b > ' + LOG_FILE + ' 2>&1 && sync && ' +
|
||||
'[ -f /.reserved/openwrt_config.tar.gz ] && ' +
|
||||
'echo done > ' + BACKUP_STATUS + ' || echo failed > ' + BACKUP_STATUS);
|
||||
return { code: 0 };
|
||||
}
|
||||
|
||||
function m_backup_status() {
|
||||
const t = trim(readfile(BACKUP_STATUS) ?? '');
|
||||
const path = '/.reserved/openwrt_config.tar.gz';
|
||||
const ok = access(path);
|
||||
return { ok: ok ? true : false, path };
|
||||
const st = stat(path);
|
||||
return {
|
||||
status: t != '' ? t : 'idle',
|
||||
path,
|
||||
size: (st && st.type == 'file') ? st.size : 0
|
||||
};
|
||||
}
|
||||
|
||||
function m_save_backup_list(req) {
|
||||
@@ -778,6 +795,7 @@ const methods = {
|
||||
delete_upload: { args: { name: '' }, call: m_delete_upload },
|
||||
install_upload: { args: { name: '' }, call: m_install_upload },
|
||||
backup_create: { call: m_backup_create },
|
||||
backup_status: { call: m_backup_status },
|
||||
save_backup_list:{ args: { content: '' }, call: m_save_backup_list },
|
||||
prime_backup_list:{ call: m_prime_backup_list },
|
||||
reload_cpu: { call: m_reload_cpu },
|
||||
|
||||
Reference in new issue
Block a user