From 964e5c096e35f1e27113b5c92f4f16242dd2f798 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Fri, 5 Jun 2020 22:41:21 -1000 Subject: [PATCH] fix autocomplete + buildate, move exampels autocomplete never worked because of wrong files naming. The package index file is called `index.json` and now available on the ASU server. The build date never worked for images created by the official OpenWrt build bots, fixed by reading the `last-modified` header. Examples files are now in their own folders to follow the structure of ASU, which offers not only profiles but also package information in the version folders. Signed-off-by: Paul Spooren --- config.js | 8 +++---- index.js | 22 +++++++++++-------- .../profiles.json} | 0 .../profiles.json} | 0 .../profiles.json} | 0 5 files changed, 16 insertions(+), 14 deletions(-) rename misc/{names-18.06.7.json => 18.06.7/profiles.json} (100%) rename misc/{names-19.07.1.json => 19.07.1/profiles.json} (100%) rename misc/{names-SNAPSHOT.json => snapshot/profiles.json} (100%) diff --git a/config.js b/config.js index d5e6891..475b625 100644 --- a/config.js +++ b/config.js @@ -1,4 +1,3 @@ - var config = { // Default language, see i18n.js language: 'en', @@ -6,10 +5,9 @@ var config = { showHelp: true, // Files to get data from versions: { - //'SNAPSHOT': '/api/names/SNAPSHOT', // when using sasu backend - 'SNAPSHOT': 'misc/names-SNAPSHOT.json', - '19.07.1': 'misc/names-19.07.1.json', - '18.06.7': 'misc/names-18.06.7.json' + 'SNAPSHOT': 'misc/snapshot', + '19.07.1': 'misc/19.07.1', + '18.06.7': 'misc/18.06.7' }, // Build custom images // See https://github.com/aparcar/asu diff --git a/index.js b/index.js index 038b404..4b6cb28 100644 --- a/index.js +++ b/index.js @@ -278,9 +278,9 @@ function setupAutocompleteList(input, items, as_list, onbegin, onend) { } // for attended sysupgrade -function updatePackageList(target) { +function updatePackageList(version, target) { // set available packages - fetch(config.asu_url + '/' + target + '/packages.json') + fetch(config.versions[version] + '/' + target + '/index.json') .then(response => response.json()) .then(all_packages => { setupAutocompleteList($('packages'), all_packages, true, _ => {}, textarea => { @@ -375,7 +375,7 @@ function updateImages(version, code, date, model, url, mobj, is_custom) { } if (config.asu_url) { - updatePackageList(target); + updatePackageList(version, target); } show('images'); @@ -385,9 +385,14 @@ function updateImages(version, code, date, model, url, mobj, is_custom) { } function init() { + var build_date = "unknown" setupSelectList($('versions'), Object.keys(config.versions), version => { - fetch(config.versions[version]).then(data => { - data.json().then(obj => { + fetch(config.versions[version] + '/profiles.json') + .then(obj => { + build_date = obj.headers.get('last-modified'); + return obj.json(); + }) + .then(obj => { // handle native openwrt json format if ('profiles' in obj) { obj['models'] = {} @@ -397,15 +402,15 @@ function init() { } } return obj - }).then(obj => { + }) + .then(obj => { setupAutocompleteList($('models'), Object.keys(obj['models']), false, updateImages, models => { var model = models.value; if (model in obj['models']) { var url = obj.url || 'unknown'; var code = obj.version_code || 'unknown'; - var date = obj.build_date || 'unknown'; var mobj = obj['models'][model]; - updateImages(version, code, date, model, url, mobj, false); + updateImages(version, code, build_date, model, url, mobj, false); current_model = mobj; } else { updateImages(); @@ -417,7 +422,6 @@ function init() { $('models').onfocus(); }); }); - }); if (config.asu_url) { show('custom'); diff --git a/misc/names-18.06.7.json b/misc/18.06.7/profiles.json similarity index 100% rename from misc/names-18.06.7.json rename to misc/18.06.7/profiles.json diff --git a/misc/names-19.07.1.json b/misc/19.07.1/profiles.json similarity index 100% rename from misc/names-19.07.1.json rename to misc/19.07.1/profiles.json diff --git a/misc/names-SNAPSHOT.json b/misc/snapshot/profiles.json similarity index 100% rename from misc/names-SNAPSHOT.json rename to misc/snapshot/profiles.json -- 2.30.2