Skip to content

Commit 3c8fccf

Browse files
authored
feat: all files allowed for shared instances (#7991)
* feat: upload config files seperately, not as zips * fix(frontend): expand expands properly * feat: allow all files for shared instances * feat: skip downloading external files if hash matches * feat: prevent certain file uploads * refactor: redo push update modal * fix: alignment with figma * fix: merge changes * feat(app-lib): use batching endpoint * fix: align with prod shared instances * chore: resync PR * fix: parallise shared instance upload/download jobs + fix visual in task manager
1 parent 00753f6 commit 3c8fccf

63 files changed

Lines changed: 2778 additions & 1150 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ anyhow = "1.0.100"
3838
arc-swap = "1.7.1"
3939
argon2 = { version = "0.5.3", features = ["std"] }
4040
ariadne = { path = "packages/ariadne" }
41+
async-compression = "0.4.32"
4142
async-minecraft-ping = { path = "packages/async-minecraft-ping" }
4243
async-recursion = "1.1.1"
4344
async-stripe = { version = "0.41.0", default-features = false, features = [
@@ -113,6 +114,7 @@ iana-time-zone = "0.1.64"
113114
image = { version = "0.25.8", default-features = false, features = ["rayon"] }
114115
indexmap = "2.11.4"
115116
indicatif = "0.18.0"
117+
infer = "0.22.0"
116118
itertools = "0.14.0"
117119
jemalloc_pprof = "0.8.1"
118120
json-patch = { version = "4.1.0", default-features = false }

‎apps/app-frontend/src/components/ui/download-manager/download-manager-job.vue‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
PlayIcon,
99
TrashIcon,
1010
UpdatedIcon,
11+
UploadIcon,
1112
XIcon,
1213
} from '@modrinth/assets'
1314
import {
@@ -106,7 +107,11 @@ const instanceLink = computed(() =>
106107
>
107108
<component
108109
:is="
109-
job.kind === 'external-file' || job.kind === 'debug-export' ? DownloadIcon : BoxIcon
110+
job.kind === 'shared-instance-publish'
111+
? UploadIcon
112+
: job.kind === 'external-file' || job.kind === 'debug-export'
113+
? DownloadIcon
114+
: BoxIcon
110115
"
111116
class="size-6 text-primary"
112117
aria-hidden="true"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { reactive, ref } from 'vue'
2+
3+
const RATE_WINDOW_MS = 5000
4+
5+
export interface SharedInstancePublishTask {
6+
id: string
7+
instanceId: string
8+
instanceName: string
9+
iconPath: string | null
10+
status: 'running' | 'succeeded' | 'failed'
11+
uploadedBytes: number
12+
totalBytes: number
13+
rate: number
14+
createdAt: string
15+
finishedAt?: string
16+
error?: string
17+
details?: string
18+
}
19+
20+
export const sharedInstancePublishes = ref(new Map<string, SharedInstancePublishTask>())
21+
22+
export function findRunningSharedInstancePublish(instanceId: string) {
23+
for (const task of sharedInstancePublishes.value.values()) {
24+
if (task.instanceId === instanceId && task.status === 'running') return task
25+
}
26+
return null
27+
}
28+
29+
export function trackSharedInstancePublish(instance: {
30+
id: string
31+
name: string
32+
icon_path?: string | null
33+
}) {
34+
const task = reactive<SharedInstancePublishTask>({
35+
id: `shared-instance-publish-${crypto.randomUUID()}`,
36+
instanceId: instance.id,
37+
instanceName: instance.name,
38+
iconPath: instance.icon_path ?? null,
39+
status: 'running',
40+
uploadedBytes: 0,
41+
totalBytes: 0,
42+
rate: 0,
43+
createdAt: new Date().toISOString(),
44+
})
45+
sharedInstancePublishes.value.set(task.id, task)
46+
const samples: { time: number; bytes: number }[] = []
47+
48+
function finish(status: SharedInstancePublishTask['status']) {
49+
task.status = status
50+
task.finishedAt = new Date().toISOString()
51+
task.rate = 0
52+
}
53+
54+
return {
55+
update(uploadedBytes: number, totalBytes: number) {
56+
if (task.status !== 'running') return
57+
const now = performance.now()
58+
samples.push({ time: now, bytes: uploadedBytes })
59+
while (samples.length > 2 && now - samples[1].time >= RATE_WINDOW_MS) samples.shift()
60+
const oldest = samples[0]
61+
const elapsed = now - oldest.time
62+
task.rate = elapsed >= 1000 ? ((uploadedBytes - oldest.bytes) * 1000) / elapsed : 0
63+
task.uploadedBytes = uploadedBytes
64+
task.totalBytes = totalBytes
65+
},
66+
succeed() {
67+
finish('succeeded')
68+
},
69+
fail(error: string) {
70+
task.error = error
71+
finish('failed')
72+
},
73+
setDetails(details: string) {
74+
task.details = details
75+
},
76+
}
77+
}
78+
79+
export function getSharedInstancePublishRate(task: SharedInstancePublishTask) {
80+
return task.status === 'running' ? task.rate : 0
81+
}

‎apps/app-frontend/src/components/ui/download-manager/use-download-manager.ts‎

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ import {
3232
getExternalFileDownloadRate,
3333
} from './external-file-downloads'
3434
import { createInstallJobProgressTracker } from './install-job-progress'
35+
import {
36+
getSharedInstancePublishRate,
37+
sharedInstancePublishes,
38+
type SharedInstancePublishTask,
39+
} from './shared-instance-publishes'
3540
import { storeVerificationTask } from './store-verification'
3641
import { useInstallJobDisplay } from './use-install-job-display'
3742

3843
export interface DownloadManagerJob {
3944
id: string
40-
kind?: 'external-file' | 'debug-export'
45+
kind?: 'external-file' | 'debug-export' | 'shared-instance-publish'
4146
serverId?: string
4247
createdAt?: string
4348
instanceId: string | null
@@ -94,6 +99,21 @@ const debugExportMessages = defineMessages({
9499
canceling: { id: 'app.debug-export.canceling', defaultMessage: 'Canceling export…' },
95100
})
96101

102+
const publishMessages = defineMessages({
103+
preparing: {
104+
id: 'app.shared-instance-publish.preparing',
105+
defaultMessage: 'Preparing update…',
106+
},
107+
uploading: {
108+
id: 'app.shared-instance-publish.uploading',
109+
defaultMessage: 'Pushing update…',
110+
},
111+
pushed: {
112+
id: 'app.shared-instance-publish.pushed',
113+
defaultMessage: 'Update pushed',
114+
},
115+
})
116+
97117
function getIconUrl(icon: string | null | undefined): string | null {
98118
if (!icon) return null
99119
return /^(https?:|data:|blob:|asset:|tauri:)/.test(icon) ? icon : convertFileSrc(icon)
@@ -184,11 +204,15 @@ export function useDownloadManager() {
184204
const debugExportRows = computed(() =>
185205
[...debugInfoExports.value.values()].map(buildDebugExportRow),
186206
)
207+
const publishRows = computed(() =>
208+
[...sharedInstancePublishes.value.values()].map(buildPublishRow),
209+
)
187210
const allRows = computed(() => [
188211
...rows.value,
189212
...verificationRows.value,
190213
...fileRows.value,
191214
...debugExportRows.value,
215+
...publishRows.value,
192216
])
193217

194218
const activeJobs = computed(() =>
@@ -214,7 +238,12 @@ export function useDownloadManager() {
214238
display.formatRate(
215239
activeJobs.value.reduce((total, job) => {
216240
const file = externalFileDownloads.value.get(job.id)
217-
const fileRate = file ? getExternalFileDownloadRate(file, now.value) : null
241+
const publish = sharedInstancePublishes.value.get(job.id)
242+
const fileRate = file
243+
? getExternalFileDownloadRate(file, now.value)
244+
: publish
245+
? getSharedInstancePublishRate(publish)
246+
: null
218247
return total + (fileRate ?? transfer.get(job.id, now.value).rate ?? 0)
219248
}, 0),
220249
),
@@ -262,6 +291,53 @@ export function useDownloadManager() {
262291
}
263292
}
264293

294+
function buildPublishRow(task: SharedInstancePublishTask): DownloadManagerJob {
295+
const rate = getSharedInstancePublishRate(task)
296+
const uploading = task.totalBytes > 0
297+
const progress = uploading ? Math.min(0.99, task.uploadedBytes / task.totalBytes) : 0
298+
return {
299+
id: task.id,
300+
kind: 'shared-instance-publish',
301+
createdAt: task.createdAt,
302+
instanceId: task.instanceId,
303+
status: task.status,
304+
paused: false,
305+
canceling: false,
306+
canPause: false,
307+
canCancel: false,
308+
title: task.instanceName,
309+
iconUrl: getIconUrl(task.iconPath),
310+
text:
311+
task.error ??
312+
formatMessage(
313+
task.status === 'succeeded'
314+
? publishMessages.pushed
315+
: uploading
316+
? publishMessages.uploading
317+
: publishMessages.preparing,
318+
),
319+
finishedAt: task.finishedAt,
320+
progress,
321+
overallProgress: task.status === 'succeeded' ? 1 : progress,
322+
progressLabel:
323+
task.status === 'running' && uploading
324+
? [
325+
`${formatBytes(task.uploadedBytes)} / ${formatBytes(task.totalBytes)}`,
326+
display.formatRate(rate),
327+
]
328+
.filter(Boolean)
329+
.join(' · ')
330+
: '',
331+
waiting: !uploading,
332+
eta:
333+
rate && uploading ? display.formatEta((task.totalBytes - task.uploadedBytes) / rate) : '',
334+
canRetry: false,
335+
canCopyDetails: !!task.error || (appSettings.alwaysShowCopyDetails && !!task.details),
336+
copied: copiedJobs.value.has(task.id),
337+
busy: busyJobs.value.has(task.id),
338+
}
339+
}
340+
265341
function buildFileRow(task: ExternalFileDownloadTask): DownloadManagerJob {
266342
const rate = getExternalFileDownloadRate(task, now.value)
267343
const progress = task.totalBytes ? Math.min(0.99, task.downloadedBytes / task.totalBytes) : 0
@@ -491,6 +567,11 @@ export function useDownloadManager() {
491567
if (file.status !== 'running') externalFileDownloads.value.delete(id)
492568
return
493569
}
570+
const publish = sharedInstancePublishes.value.get(id)
571+
if (publish) {
572+
if (publish.status !== 'running') sharedInstancePublishes.value.delete(id)
573+
return
574+
}
494575
if (storeVerificationTask.value?.id === id) {
495576
if (storeVerificationTask.value.status !== 'running') storeVerificationTask.value = null
496577
return
@@ -512,8 +593,13 @@ export function useDownloadManager() {
512593

513594
async function copyDetails(id: string) {
514595
await runAction(id, async () => {
596+
const publish = sharedInstancePublishes.value.get(id)
515597
const file = externalFileDownloads.value.get(id) ?? debugInfoExports.value.get(id)
516-
const details = file ? (file.error ?? '') : await install_job_support_details(id)
598+
const details = publish
599+
? (publish.details ?? publish.error ?? '')
600+
: file
601+
? (file.error ?? '')
602+
: await install_job_support_details(id)
517603
if (disposed) return
518604
await navigator.clipboard.writeText(details)
519605
if (disposed) return

0 commit comments

Comments
 (0)