From 90abceb89a27bf4c66477ffe9b665ac3c2f753d2 Mon Sep 17 00:00:00 2001 From: albert4719 Date: Fri, 18 Sep 2026 15:56:44 +0800 Subject: [PATCH] =?UTF-8?q?sync-stats=20=E5=8A=A0=20og.png=20=E8=87=AA?= =?UTF-8?q?=E6=A3=80=EF=BC=9A=E6=A0=A1=E9=AA=8C=E6=98=AF=E6=9C=AC=E6=AC=A1?= =?UTF-8?q?=E5=86=99=E5=85=A5=E4=B8=94=E5=A4=A7=E5=B0=8F=E5=9C=A8=E5=8C=BA?= =?UTF-8?q?=E9=97=B4=E5=86=85=EF=BC=8CChrome=20=E6=94=B9=E7=94=A8=20Start-?= =?UTF-8?q?Process=20=E9=81=BF=E5=BC=80=20PS=205.1=20=E7=9A=84=20stderr=20?= =?UTF-8?q?=E8=AF=AF=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/sync-stats.ps1 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/sync-stats.ps1 b/tools/sync-stats.ps1 index 5704a84..b899b8c 100644 --- a/tools/sync-stats.ps1 +++ b/tools/sync-stats.ps1 @@ -109,7 +109,21 @@ if (-not (Test-Path $chrome)) { throw "找不到 Chrome:$chrome,装在别处 $shotProfile = Join-Path $env:TEMP ('og-shot-' + [guid]::NewGuid().ToString('N')) $target = Join-Path $repo 'og.png' $source = 'file:///' + ((Join-Path $repo 'tools\og.html') -replace '\\', '/') -& $chrome --headless --disable-gpu --hide-scrollbars --force-device-scale-factor=1 --window-size=1200,630 --user-data-dir="$shotProfile" --screenshot="$target" $source | Out-Null +$startedAt = Get-Date +# 用 Start-Process 而不是 & 调用:Chrome 把「xxx bytes written」写在 stderr 上, +# PowerShell 5.1 一旦让原生程序的 stderr 流进错误流,配上 ErrorActionPreference=Stop 就会误报失败 +$chromeArgs = @( + '--headless', '--disable-gpu', '--hide-scrollbars', '--force-device-scale-factor=1', + '--window-size=1200,630', "--user-data-dir=$shotProfile", "--screenshot=$target", $source +) +$chromeLog = Join-Path $env:TEMP ('og-shot-' + [guid]::NewGuid().ToString('N') + '.log') +Start-Process -FilePath $chrome -ArgumentList $chromeArgs -Wait -NoNewWindow -RedirectStandardError $chromeLog +Remove-Item -Force $chromeLog -ErrorAction SilentlyContinue Remove-Item -Recurse -Force $shotProfile -ErrorAction SilentlyContinue + +# 自检:文件是这次写的、大小在正常区间。过了这两关就不必再打开图看,省一次读图的开销 +$png = Get-Item $target +if ($png.LastWriteTime -lt $startedAt) { throw 'og.png 没有被这次运行写入,截图失败了' } +if ($png.Length -lt 120KB -or $png.Length -gt 400KB) { throw "og.png 大小异常($($png.Length) 字节),正常在 120KB 到 400KB,打开看一眼是不是渲染坏了" } '' -"og.png 已重出:$((Get-Item $target).Length) 字节。用 Read 看一眼图里三个数字对不对,再和正文改动一起提交。" +"og.png 已重出:$($png.Length) 字节,自检通过。改过 tools/og.html 的版式才需要打开图确认。"