From 250dcf7a6dac2a97de27f27c372ec999057c708c Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Sun, 24 May 2020 12:27:41 -1000 Subject: [PATCH] support upstream json format Signed-off-by: Paul Spooren --- config.js | 2 ++ index.js | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/config.js b/config.js index d5e6891..7a19d50 100644 --- a/config.js +++ b/config.js @@ -4,6 +4,8 @@ var config = { language: 'en', // Show help text for images showHelp: true, + // base URL + base_url: 'https://downloads.openwrt.org', // Files to get data from versions: { //'SNAPSHOT': '/api/names/SNAPSHOT', // when using sasu backend diff --git a/index.js b/index.js index ce5f4b4..df13208 100644 --- a/index.js +++ b/index.js @@ -17,22 +17,30 @@ function split(str) { return str.match(/[^\s,]+/g) || []; } +function get_model_titles(titles) { + return titles.map(e => { + if (e.title) { + return e.title; + } else { + return ((e.vendor || '') + ' ' + (e.model || '') + ' ' + (e.variant || '')).trim(); + } + }).join(' / '); +} + +function get_version_url(version) { + if (version == 'SNAPSHOT') { + return config.base_url + '/snapshots/targets/{target}' + } else { + return config.base_url + '/releases/{version}/targets/{target}'.replace('{version}', version) + } +} + function build_asa_request() { if (!current_model || !current_model.id) { alert('bad profile'); return; } - function get_model_titles(titles) { - return titles.map(e => { - if (e.title) { - return e.title; - } else { - return ((e.vendor || '') + ' ' + (e.model || '') + ' ' + (e.variant || '')).trim(); - } - }).join('/'); - } - function showStatus(text) { show('buildstatus'); $('buildstatus').innerHTML = text; @@ -388,6 +396,17 @@ function init() { setupSelectList($('versions'), Object.keys(config.versions), version => { fetch(config.versions[version]).then(data => { data.json().then(obj => { + // handle native openwrt json format + if ('profiles' in obj) { + obj['url'] = get_version_url(version) + obj['models'] = {} + for (const [key, value] of Object.entries(obj['profiles'])) { + obj['models'][get_model_titles(value.titles)] = value + obj['models'][get_model_titles(value.titles)]['id'] = key + } + } + return obj + }).then(obj => { setupAutocompleteList($('models'), Object.keys(obj['models']), false, updateImages, models => { var model = models.value; if (model in obj['models']) { -- 2.30.2