Align dashboard and installer flows with spec
This commit is contained in:
@@ -3,6 +3,7 @@ import { fetchReleaseVersions } from '../../shared/mojang'
|
||||
import {
|
||||
createNewPack,
|
||||
deletePacks,
|
||||
listDashboardPacks,
|
||||
loadAccounts,
|
||||
loadPackDefinition,
|
||||
loadRootManifest,
|
||||
@@ -59,10 +60,10 @@ opRouter.post('/op/logout', requireAuth, (req, res) => {
|
||||
|
||||
opRouter.get('/op/dashboard', requireAuth, async (_req, res, next) => {
|
||||
try {
|
||||
const manifest = await loadRootManifest()
|
||||
const packs = await listDashboardPacks()
|
||||
res.render('op/dashboard', {
|
||||
userId: _req.session.userId,
|
||||
packs: manifest.packs
|
||||
packs
|
||||
})
|
||||
} catch (error) {
|
||||
next(error)
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from 'node:fs'
|
||||
import fsp from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import { accountPath, fileDir, manifestDir, manifestRootPath } from './paths'
|
||||
import { AccountEntry, PackDefinition, PackListEntry, RootManifest } from './types'
|
||||
import { AccountEntry, DashboardPackEntry, PackDefinition, PackListEntry, RootManifest } from './types'
|
||||
|
||||
const defaultRootManifest: RootManifest = {
|
||||
packs: [
|
||||
@@ -93,6 +93,22 @@ export async function listManifestFiles(): Promise<string[]> {
|
||||
.sort((left, right) => left.localeCompare(right))
|
||||
}
|
||||
|
||||
export async function listDashboardPacks(): Promise<DashboardPackEntry[]> {
|
||||
const [manifestFiles, rootManifest] = await Promise.all([
|
||||
listManifestFiles(),
|
||||
loadRootManifest()
|
||||
])
|
||||
|
||||
return manifestFiles.map((file) => {
|
||||
const registeredPack = rootManifest.packs.find((entry) => entry.file === file)
|
||||
return {
|
||||
file,
|
||||
name: registeredPack?.name ?? file,
|
||||
registered: registeredPack != null
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function loadPackDefinition(packKey: string): Promise<PackDefinition | null> {
|
||||
await ensureProjectFiles()
|
||||
const safeKey = sanitizePackKey(packKey)
|
||||
|
||||
@@ -3,6 +3,10 @@ export interface PackListEntry {
|
||||
file: string
|
||||
}
|
||||
|
||||
export interface DashboardPackEntry extends PackListEntry {
|
||||
registered: boolean
|
||||
}
|
||||
|
||||
export interface RootManifest {
|
||||
packs: PackListEntry[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user