Skip to content

Commit

Permalink
fix: downloads latest file selection (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaT82 authored Dec 13, 2023
1 parent cbb73fe commit f2ac3bc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 44 deletions.
9 changes: 6 additions & 3 deletions assets/css/downloads.css
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,13 @@ div#support.download-content > .dl-card div.dl-info-holder {
flex-grow: 1;
}

/* #linuxArchID,
.dropdown-container select,
#linuxArchID,
#osxArchID,
#windowsArchID */
.dropdown-container select {
#windowsArchID,
#linuxNetworkID,
#osxNetworkID,
#windowsNetworkID {
padding: 10px;
font-size: 16px;
border: 1px solid #ebebeb;
Expand Down
87 changes: 46 additions & 41 deletions assets/js/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ let OS = "";
const networks = ["nextnet", "testnet"]
let options = [{
os: "linux",
arch: [],
arch: ['arm64', 'x86_64'],
network: [],
},{
os: "osx",
arch: [],
arch: ['arm64', 'x86_64'],
network: [],
},{
os: "windows",
arch: [],
arch: ['x64'],
network: [],
}];
let currentNetwork = networks[0];
Expand All @@ -19,34 +19,34 @@ let networkUrlData = {};
let currentOS = "";
let currentArch = "";

function getArchValues() {
options.forEach(({os, arch}) => {
let selectElement = document.getElementById(`${os}ArchID`) || "";

if (selectElement !== "") {
for (let i = 0; i < selectElement.options.length; i++) {
let optionValue = selectElement.options[i].value;
arch.push(optionValue);
}
currentArch = arch[0];
}
});
}
getArchValues();

function getNetworkValues() {
options.forEach(({os, network}) => {
let selectElement = document.getElementById(`${os}NetworkID`) || "";

if (selectElement !== "") {
for (let i = 0; i < selectElement.options.length; i++) {
let optionValue = selectElement.options[i].value;
network.push(optionValue);
}
}
});
}
getNetworkValues();
// function getArchValues() {
// options.forEach(({os, arch}) => {
// let selectElement = document.getElementById(`${os}ArchID`) || "";

// if (selectElement !== "") {
// for (let i = 0; i < selectElement.options.length; i++) {
// let optionValue = selectElement.options[i].value;
// arch.push(optionValue);
// }
// currentArch = arch[0];
// }
// });
// }
// getArchValues();

// function getNetworkValues() {
// options.forEach(({os, network}) => {
// let selectElement = document.getElementById(`${os}NetworkID`) || "";

// if (selectElement !== "") {
// for (let i = 0; i < selectElement.options.length; i++) {
// let optionValue = selectElement.options[i].value;
// network.push(optionValue);
// }
// }
// });
// }
// getNetworkValues();

function ignoreFolders(data, foldersToIgnore) {
return Object.entries(data).reduce((acc, [os, binaries]) => {
Expand Down Expand Up @@ -237,59 +237,64 @@ jQuery(document).ready(function ($) {
return;
}
if (rawOs !== "libwallet") {

// filter by network
networks.forEach((network) => {
let nets = data[os].filter((key) => key.path.includes(network));

// filter by architecture
if (nets.length > 0) {
let btn = document.getElementById(`${rawOs}DL`);
let checkSumDiv = document.getElementById(`${rawOs}CSID`);

let filteredUrls = {};
options.forEach(({ os: archOs, arch: archList }) => {
if (rawOs === archOs) {

let filteredNetWithoutSha256 = nets.filter(net => !net.url.endsWith(".sha256"));

archList.forEach((archItem) => {
let filteredNet = nets.filter((net) => net.path.includes(archItem));
let filteredNet = filteredNetWithoutSha256.filter((net) => net.path.includes(archItem));
if (filteredNet.length > 0) {
let latest = filteredNet.reduce((a, b) => a.lastModified > b.lastModified || (a.lastModified == b.lastModified && a.url < b.url) ? a : b);
filteredUrls[archItem] = latest;
}
});
}
});

// create object for each arch/network
Object.keys(filteredUrls).forEach((arch) => {
let latest = filteredUrls[arch];
let sha256 = "";
let checksum = latest.sha256;

if (checksum) {
sha256 = checksum.split(" ")[0];
}

latest.checksum = checksum ? `SHA256: ${sha256}` : "";
latest.button = btn;
latest.checksumDiv = checkSumDiv;
latest.arch = arch;

if (!networkUrlData[rawOs]) {
networkUrlData[rawOs] = {};
}

if (!networkUrlData[rawOs][network]) {
networkUrlData[rawOs][network] = {};
}

networkUrlData[rawOs][network][arch] = latest;

});
}
});
}
});
}


function setInitialActive(os) {
switch (os) {
Expand Down

0 comments on commit f2ac3bc

Please sign in to comment.