11import type { Archon , Labrinth } from '@modrinth/api-client'
22import {
3- addPendingServerContentInstalls ,
43 type BrowseInstallPlan ,
54 type BrowseSelectedProject ,
65 createContext ,
@@ -12,12 +11,11 @@ import {
1211 injectModrinthClient ,
1312 injectNotificationManager ,
1413 type ModpackSearchResult ,
15- type PendingServerContentInstall ,
16- type PendingServerContentInstallType ,
1714 readStoredServerInstallQueue ,
18- removePendingServerContentInstall ,
1915 resolveServerAddonInstallPlans ,
20- writePendingServerContentInstallBaseline ,
16+ useServerContextRuntime ,
17+ useServerPanelSync ,
18+ waitForServerContextRuntimeReady ,
2119 writeStoredServerInstallQueue ,
2220} from '@modrinth/ui'
2321import { useQueryClient } from '@tanstack/vue-query'
@@ -30,7 +28,6 @@ type InstallableSearchResult = Labrinth.Search.v3.ResultSearchProject & {
3028 installing ?: boolean
3129 installed ?: boolean
3230}
33- type PendingServerContentInstallInput = Omit < PendingServerContentInstall , 'createdAt' >
3431
3532export interface ServerModpackSelectionRequest {
3633 projectId : string
@@ -96,61 +93,6 @@ function readQueryString(value: unknown): string | null {
9693 return typeof value === 'string' && value . length > 0 ? value : null
9794}
9895
99- function getQueuedInstallOwnerFallback ( project : InstallableSearchResult ) {
100- if ( project . organization ) {
101- const ownerId = project . organization_id ?? project . organization
102- return {
103- id : ownerId ,
104- name : project . organization ,
105- type : 'organization' as const ,
106- link : `https://modrinth.com/organization/${ ownerId } ` ,
107- }
108- }
109-
110- if ( ! project . author ) return null
111-
112- const ownerId = project . author_id ?? project . author
113- return {
114- id : ownerId ,
115- name : project . author ,
116- type : 'user' as const ,
117- link : `/user/${ encodeURIComponent ( ownerId ) } ` ,
118- }
119- }
120-
121- function getQueuedAddonInstallPlans (
122- plans : Map < string , BrowseInstallPlan < InstallableSearchResult > > ,
123- ) {
124- return Array . from ( plans . values ( ) ) . filter ( ( plan ) => plan . contentType !== 'modpack' )
125- }
126-
127- function getQueuedInstallPlaceholder (
128- plan : BrowseInstallPlan < InstallableSearchResult > ,
129- owner : PendingServerContentInstallInput [ 'owner' ] ,
130- ) : PendingServerContentInstallInput {
131- const project = plan . project as InstallableSearchResult & { slug ?: string | null }
132- return {
133- projectId : plan . projectId ,
134- versionId : plan . versionId ,
135- contentType : plan . contentType as PendingServerContentInstallType ,
136- title : project . name ?? 'Project' ,
137- versionName : plan . versionName ?? null ,
138- versionNumber : plan . versionNumber ?? null ,
139- fileName : plan . fileName ?? null ,
140- owner,
141- slug : project . slug ?? plan . projectId ,
142- iconUrl : project . icon_url ?? null ,
143- }
144- }
145-
146- function getQueuedInstallPlaceholderFallbacks (
147- plans : Map < string , BrowseInstallPlan < InstallableSearchResult > > ,
148- ) {
149- return getQueuedAddonInstallPlans ( plans ) . map ( ( plan ) =>
150- getQueuedInstallPlaceholder ( plan , getQueuedInstallOwnerFallback ( plan . project ) ) ,
151- )
152- }
153-
15496export function createServerInstallContent ( opts : {
15597 serverSetupModalRef : Ref < ServerSetupModalHandle | null >
15698} ) {
@@ -173,6 +115,7 @@ export function createServerInstallContent(opts: {
173115 const isFromWorlds = computed ( ( ) => browseFrom . value === 'worlds' )
174116 const isServerContext = computed ( ( ) => ! ! serverIdQuery . value )
175117 const isSetupServerContext = computed ( ( ) => ! ! serverIdQuery . value && ! ! serverFlowFrom . value )
118+ useServerContextRuntime ( serverIdQuery )
176119
177120 const serverContextWorldId = ref < string | null > ( worldIdQuery . value )
178121
@@ -199,7 +142,6 @@ export function createServerInstallContent(opts: {
199142 initialServerId ? getCachedServer ( initialServerId ) : null ,
200143 )
201144 const serverContentProjectIds = ref < Set < string > > ( new Set ( ) )
202- const serverContentInstallKeys = ref < Set < string > > ( new Set ( ) )
203145 const queuedServerInstalls = ref < Map < string , BrowseInstallPlan < InstallableSearchResult > > > (
204146 new Map ( ) ,
205147 )
@@ -220,6 +162,10 @@ export function createServerInstallContent(opts: {
220162 const isInstallingQueuedServerInstalls = ref ( false )
221163 const queuedInstallProgress = ref ( { completed : 0 , total : 0 } )
222164 const effectiveServerWorldId = computed ( ( ) => worldIdQuery . value ?? serverContextWorldId . value )
165+ useServerPanelSync ( {
166+ serverId : serverIdQuery ,
167+ worldId : effectiveServerWorldId ,
168+ } )
223169 const serverBackUrl = computed ( ( ) => {
224170 const sid = serverIdQuery . value
225171 if ( ! sid ) return '/hosting/manage'
@@ -265,11 +211,7 @@ export function createServerInstallContent(opts: {
265211 . map ( ( addon ) => addon . project_id )
266212 . filter ( ( projectId ) : projectId is string => ! ! projectId ) ,
267213 )
268- const keys = new Set (
269- ( content . addons ?? [ ] ) . map ( ( addon ) => addon . project_id ?? addon . filename ) ,
270- )
271214 serverContentProjectIds . value = ids
272- serverContentInstallKeys . value = keys
273215 } catch ( err ) {
274216 handleError ( err as Error )
275217 }
@@ -311,14 +253,12 @@ export function createServerInstallContent(opts: {
311253 serverContextWorldId . value = null
312254 serverContextServerData . value = null
313255 serverContentProjectIds . value = new Set ( )
314- serverContentInstallKeys . value = new Set ( )
315256 setQueuedServerInstallPlans ( new Map ( ) )
316257 return
317258 }
318259
319260 if ( sid !== prevSid ) {
320261 serverContentProjectIds . value = new Set ( )
321- serverContentInstallKeys . value = new Set ( )
322262 queuedServerInstalls . value = readStoredServerInstallQueue ( sid , wid )
323263 serverContextServerData . value = getCachedServer ( sid )
324264 try {
@@ -487,6 +427,13 @@ export function createServerInstallContent(opts: {
487427 const queuedPlans = getStoredServerAddonInstallQueue < InstallableSearchResult > ( serverId , worldId )
488428 if ( queuedPlans . size === 0 ) return true
489429
430+ try {
431+ await waitForServerContextRuntimeReady ( client , serverId )
432+ } catch ( error ) {
433+ handleError ( error as Error )
434+ return false
435+ }
436+
490437 isInstallingQueuedServerInstalls . value = true
491438 queuedInstallProgress . value = {
492439 completed : 0 ,
@@ -507,9 +454,6 @@ export function createServerInstallContent(opts: {
507454 } )
508455
509456 if ( ! result . ok ) {
510- for ( const plan of result . attemptedPlans ) {
511- removePendingServerContentInstall ( serverId , worldId , plan . projectId )
512- }
513457 handleError ( result . error as Error )
514458 return false
515459 }
@@ -522,10 +466,6 @@ export function createServerInstallContent(opts: {
522466 ...serverContentProjectIds . value ,
523467 ...result . flushedPlans . map ( ( plan ) => plan . projectId ) ,
524468 ] )
525- serverContentInstallKeys . value = new Set ( [
526- ...serverContentInstallKeys . value ,
527- ...result . flushedPlans . map ( ( plan ) => plan . projectId ) ,
528- ] )
529469 if ( result . flushedPlans . length > 0 ) {
530470 await queryClient . invalidateQueries ( { queryKey : [ 'content' , 'list' , 'v1' , serverId ] } )
531471 }
@@ -550,8 +490,6 @@ export function createServerInstallContent(opts: {
550490
551491 if ( sid && wid ) {
552492 writeStoredServerInstallQueue ( sid , wid , plans )
553- writePendingServerContentInstallBaseline ( sid , wid , serverContentInstallKeys . value )
554- addPendingServerContentInstalls ( sid , wid , getQueuedInstallPlaceholderFallbacks ( plans ) )
555493 }
556494 const installed = await flushQueuedServerInstalls ( sid , wid )
557495 if ( ! installed ) return false
0 commit comments