diff --git a/.github/workflows/data.yml b/.github/workflows/data.yml index b78d4288..6166a8e0 100644 --- a/.github/workflows/data.yml +++ b/.github/workflows/data.yml @@ -70,6 +70,7 @@ jobs: python scripts/func.py getmodels -w "arc/ws" -j "docs/models.json" python scripts/func.py getaddons -w "arc/ws" -j "docs/addons.json" python scripts/func.py getmodules -w "arc/ws" -j "docs/modules.json" + python scripts/func.py getpats -w "arc/ws" -j "docs/pats.json" - name: Upload to Artifacts if: success() diff --git a/docs/custom.html b/docs/custom.html index 9365d072..6dc70730 100644 --- a/docs/custom.html +++ b/docs/custom.html @@ -54,6 +54,7 @@ var _models = {}; var _addons = {}; + var _pats = {}; function httpGetAsync(theUrl, callback) { let xmlHttpReq = new XMLHttpRequest(); @@ -72,13 +73,16 @@ function init() { httpGetAsync("https://raw.githubusercontent.com/AuxXxilium/arc/page/docs/models.json", function (result) { _models = JSON.parse(result); - httpGetAsync("https://raw.githubusercontent.com/AuxXxilium/arc/page/docs/addons.json", function (result) { - _addons = JSON.parse(result); - $("#model").on("change", changeModel); - $("#version").on("change", changeVersion); - $("#kernel").on("change", changeKernel); - $('#addons').val("acpid"); - setModels(); + httpGetAsync("https://raw.githubusercontent.com/AuxXxilium/arc/page/docs/pats.json", function (result) { + _pats = JSON.parse(result); + httpGetAsync("https://raw.githubusercontent.com/AuxXxilium/arc/page/docs/addons.json", function (result) { + _addons = JSON.parse(result); + $("#model").on("change", changeModel); + $("#version").on("change", changeVersion); + $("#kernel").on("change", changeKernel); + $('#addons').val("acpid,mountloader,powersched,reboottoloader"); + setModels(); + }); }); }); } @@ -98,11 +102,9 @@ function changeModel() { model = $("#model").val(); var versions = []; - for (var P in _models) { - if (_models[P]["models"].includes(model)) { - versions = Object.keys(_models[P]["productvers"]).reverse(); - break; - } + if (model in _pats) { + versions = Object.keys(_pats[model]); + versions.sort((a, b) => b.localeCompare(a)) } $("#version")[0].options.length = 0; for (var i = 0; i < versions.length; i++) { @@ -125,7 +127,6 @@ changeKernel(); } function createAddonsBtn() { - var language = $("#language").val(); var extstr = $('#addons').val().split(","); var idx = 1; var html = `
`; @@ -147,7 +148,7 @@ function changeKernel() { var model = $("#model").val(); - var version = $("#version").val(); + var version = $("#version").val().split(".").slice(0, 2).join("."); var kernel = $("#kernel").val(); if (model == "SA6400" && version == "7.2") { $("#kernel_item").show(); diff --git a/scripts/func.py b/scripts/func.py index 5678be8f..046f13df 100755 --- a/scripts/func.py +++ b/scripts/func.py @@ -56,6 +56,108 @@ def getmodels(workpath, jsonpath): with open(jsonpath, "w") as f: json.dump(models, f, indent=4, ensure_ascii=False) +@cli.command() +@click.option("-w", "--workpath", type=str, required=True, help="The workpath of Arc.") +@click.option("-j", "--jsonpath", type=str, required=True, help="The output path of jsonfile.") +def getpats(workpath, jsonpath): + def __fullversion(ver): + out = ver + arr = ver.split('-') + if len(arr) > 0: + a = arr[0].split('.')[0] if len(arr[0].split('.')) > 0 else '0' + b = arr[0].split('.')[1] if len(arr[0].split('.')) > 1 else '0' + c = arr[0].split('.')[2] if len(arr[0].split('.')) > 2 else '0' + d = arr[1] if len(arr) > 1 else '00000' + e = arr[2] if len(arr) > 2 else '0' + out = '{}.{}.{}-{}-{}'.format(a,b,c,d,e) + return out + + platforms = [] + models = [] + with open("{}/mnt/p3/configs/platforms.yml".format(workpath), "r") as f: + data = yaml.safe_load(f) + platforms = data.get("platforms", []) + + req = requests.get("https://autoupdate.synology.com/os/v2") + req.encoding = "utf-8" + data = json.loads(req.text) + + for I in data["channel"]["item"]: + if not I["title"].startswith("DSM"): + continue + for J in I["model"]: + arch = J["mUnique"].split("_")[1].lower() + name = J["mLink"].split("/")[-1].split("_")[1].replace("%2B", "+") + if arch not in platforms: + continue + if name in models: + continue + models.append(name) + + pats = {} + for M in models: + pats[M] = {} + version = '7' + urlInfo = "https://www.synology.com/api/support/findDownloadInfo?lang=en-us" + urlSteps = "https://www.synology.com/api/support/findUpgradeSteps?" + #urlInfo = "https://www.synology.cn/api/support/findDownloadInfo?lang=zh-cn" + #urlSteps = "https://www.synology.cn/api/support/findUpgradeSteps?" + + major = "&major={}".format(version.split('.')[0]) if len(version.split('.')) > 0 else "" + minor = "&minor={}".format(version.split('.')[1]) if len(version.split('.')) > 1 else "" + req = requests.get("{}&product={}{}{}".format(urlInfo, M.replace("+", "%2B"), major, minor)) + req.encoding = "utf-8" + data = json.loads(req.text) + + build_ver = data['info']['system']['detail'][0]['items'][0]['build_ver'] + build_num = data['info']['system']['detail'][0]['items'][0]['build_num'] + buildnano = data['info']['system']['detail'][0]['items'][0]['nano'] + V=__fullversion("{}-{}-{}".format(build_ver, build_num, buildnano)) + if not V in pats[M]: + pats[M][V]={} + pats[M][V]['url'] = data['info']['system']['detail'][0]['items'][0]['files'][0]['url'].split('?')[0] + pats[M][V]['sum'] = data['info']['system']['detail'][0]['items'][0]['files'][0]['checksum'] + + from_ver=0 + for I in data['info']['pubVers']: + if from_ver == 0 or I['build'] < from_ver: from_ver = I['build'] + + for I in data['info']['productVers']: + if not I['version'].startswith(version): continue + if major == "" or minor == "": + majorTmp = "&major={}".format(I['version'].split('.')[0]) if len(I['version'].split('.')) > 0 else "" + minorTmp = "&minor={}".format(I['version'].split('.')[1]) if len(I['version'].split('.')) > 1 else "" + reqTmp = requests.get("{}&product={}{}{}".format(urlInfo, M.replace("+", "%2B"), majorTmp, minorTmp)) + reqTmp.encoding = "utf-8" + dataTmp = json.loads(reqTmp.text) + + build_ver = dataTmp['info']['system']['detail'][0]['items'][0]['build_ver'] + build_num = dataTmp['info']['system']['detail'][0]['items'][0]['build_num'] + buildnano = dataTmp['info']['system']['detail'][0]['items'][0]['nano'] + V=__fullversion("{}-{}-{}".format(build_ver, build_num, buildnano)) + if not V in pats[M]: + pats[M][V]={} + pats[M][V]['url'] = dataTmp['info']['system']['detail'][0]['items'][0]['files'][0]['url'].split('?')[0] + pats[M][V]['sum'] = dataTmp['info']['system']['detail'][0]['items'][0]['files'][0]['checksum'] + + for J in I['versions']: + to_ver=J['build'] + reqSteps = requests.get("{}&product={}&from_ver={}&to_ver={}".format(urlSteps, M.replace("+", "%2B"), from_ver, to_ver)) + if reqSteps.status_code != 200: continue + reqSteps.encoding = "utf-8" + dataSteps = json.loads(reqSteps.text) + for S in dataSteps['upgrade_steps']: + if not 'full_patch' in S or S['full_patch'] is False: continue + if not 'build_ver' in S or not S['build_ver'].startswith(version): continue + V=__fullversion("{}-{}-{}".format(S['build_ver'], S['build_num'], S['nano'])) + if not V in pats[M]: + pats[M][V] = {} + pats[M][V]['url'] = S['files'][0]['url'].split('?')[0] + pats[M][V]['sum'] = S['files'][0]['checksum'] + + if jsonpath: + with open(jsonpath, "w") as f: + json.dump(pats, f, indent=4, ensure_ascii=False) @cli.command() @click.option("-w", "--workpath", type=str, required=True, help="The workpath of Arc.") diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 27320e5a..495ecaf5 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -1,3 +1,4 @@ +bs4 click kmodule requests