⚡ perf(vscode): 看板打开先出快照、评论只拉末页
This commit is contained in:
1 parent
904ab7491d
commit
a68caf5f6e
9 files changed
+447
-115
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import type { Issue } from '../gitea/types'
|
||||
|
||||
export const KANBAN_SNAPSHOT_KEY = 'superpowers.kanbanSnapshot'
|
||||
|
||||
export interface KanbanSnapshot {
|
||||
issues: Issue[]
|
||||
scope: 'mine' | 'all'
|
||||
me?: string
|
||||
globalAutoReview: boolean
|
||||
youtrackConfigured: boolean
|
||||
}
|
||||
|
||||
export function parseKanbanSnapshot(raw: unknown): KanbanSnapshot | null {
|
||||
if (!raw || typeof raw !== 'object')
|
||||
return null
|
||||
const obj = raw as Record<string, unknown>
|
||||
if (!Array.isArray(obj.issues))
|
||||
return null
|
||||
if (obj.scope !== 'mine' && obj.scope !== 'all')
|
||||
return null
|
||||
return {
|
||||
issues: obj.issues as Issue[],
|
||||
scope: obj.scope,
|
||||
me: typeof obj.me === 'string' ? obj.me : undefined,
|
||||
globalAutoReview: obj.globalAutoReview === true,
|
||||
youtrackConfigured: obj.youtrackConfigured === true,
|
||||
}
|
||||
}
|
||||
|
||||
/** 写入 HTML 的 JSON:小于号换成 \\u003c,避免 script 标签被提前关掉。 */
|
||||
export function snapshotToScriptJson(snapshot: KanbanSnapshot): string {
|
||||
return JSON.stringify(snapshot).replace(/</g, '\\u003c')
|
||||
}
|
||||
|
||||
export function snapshotScriptTag(nonce: string, snapshot: KanbanSnapshot): string {
|
||||
return `<script nonce="${nonce}" type="application/json" id="kanban-snapshot">${snapshotToScriptJson(snapshot)}</script>`
|
||||
}
|
||||
Reference in new issue
Block a user