mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-11-03 00:13:56 +08:00
update 2026-10-04 18:21:54
This commit is contained in:
1 parent
595111c0e8
commit
c75ec11645
77 files changed
+21891
-27
No files matched your search
@@ -817,12 +817,14 @@ end
|
||||
function com_update(comname)
|
||||
local json = nil
|
||||
local task = http.formvalue("task")
|
||||
if task == "extract" then
|
||||
if task == "progress" then
|
||||
json = api.to_download_progress(comname, http.formvalue("id"), http.formvalue("total_size"))
|
||||
elseif task == "extract" then
|
||||
json = api.to_extract(comname, http.formvalue("file"), http.formvalue("subfix"))
|
||||
elseif task == "move" then
|
||||
json = api.to_move(comname, http.formvalue("file"))
|
||||
else
|
||||
json = api.to_download(comname, http.formvalue("url"), http.formvalue("size"))
|
||||
json = api.to_download(comname, http.formvalue("url"), http.formvalue("size"), http.formvalue("id"))
|
||||
end
|
||||
|
||||
http_write_json(json)
|
||||
@@ -870,7 +872,7 @@ function create_backup()
|
||||
local date = os.date("%y%m%d%H%M")
|
||||
local tar_file = "/tmp/passwall-" .. date .. "-backup.tar.gz"
|
||||
local version_file = "/tmp/passwall-version"
|
||||
local version = api.get_version()
|
||||
local version = api.get_version():match("^([^-]+)")
|
||||
api.remove(tar_file)
|
||||
fs.writefile(version_file, version .. "\n")
|
||||
local cmd = "tar -czf " .. tar_file .. " " .. table.concat(backup_files, " ") .. " " .. "-C /tmp passwall-version"
|
||||
|
||||
@@ -981,9 +981,16 @@ function compare_versions(ver1, comp, ver2)
|
||||
local n2 = table.getn(av2)
|
||||
if (max < n2) then max = n2 end
|
||||
|
||||
local function version_part(value)
|
||||
local number = tonumber(value)
|
||||
if number then return number end
|
||||
local revision = type(value) == "string" and value:match("^[rR](%d+)$")
|
||||
return tonumber(revision) or 0
|
||||
end
|
||||
|
||||
for i = 1, max, 1 do
|
||||
local s1 = tonumber(av1[i] or 0) or 0
|
||||
local s2 = tonumber(av2[i] or 0) or 0
|
||||
local s1 = version_part(av1[i] or 0)
|
||||
local s2 = version_part(av2[i] or 0)
|
||||
|
||||
if comp == "~=" and (s1 ~= s2) then return true end
|
||||
if (comp == "<" or comp == "<=") and (s1 < s2) then return true end
|
||||
@@ -1232,7 +1239,7 @@ function to_check(arch, app_name)
|
||||
}
|
||||
end
|
||||
|
||||
function to_download(app_name, url, size)
|
||||
function to_download(app_name, url, size, task_id)
|
||||
local result = check_path(app_name)
|
||||
if result.code ~= 0 then
|
||||
return result
|
||||
@@ -1244,7 +1251,13 @@ function to_download(app_name, url, size)
|
||||
|
||||
remove("/tmp/" .. app_name .. "_download.*")
|
||||
|
||||
local tmp_file = trim(util.exec("mktemp -u -t " .. app_name .. "_download.XXXXXX"))
|
||||
local tmp_file
|
||||
if task_id and task_id:match("^[%w_-]+$") then
|
||||
tmp_file = "/tmp/" .. app_name .. "_download." .. task_id
|
||||
remove(tmp_file)
|
||||
else
|
||||
tmp_file = trim(util.exec("mktemp -u -t " .. app_name .. "_download.XXXXXX"))
|
||||
end
|
||||
|
||||
if size then
|
||||
local kb1 = get_free_space("/tmp")
|
||||
@@ -1277,6 +1290,23 @@ function to_download(app_name, url, size)
|
||||
return {code = 0, file = tmp_file, zip = com[app_name].zipped }
|
||||
end
|
||||
|
||||
function to_download_progress(app_name, task_id, total_size)
|
||||
if not com[app_name] or type(task_id) ~= "string" or not task_id:match("^[%w_-]+$") then
|
||||
return {code = 1, error = i18n.translate("Invalid download task.")}
|
||||
end
|
||||
|
||||
total_size = tonumber(total_size) or 0
|
||||
local tmp_file = "/tmp/" .. app_name .. "_download." .. task_id
|
||||
local downloaded = tonumber(fs.stat(tmp_file, "size")) or 0
|
||||
local percent
|
||||
if total_size > 0 then
|
||||
-- The download request has not completed yet, so leave 100% for its success callback.
|
||||
percent = math.min(99, math.floor(downloaded * 100 / total_size))
|
||||
end
|
||||
|
||||
return {code = 0, downloaded = downloaded, total = total_size, percent = percent}
|
||||
end
|
||||
|
||||
function to_extract(app_name, file, subfix)
|
||||
local result = check_path(app_name)
|
||||
if result.code ~= 0 then
|
||||
@@ -1419,38 +1449,33 @@ function get_version()
|
||||
fs.writefile(version_file, version)
|
||||
end
|
||||
end
|
||||
return version:match("^([^-]+)") or ""
|
||||
version = (version or ""):match("^%s*(.-)%s*$")
|
||||
-- Normalize APK's -rN release notation while retaining the release number.
|
||||
return version:gsub("%-r(%d+)$", "-%1")
|
||||
end
|
||||
|
||||
function to_check_self()
|
||||
local url = "https://raw.githubusercontent.com/Openwrt-Passwall/openwrt-passwall/main/luci-app-passwall/Makefile"
|
||||
local tmp_file = "/tmp/passwall_makefile"
|
||||
local gh_proxy = uci_get_c("@global_app[0]", "gh_proxy_url") or ""
|
||||
local return_code, result
|
||||
if gh_proxy ~= "" then
|
||||
url = gh_proxy .. url
|
||||
return_code, result = curl_base(url, tmp_file, curl_args)
|
||||
else
|
||||
return_code, result = curl_auto(url, tmp_file, curl_args)
|
||||
local release = get_api_json(com.passwall:get_url())
|
||||
if type(release) == "table" and #release > 0 then
|
||||
release = release[1]
|
||||
end
|
||||
result = return_code == 0
|
||||
if not result then
|
||||
exec("/bin/rm", {"-f", tmp_file})
|
||||
if type(release) ~= "table" or not release.tag_name then
|
||||
return {
|
||||
code = 1,
|
||||
error = i18n.translatef("Failed")
|
||||
error = i18n.translate("Get remote version info failed.")
|
||||
}
|
||||
end
|
||||
local local_version = get_version()
|
||||
local remote_version = sys.exec("echo -n $(grep '^PKG_VERSION' /tmp/passwall_makefile | head -n 1 | awk -F '=' '{print $2}')")
|
||||
exec("/bin/rm", {"-f", tmp_file})
|
||||
|
||||
-- Keep the release suffix (-1, -2, ...) so package revisions are compared too.
|
||||
local remote_version = release.tag_name:gsub("^v", "")
|
||||
local has_update = compare_versions(local_version, "<", remote_version)
|
||||
if not has_update then
|
||||
return {
|
||||
code = 0,
|
||||
local_version = local_version,
|
||||
remote_version = remote_version
|
||||
remote_version = remote_version,
|
||||
html_url = release.html_url,
|
||||
data = release.assets or {}
|
||||
}
|
||||
end
|
||||
return {
|
||||
@@ -1458,6 +1483,8 @@ function to_check_self()
|
||||
has_update = true,
|
||||
local_version = local_version,
|
||||
remote_version = remote_version,
|
||||
html_url = release.html_url,
|
||||
data = release.assets or {},
|
||||
error = i18n.translatef("The latest version: %s, currently does not support automatic update, if you need to update, please compile or download the ipk and then manually install.", remote_version)
|
||||
}
|
||||
end
|
||||
|
||||
@@ -19,6 +19,13 @@ _M.order = {
|
||||
"hysteria"
|
||||
}
|
||||
|
||||
-- PassWall uses the same cached GitHub Release API, but is not listed as a
|
||||
-- downloadable component because its LuCI package update flow is handled separately.
|
||||
_M.passwall = {
|
||||
name = "PassWall",
|
||||
get_url = gh_release_url
|
||||
}
|
||||
|
||||
_M.hysteria = {
|
||||
name = "Hysteria",
|
||||
repo = "HyNetwork/hysteria",
|
||||
|
||||
@@ -129,12 +129,54 @@ local com = self.com
|
||||
|
||||
var appUpdateUrl = '<%=api.url("update_")%>' + app;
|
||||
var appInfo = appInfoList[app];
|
||||
var downloadId = Date.now().toString(36) + Math.random().toString(36).substring(2, 8);
|
||||
var totalSize = appInfo && appInfo.data ? Number(appInfo.data.size) : 0;
|
||||
if (!isFinite(totalSize) || totalSize <= 0) {
|
||||
totalSize = 0;
|
||||
}
|
||||
var downloadProgressActive = true;
|
||||
var downloadProgressPending = false;
|
||||
var progressTimer = null;
|
||||
|
||||
function stopDownloadProgress() {
|
||||
downloadProgressActive = false;
|
||||
if (progressTimer) {
|
||||
clearInterval(progressTimer);
|
||||
progressTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function updateDownloadProgress() {
|
||||
if (!downloadProgressActive || downloadProgressPending || totalSize <= 0) {
|
||||
return;
|
||||
}
|
||||
downloadProgressPending = true;
|
||||
XHR.get(appUpdateUrl, {
|
||||
token: tokenStr,
|
||||
task: 'progress',
|
||||
id: downloadId,
|
||||
total_size: totalSize
|
||||
}, function (x, json) {
|
||||
downloadProgressPending = false;
|
||||
if (downloadProgressActive && json && !json.code && typeof json.percent === 'number') {
|
||||
btn.value = downloadingText + ' ' + json.percent + '%';
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
if (totalSize > 0) {
|
||||
updateDownloadProgress();
|
||||
progressTimer = setInterval(updateDownloadProgress, 1000);
|
||||
}
|
||||
|
||||
// Download file
|
||||
XHR.get(appUpdateUrl, {
|
||||
token: tokenStr,
|
||||
url: appInfo ? appInfo.data.browser_download_url : '',
|
||||
size: appInfo ? appInfo.data.size / 1024 : null
|
||||
size: appInfo ? appInfo.data.size / 1024 : null,
|
||||
id: downloadId
|
||||
}, function (x, json) {
|
||||
stopDownloadProgress();
|
||||
if (json.code) {
|
||||
removePageNotice();
|
||||
onRequestError(btn, json.error);
|
||||
|
||||
@@ -1776,7 +1776,7 @@ local function curl(url, file, ua, mode)
|
||||
}
|
||||
|
||||
ua = (ua and ua ~= "") and ua or "passwall"
|
||||
ua = (ua == "passwall") and ("passwall/" .. api.get_version()) or ua
|
||||
ua = (ua == "passwall") and ("passwall/" .. api.get_version():match("^([^-]+)")) or ua
|
||||
curl_args[#curl_args + 1] = '--user-agent "' .. ua .. '"'
|
||||
|
||||
local cookie_file = "/tmp/cookie_" .. api.gen_random_char(5)
|
||||
|
||||
Reference in new issue
Block a user