@@ -5,6 +5,7 @@ import { computed, type ComputedRef, ref } from 'vue'
55import { injectModrinthClient } from '#ui/providers'
66
77type UpstreamRef = ComputedRef < Archon . Servers . v0 . Server [ 'upstream' ] | null | undefined >
8+ type ServerIdSource = string | { readonly value : string }
89
910type UseServerImageOptions = {
1011 enabled ?: ComputedRef < boolean > | boolean
@@ -39,32 +40,35 @@ function isNotFound(error: unknown): boolean {
3940}
4041
4142export function useServerImage (
42- serverId : string ,
43+ serverId : ServerIdSource ,
4344 upstream : UpstreamRef ,
4445 options : UseServerImageOptions = { } ,
4546) {
4647 const client = injectModrinthClient ( )
4748 const localImage = ref < string | null | undefined > ( undefined )
4849 const iconSize = options . size ?? 512
4950 const includeProjectFallback = options . includeProjectFallback ?? false
51+ const resolvedServerId = computed ( ( ) => resolveServerId ( serverId ) )
5052
5153 const queryKey = computed (
52- ( ) => [ 'servers' , 'detail' , serverId , 'icon' , upstream . value ?. project_id ?? null ] as const ,
54+ ( ) =>
55+ [ 'servers' , 'detail' , resolvedServerId . value , 'icon' , upstream . value ?. project_id ?? null ] as const ,
5356 )
5457
5558 const isEnabled = computed ( ( ) => {
5659 const explicitEnabled =
5760 typeof options . enabled === 'boolean' ? options . enabled : options . enabled ?. value
58- return ! ! serverId && ( explicitEnabled ?? true )
61+ return ! ! resolvedServerId . value && ( explicitEnabled ?? true )
5962 } )
6063
6164 const { data : remoteImage , refetch } = useQuery ( {
6265 queryKey,
6366 queryFn : async ( ) : Promise < string | null > => {
64- if ( ! serverId ) return null
67+ const id = resolvedServerId . value
68+ if ( ! id ) return null
6569
6670 try {
67- const fsAuth = await client . archon . servers_v0 . getFilesystemAuth ( serverId )
71+ const fsAuth = await client . archon . servers_v0 . getFilesystemAuth ( id )
6872
6973 try {
7074 const blob = await client . kyros . files_v0 . downloadFileWithAuth ( fsAuth , '/server-icon.png' )
@@ -132,3 +136,7 @@ export function useServerImage(
132136 resetLocalOverride,
133137 }
134138}
139+
140+ function resolveServerId ( serverId : ServerIdSource ) : string {
141+ return typeof serverId === 'string' ? serverId : serverId . value
142+ }
0 commit comments