feat: 日报新增模板市场,支持社区模板安装与使用

This commit is contained in:
Wxw-Gu committed 2026-09-08 11:37:38 +08:00
1 parent 1156362c3c
commit 976aac32c5
35 files changed
+2957 -82

No files matched your search

+5 -1
View File
@@ -2,6 +2,7 @@ export type ReportHeat = '高' | '中' | '低'
export type ReportMode = 'compact' | 'full'
import type { ReportTemplateRequestId } from './report-templates'
import type { ReportTemplateRef } from './report-template-package'
export const selectHeroParticipantNames = (names: string[]): string[] =>
Array.from(new Set(names.map((name) => name.trim()).filter(Boolean))).slice(0, 4)
@@ -287,6 +288,8 @@ export interface GroupReportExportRequest {
metadata: GroupReportMetadata
/** v1 是默认经典模板,v2 仅保留旧调用兼容;另有五套新版产品模板。 */
templateId?: ReportTemplateRequestId
/** 外部模板只允许传 ID + 可选版本,由主进程 registry 解析入口路径。 */
templateRef?: ReportTemplateRef
}
export interface GroupReportExportResult {
@@ -322,5 +325,6 @@ export interface GroupReportRenderSnapshot {
export interface GroupReportRenderSnapshotExportRequest {
snapshot: GroupReportRenderSnapshot
templateId: ReportTemplateRequestId
templateId?: ReportTemplateRequestId
templateRef?: ReportTemplateRef
}
+6 -4
View File
@@ -3,7 +3,8 @@ import type {
GroupReportMetadata,
GroupReportRenderSnapshot
} from './group-report'
import type { SelectableReportTemplateId } from './report-templates'
import type { ReportTemplateSelectionId } from './report-templates'
import type { ReportTemplateRef } from './report-template-package'
export type ReportAssetStatus = 'ready' | 'missing'
export type GeneratedReportSource = 'manual' | 'scheduled'
@@ -54,7 +55,7 @@ export interface GeneratedReportRecord {
reportSnapshot?: GroupDailyReport
reportMetadata?: GroupReportMetadata
reportRenderSnapshot?: GroupReportRenderSnapshot
templateId?: SelectableReportTemplateId
templateId?: ReportTemplateSelectionId
}
export interface SaveGeneratedReportRequest {
@@ -88,12 +89,13 @@ export interface SaveGeneratedReportRequest {
}[]
reportSnapshot?: GroupDailyReport
reportMetadata?: GroupReportMetadata
templateId?: SelectableReportTemplateId
templateId?: ReportTemplateSelectionId
}
export interface UpdateGeneratedReportTemplateRequest {
reportId: string
templateId: SelectableReportTemplateId
templateId: ReportTemplateSelectionId
templateRef?: ReportTemplateRef
generatedImage?: string
htmlPath?: string
pngPath?: string
+45
View File
@@ -0,0 +1,45 @@
import type { ReportTemplateOperationResult } from './report-template-package'
export const REPORT_TEMPLATE_CATALOG_URL =
'https://raw.githubusercontent.com/Wxw-Gu/TraceMemo-Templates/main/catalog/v1/index.json'
export interface ReportTemplateCatalogEntry {
id: string
version: string
interfaceVersion: string
name: string
description: string
author: string
platform?: 'default' | 'mobile' | 'desktop'
tags: string[]
license: string
minAppVersion: string | null
download: string
sizeBytes: number
sha256: string
preview?: string
publishedAt?: string | null
status: 'published' | 'draft'
}
export interface ReportTemplateCatalog {
schemaVersion: '1'
generatedAt?: string
source?: {
repository?: string
commit?: string
}
status: 'published' | 'draft'
templates: ReportTemplateCatalogEntry[]
}
export interface ReportTemplateCatalogResult {
success: boolean
catalog?: ReportTemplateCatalog
error?: string
code?: string
}
export interface ReportTemplateCatalogInstallResult extends ReportTemplateOperationResult {
catalogEntry?: ReportTemplateCatalogEntry
}
+105
View File
@@ -0,0 +1,105 @@
import type { ReportTemplatePlatform } from './report-templates'
export const REPORT_TEMPLATE_PACKAGE_PROTOCOL_VERSION = '1.0'
export const REPORT_TEMPLATE_INTERFACE_VERSION = '1'
export const REPORT_TEMPLATE_LIMITS = {
maxCompressedBytes: 20 * 1024 * 1024,
maxExtractedBytes: 50 * 1024 * 1024,
maxFiles: 100,
maxFileBytes: 10 * 1024 * 1024,
maxHtmlBytes: 2 * 1024 * 1024,
maxCssBytes: 2 * 1024 * 1024,
maxImageBytes: 10 * 1024 * 1024
} as const
export type ReportTemplateSource = 'builtin' | 'installed'
export interface ReportTemplateRef {
id: string
version?: string
}
export interface ReportTemplateManifest {
protocolVersion: string
kind: 'daily-report'
id: string
name: string
author: { name: string; homepage?: string }
templateVersion: string
interfaceVersion: string
entry: string
preview?: string
capture: { width: number; maxWidth: number; maxHeight: number }
license: { spdx: string; notice?: string }
minAppVersion?: string
platform?: ReportTemplatePlatform
}
export interface InstalledReportTemplate {
id: string
version: string
interfaceVersion: string
source: ReportTemplateSource
name: string
author: string
entryPath: string
previewPath?: string
capture: ReportTemplateManifest['capture']
license: ReportTemplateManifest['license']
packagePath?: string
sha256?: string
installedAt?: string
}
export type ReportTemplateValueKind = 'text' | 'html' | 'class'
export const REPORT_TEMPLATE_PLACEHOLDERS: Readonly<Record<string, ReportTemplateValueKind>> = {
REPORT_TITLE: 'text', REPORT_DATE: 'text', GROUP_NAME: 'text', DATE_RANGE: 'text',
RECORD_NOTE: 'text', OVERVIEW: 'text', HERO_HEADLINE: 'text', HERO_SUMMARY: 'text',
HERO_TAKEAWAY: 'text', HERO_PENDING: 'text', HERO_STATUS_LINE: 'text', MESSAGE_COUNT: 'text',
ACTIVE_USERS: 'text', TIME_SPAN: 'text', TOPIC_COUNT: 'text', MEDIA_COUNT: 'text',
CONCLUSION_COUNT: 'text', TODO_COUNT: 'text', UNRESOLVED_COUNT: 'text',
ACTIVITY_TIMELINE: 'text', GENERATED_AT: 'text', FOOTER_NOTE: 'text',
TEMPLATE_LABEL: 'text', TEMPLATE_NAME: 'text',
HERO_AVATARS: 'html', TOPIC_CARDS: 'html', IMPORTANT_MESSAGES: 'html', QUOTE_BLOCKS: 'html',
QA_CARDS: 'html', RESOURCE_ITEMS: 'html', TODO_CARDS: 'html', UNRESOLVED_CARDS: 'html',
STORYLINE_CARDS: 'html', REVERSAL_CARDS: 'html', CHAIN_CARDS: 'html', VISION_CARDS: 'html',
VOICE_CARDS: 'html', VOICE_RANK_CARDS: 'html', BADGE_CARDS: 'html', RANK_ITEMS: 'html',
HEAT_BARS: 'html', CLOUD_TAGS: 'html',
TEMPLATE_CLASS: 'class', REPORT_MODE_CLASS: 'class', HERO_AVATAR_CLASS: 'class',
HERO_STATUS_EMPTY_CLASS: 'class', HERO_TAKEAWAY_EMPTY_CLASS: 'class', HERO_PENDING_EMPTY_CLASS: 'class',
TOPICS_EMPTY_CLASS: 'class', TOPICS_MORE_NOTE: 'html', MESSAGES_EMPTY_CLASS: 'class',
MESSAGES_MORE_NOTE: 'html', QUOTES_EMPTY_CLASS: 'class', QUOTES_MORE_NOTE: 'html',
ACTIONS_EMPTY_CLASS: 'class', ACTIONS_MORE_NOTE: 'html', QA_EMPTY_CLASS: 'class', QA_MORE_NOTE: 'html',
RESOURCES_EMPTY_CLASS: 'class', RESOURCES_MORE_NOTE: 'html', STORYLINES_EMPTY_CLASS: 'class',
STORYLINES_MORE_NOTE: 'html', REVERSALS_EMPTY_CLASS: 'class', REVERSALS_MORE_NOTE: 'html',
CHAINS_EMPTY_CLASS: 'class', CHAINS_MORE_NOTE: 'html', VISION_EMPTY_CLASS: 'class',
VOICE_EMPTY_CLASS: 'class', VOICE_MORE_NOTE: 'html', VOICE_RANK_EMPTY_CLASS: 'class',
BADGES_EMPTY_CLASS: 'class', BADGES_MORE_NOTE: 'html', KEYWORDS_EMPTY_CLASS: 'class',
KEYWORDS_MORE_NOTE: 'html', ANALYTICS_EMPTY_CLASS: 'class', TODO_EMPTY_CLASS: 'class',
UNRESOLVED_EMPTY_CLASS: 'class'
}
export const REPORT_TEMPLATE_ALLOWED_TAGS = new Set([
'html', 'head', 'body', 'meta', 'title', 'style', 'main', 'section', 'article', 'header',
'footer', 'div', 'span', 'p', 'h1', 'h2', 'h3', 'h4', 'b', 'strong', 'em', 'i', 'small',
'ul', 'ol', 'li', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'img', 'br'
])
export const REPORT_TEMPLATE_ALLOWED_ATTRS = new Set([
'class', 'id', 'title', 'aria-hidden', 'aria-label', 'alt', 'width', 'height', 'role', 'content',
'charset', 'name', 'content', 'src'
])
export const REPORT_TEMPLATE_ALLOWED_ASSET_EXTENSIONS = new Set(['.png', '.jpg', '.jpeg', '.webp'])
export class ReportTemplateError extends Error {
constructor(readonly code: string, message: string) {
super(message)
this.name = 'ReportTemplateError'
}
}
export interface ReportTemplateOperationResult {
success: boolean
template?: InstalledReportTemplate
error?: string
code?: string
}
+20
View File
@@ -7,6 +7,9 @@ export type ReportTemplateId =
export type LegacyReportTemplateId = 'v1' | 'v2'
export type SelectableReportTemplateId = 'v1' | ReportTemplateId
export type ExternalReportTemplateId = `external:${string}@${string}`
/** 日报即时生成/历史换版式可用的选择键;定时日报仍只接受 SelectableReportTemplateId。 */
export type ReportTemplateSelectionId = SelectableReportTemplateId | ExternalReportTemplateId
export type ReportTemplateRequestId = ReportTemplateId | LegacyReportTemplateId
export type ReportTemplatePlatform = 'default' | 'mobile' | 'desktop'
@@ -121,5 +124,22 @@ export const isSelectableReportTemplateId = (
): value is SelectableReportTemplateId =>
SELECTABLE_REPORT_TEMPLATES.some((template) => template.id === value)
export const encodeExternalReportTemplateId = (
id: string,
version: string
): ExternalReportTemplateId => `external:${id}@${version}`
export const decodeExternalReportTemplateId = (
value: unknown
): { id: string; version: string } | null => {
if (typeof value !== 'string' || !value.startsWith('external:')) return null
const match = /^external:([^@]+)@([^@]+)$/.exec(value)
if (!match || !match[1] || !match[2]) return null
return { id: match[1], version: match[2] }
}
export const isExternalReportTemplateId = (value: unknown): value is ExternalReportTemplateId =>
Boolean(decodeExternalReportTemplateId(value))
export const getReportTemplate = (value?: string): ReportTemplateDefinition =>
SELECTABLE_REPORT_TEMPLATES.find((template) => template.id === value) || DEFAULT_REPORT_TEMPLATE