From 7334b5ad25099a9b3073073685b4655011a8b6f7 Mon Sep 17 00:00:00 2001 From: OMGDuke Date: Tue, 9 Apr 2024 21:32:37 +0100 Subject: [PATCH] Sort piped instances by uptime --- src/actions/audio.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/actions/audio.ts b/src/actions/audio.ts index 28ad418..c378c78 100644 --- a/src/actions/audio.ts +++ b/src/actions/audio.ts @@ -83,8 +83,8 @@ export async function getAudioUrlFromVideoId( res.result?.body ) - const audios = audioFormats.audioStreams.filter( - (aud) => aud.mimeType?.includes('audio/webm') + const audios = audioFormats.audioStreams.filter((aud) => + aud.mimeType?.includes('audio/webm') ) const audio = audios.reduce((prev, current) => { return prev.bitrate > current.bitrate ? prev : current @@ -149,12 +149,14 @@ export async function getPipedInstances( }[] = JSON.parse(res.result?.body) if (instances?.length) { - return instances.map((ins) => ({ - name: `${ins.locations} ${ins.name || ins.api_url} ${ - ins.uptime_30d ? `| Uptime (30d): ${Math.floor(ins.uptime_30d)}%` : '' - }`, - url: ins.api_url - })) + return instances + .sort((a, b) => b.uptime_30d - a.uptime_30d) + .map((ins) => ({ + name: `${ins.locations} ${ins.name || ins.api_url} ${ + ins.uptime_30d ? `| Uptime: ${Math.floor(ins.uptime_30d)}%` : '' + }`, + url: ins.api_url + })) } return [] }