From b5c18c1fa29e381ed8fd0f859742bdf549b8e669 Mon Sep 17 00:00:00 2001 From: jduncanator <1518948+jduncanator@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:50:47 +1100 Subject: [PATCH] view/download: Fallback to the previous build if the current build is still in progress (#41) --- .env.development | 2 +- .env.production | 2 +- src/views/DownloadPage.vue | 93 ++++++++++++++++++++++---------------- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/.env.development b/.env.development index aa2ae2e..37754c4 100644 --- a/.env.development +++ b/.env.development @@ -5,7 +5,7 @@ VITE_FAQ_URL=https://ryujinx.org/faq VITE_COMPATIBILITY_URL=https://github.com/Ryujinx/Ryujinx-Games-List/issues VITE_GUIDE_URL=https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide VITE_DISCORD_URL=https://discord.gg/VkQYXAZ -VITE_RELEASE_URL=https://api.github.com/repos/Ryujinx/release-channel-master/releases/latest +VITE_RELEASE_URL="https://api.github.com/repos/Ryujinx/release-channel-master/releases?per_page=2" VITE_OLDER_BUILDS_URL=https://github.com/Ryujinx/release-channel-master/releases VITE_LDN_BUILD_URL=https://www.patreon.com/posts/ldn-2-5-vulkan-70757628 VITE_PATREON_URL=https://patreon.com/Ryujinx diff --git a/.env.production b/.env.production index cc905f6..731f714 100644 --- a/.env.production +++ b/.env.production @@ -5,7 +5,7 @@ VITE_FAQ_URL=https://ryujinx.org/faq VITE_COMPATIBILITY_URL=https://github.com/Ryujinx/Ryujinx-Games-List/issues VITE_GUIDE_URL=https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide VITE_DISCORD_URL=https://discord.gg/VkQYXAZ -VITE_RELEASE_URL=https://api.github.com/repos/Ryujinx/release-channel-master/releases/latest +VITE_RELEASE_URL="https://api.github.com/repos/Ryujinx/release-channel-master/releases?per_page=2" VITE_OLDER_BUILDS_URL=https://github.com/Ryujinx/release-channel-master/releases VITE_LDN_BUILD_URL=https://www.patreon.com/posts/introducing-ldn3-74910544 VITE_PATREON_URL=https://patreon.com/Ryujinx diff --git a/src/views/DownloadPage.vue b/src/views/DownloadPage.vue index 5a6c40c..116998b 100644 --- a/src/views/DownloadPage.vue +++ b/src/views/DownloadPage.vue @@ -9,51 +9,66 @@ import { InformationCircleIcon, } from "@heroicons/vue/solid"; -import { DownloadRelease } from "@/types"; +import { DownloadAsset, DownloadRelease } from "@/types"; const GUIDE_URL = import.meta.env.VITE_GUIDE_URL as string; const LDN_BUILD_URL = import.meta.env.VITE_LDN_BUILD_URL as string; const OLDER_BUILD_URL = import.meta.env.VITE_OLDER_BUILDS_URL as string; const { t } = useI18n(); const isLoading = ref(true); -const downloadRelease = ref({} as DownloadRelease); -const macosBuildUrl = ref(""); -const linuxIntelBuildUrl = ref(""); -const linuxArm64BuildUrl = ref(""); -const windowBuildUrl = ref(""); + +type Release = { + release: DownloadRelease; + asset: DownloadAsset; +}; + +const releaseMap = { + "win-x64": /win_x64\.zip/, + "lin-x64": /linux_x64\.tar\.gz/, + "lin-arm64": /linux_arm64\.tar\.gz/, + "macos": /macos_universal\.app\.tar\.gz/ +} + +type ReleaseTargets = keyof typeof releaseMap; + +const downloadReleases = ref([]); +const releases = ref<{ [K in ReleaseTargets]?: Release }>({}); onMounted(() => { fetchBuilds(); }); const totalDownload = computed(() => { - let total = 0; - - downloadRelease.value?.assets.forEach((a) => (total += a.download_count)); - - return total; + return downloadReleases.value[0] + .assets.reduce((total, asset) => total + asset.download_count, 0) }); const fetchBuilds = async () => { try { - const result = await axios.get( + const result = await axios.get( import.meta.env.VITE_RELEASE_URL ); - downloadRelease.value = result.data; + downloadReleases.value = result.data; - downloadRelease.value?.assets.forEach((asset) => { - if (asset.name.startsWith("ryujinx")) { - if (asset.name.endsWith("win_x64.zip")) { - windowBuildUrl.value = asset.browser_download_url; - } else if (asset.name.endsWith("linux_x64.tar.gz")) { - linuxIntelBuildUrl.value = asset.browser_download_url; - } else if (asset.name.endsWith("linux_arm64.tar.gz")) { - linuxArm64BuildUrl.value = asset.browser_download_url; - } else if (asset.name.endsWith("macos_universal.app.tar.gz")) { - macosBuildUrl.value = asset.browser_download_url; + const targets = Object.keys(releaseMap) as Array; + result.data.forEach(release => { + targets.forEach(target => { + if(releases.value[target]) { + return; } - } + + const asset = release.assets + .filter(asset => asset.name.startsWith("ryujinx")) + .find(asset => asset.name.match(releaseMap[target])); + + if(asset) { + releases.value[target] = { + release, + asset + }; + } + }); }); } catch (err) { console.error(err); @@ -85,14 +100,14 @@ const fetchBuilds = async () => {