hook up on download button

This commit is contained in:
tdgao
2026-03-20 11:52:38 -06:00
parent 0a05061bf7
commit 672757c295
4 changed files with 131 additions and 18 deletions
@@ -234,6 +234,7 @@
v-bind="subscription.serverInfo"
:pending-change="getPendingChange(subscription)"
:cancellation-date="getCancellationDate(subscription)"
:on-download-backup="getLatestBackupDownload(subscription.serverInfo)"
/>
<div v-else class="w-fit">
<p>
@@ -765,6 +766,11 @@ const { data: serversData } = useQuery({
queryFn: () => client.archon.servers_v0.list(),
})
const { data: serverFullList } = useQuery({
queryKey: ['servers', 'v1'],
queryFn: () => client.archon.servers_v1.list(),
})
const midasProduct = ref(products.find((x) => x.metadata?.type === 'midas'))
const midasSubscription = computed(() =>
subscriptions.value?.find(
@@ -990,6 +996,46 @@ const resubscribePyro = async (subscriptionId, wasSuspended) => {
}
}
function getLatestBackupDownload(serverInfo) {
const serverFull = serverFullList.value?.find((s) => s.id === serverInfo.server_id)
if (!serverFull) return null
const activeWorld = serverFull.worlds.find((w) => w.is_active) ?? serverFull.worlds[0]
if (!activeWorld?.backups?.length) return null
const latestBackup = activeWorld.backups
.filter((b) => b.status === 'done')
.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())[0]
if (!latestBackup) return null
return async () => {
try {
const server = await client.archon.servers_v0.get(serverInfo.server_id)
const kyrosUrl = server.node?.instance
const jwt = server.node?.token
if (!kyrosUrl || !jwt) {
addNotification({
title: 'Download unavailable',
text: 'Server connection info is not available. Please contact support.',
type: 'error',
})
return
}
window.open(
`https://${kyrosUrl}/modrinth/v0/backups/${latestBackup.id}/download?auth=${jwt}`,
'_blank',
)
} catch {
addNotification({
title: 'Download failed',
text: 'An error occurred while trying to download the backup.',
type: 'error',
})
}
}
}
const refresh = async () => {
await Promise.all([
queryClient.invalidateQueries({ queryKey: ['billing'] }),