Adding working board

This commit is contained in:
2026-08-17 09:24:53 +02:00
parent 35685f765a
commit 0237da74cf
18 changed files with 1365 additions and 738 deletions
+12 -15
View File
@@ -29,10 +29,6 @@ function requireOk(response: Response, action: string) {
return response.text().then(body => { throw new Error(`${action} failed (${response.status}): ${body}`) })
}
function documentKind(type: SourceFileType) {
return type === 'web_capture' ? 'WEB CAPTURE' : type.toUpperCase()
}
async function uploadAsset(baseUrl: string, levelId: string, manifestDir: string, document: MysteryDocument, authorization?: string) {
if (!document.asset) return undefined
const assetPath = path.resolve(manifestDir, document.asset)
@@ -55,12 +51,15 @@ export async function importMysteryTemplate(manifestPath: string, baseUrl = 'htt
}), 'Create authoring level')
const state = await createdResponse.json() as CaseState
const documentPositions = new Map<string, { x: number; y: number }>()
manifest.folders.forEach((folder, folderIndex) => folder.members.forEach((key, memberIndex) => documentPositions.set(key, { x: folder.x + 70 + memberIndex * 205, y: folder.y + 230 + folderIndex * 35 })))
const documents = new Map<string, CaseDocument>()
for (const source of manifest.documents) {
const uploaded = await uploadAsset(baseUrl, state.id, manifestDir, source, authorization)
documents.set(source.key, {
id: uploaded?.id || randomUUID(), title: source.title, kind: documentKind(source.fileType),
date: source.publishedAt.slice(0, 10), publishedAt: source.publishedAt,
id: uploaded?.id || randomUUID(), type: 'document', title: source.title, publishedAt: source.publishedAt,
x: documentPositions.get(source.key)?.x || 100, y: documentPositions.get(source.key)?.y || 100,
width: uploaded?.width || 174, height: uploaded?.height || 145, rotation: 0, zIndex: uploaded?.zIndex || 1, hidden: false,
body: source.body || [], regions: [], assetId: uploaded?.assetId,
fileName: uploaded?.fileName, mimeType: uploaded?.mimeType, fileSize: uploaded?.fileSize,
fileType: source.fileType, metadata: source.metadata || {},
@@ -69,20 +68,18 @@ export async function importMysteryTemplate(manifestPath: string, baseUrl = 'htt
const folderIds = new Map(manifest.folders.map(folder => [folder.key, randomUUID()]))
state.brief = { body: manifest.brief.body, concepts: manifest.brief.concepts.map(concept => ({ id: randomUUID(), ...concept })) }
state.timelineRange = manifest.timelineRange
state.documents = [...documents.values()]
state.evidence = manifest.folders.map(folder => ({
state.views = state.views.map(view => view.type === 'timeline' ? { ...view, rangeMode: manifest.timelineRange ? 'fixed' : 'auto', range: manifest.timelineRange } : view)
const folders = manifest.folders.map(folder => ({
id: folderIds.get(folder.key)!, type: 'folder', title: folder.title, content: folder.content,
x: folder.x, y: folder.y, width: folder.width, config: { open: false },
containedDocumentIds: folder.members.map(key => documents.get(key)!.id),
}))
state.relations = manifest.folders.flatMap((folder, folderIndex) => folder.members.map((key, memberIndex) => {
x: folder.x, y: folder.y, width: folder.width, height: 166, rotation: 0, zIndex: 1, hidden: false, isOpen: false,
} as const))
state.exhibits = [...documents.values(), ...folders]
state.relations = manifest.folders.flatMap(folder => folder.members.map((key, memberIndex) => {
const document = documents.get(key)
if (!document) throw new Error(`Folder ${folder.key} refers to unknown document ${key}`)
return {
id: `contains:${folderIds.get(folder.key)}:${document.id}`,
fromWidgetId: folderIds.get(folder.key)!, toWidgetId: document.id, type: 'contains', sortOrder: memberIndex,
config: { x: folder.x + 70 + memberIndex * 205, y: folder.y + 230 + folderIndex * 35 },
fromExhibitId: folderIds.get(folder.key)!, toExhibitId: document.id, type: 'contains' as const, sortOrder: memberIndex,
}
}))
state.connections = []