fix: debug 分享卡片生成问题

This commit is contained in:
2026-03-11 11:48:40 +08:00
parent 883ce3c2c4
commit d3390d5e81
2 changed files with 44 additions and 18 deletions

View File

@@ -106,6 +106,12 @@ const drawLabel = (ctx: any, x: number, y: number, width: number, height: number
ctx.restore()
}
/** 给图片 URL 加随机参数,避免同一链接二次加载不触发 onload */
function with_cache_bust(url: string): string {
const sep = url.includes('?') ? '&' : '?';
return `${url}${sep}_t=${Date.now()}_${Math.random().toString(36).slice(2)}`;
}
// 工具函数 - OffscreenCanvas 下加载图片(使用 offscreen.createImage
const loadImage = (src: string): Promise<any> => {
return new Promise((resolve, reject) => {
@@ -117,7 +123,7 @@ const loadImage = (src: string): Promise<any> => {
const img = off.createImage()
img.onload = () => resolve(img)
img.onerror = reject
img.src = src
img.src = with_cache_bust(src)
} catch (e) {
reject(e)
}