6e67034fbd
build / build (push) Successful in 1m10s
以治理库单一只读事务分开聚合累计、自然周、截止月及当前通讯录使用分母;浏览器不再读取全量长答案来构建看板。 新增迁移52与普通worker周质量冻结,保留真实冻结时点、规则和标量贡献;缺少当时快照留空。提交后冻结头与贡献不可修改、删除或追加;只读接口保留管理员、固定租户、严格JSON与输入冲突保护。 已验证:make verify退出0,686个Go用例和305个前端用例通过,必需跳过0;镜像与组织隔离PostgreSQL竞态回归退出0。真实治理副本浏览器核对第41周累计1885与新增471、十一项和完整PNG下载,390px无外溢、JS异常0;明确模拟503后不伪零且重试恢复。没有修改DobotAI原始问答、真实区域规则或生产发布门禁。
49 lines
2.2 KiB
TypeScript
49 lines
2.2 KiB
TypeScript
export function dashboardExportSize(w: number, h: number): { width: number; height: number; scale: number } {
|
|
if (!Number.isFinite(w) || !Number.isFinite(h) || w <= 0 || h <= 0 || w > 32760 || h > 32760 || w * h > 64000000)
|
|
throw new Error('看板过大,无法完整生成 PNG,请缩小统计范围')
|
|
const scale = w * 2 <= 32760 && h * 2 <= 32760 && w * h * 4 <= 64000000 ? 2 : 1
|
|
return { width: Math.ceil(w * scale), height: Math.ceil(h * scale), scale }
|
|
}
|
|
export async function createDashboardPNG(svg: SVGSVGElement): Promise<Blob> {
|
|
const box = svg.viewBox.baseVal,
|
|
size = dashboardExportSize(box.width, box.height),
|
|
copy = svg.cloneNode(true) as SVGSVGElement
|
|
if (
|
|
copy.querySelectorAll('[data-panel]').length !== 11 ||
|
|
copy.querySelector('foreignObject,image,script,iframe,use')
|
|
)
|
|
throw new Error('看板内容不完整,未生成图片')
|
|
copy.setAttribute('width', String(box.width))
|
|
copy.setAttribute('height', String(box.height))
|
|
copy.style.width = `${box.width}px`
|
|
copy.style.height = `${box.height}px`
|
|
copy.style.fontFamily = getComputedStyle(svg).fontFamily
|
|
if (document.fonts) await document.fonts.ready
|
|
const source = new Blob([new XMLSerializer().serializeToString(copy)], { type: 'image/svg+xml;charset=utf-8' }),
|
|
url = URL.createObjectURL(source)
|
|
try {
|
|
const image = new Image()
|
|
await new Promise<void>((resolve, reject) => {
|
|
image.onload = () => resolve()
|
|
image.onerror = () => reject(new Error('看板图片绘制失败'))
|
|
image.src = url
|
|
})
|
|
const canvas = document.createElement('canvas')
|
|
canvas.width = size.width
|
|
canvas.height = size.height
|
|
const context = canvas.getContext('2d', { alpha: false })
|
|
if (!context) throw new Error('浏览器无法创建完整图片画布')
|
|
context.fillStyle = '#fff'
|
|
context.fillRect(0, 0, size.width, size.height)
|
|
context.drawImage(image, 0, 0, size.width, size.height)
|
|
return await new Promise<Blob>((resolve, reject) =>
|
|
canvas.toBlob(
|
|
(blob) => (blob && blob.size > 0 ? resolve(blob) : reject(new Error('PNG生成失败,请重试'))),
|
|
'image/png'
|
|
)
|
|
)
|
|
} finally {
|
|
URL.revokeObjectURL(url)
|
|
}
|
|
}
|