hulai-website/composables/useImageProxy.js
刘涛 8832762e51 fix: 修复首页空白、小红书/游记封面图、定制页二维码
1. 首页大面积空白:useScrollReveal 添加 MutationObserver,
   确保异步子组件的 .reveal 元素也能触发入场动画

2. 小红书/游记封面图不显示:
   - 小红书 CDN 签名链接过期+防盗链,全部下载到本地
   - 新增 download-covers.mjs 脚本批量下载封面
   - 新增 useImageProxy composable 转换外部 URL
   - 页面 img 标签添加 referrerpolicy="no-referrer"
   - 管理端保存时自动下载外部封面图到本地
   - 种子数据更新为本地路径

3. 定制页微信号文字替换为二维码图片

4. prerender 路由添加 /xiaohongshu 和 /youji

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 15:37:58 +08:00

39 行
1.3 KiB
JavaScript

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

/**
* 小红书图片 URL 转换
*
* 小红书 CDN 图片 (sns-webpic-qc.xhscdn.com) 使用签名 URL,
* 格式: https://sns-webpic-qc.xhscdn.com/{timestamp}/{hash}/{path}
* 这些 URL 会过期且有防盗链,第三方站点无法直接使用。
*
* 解决方案:转换为 ci.xiaohongshu.com 的永久 URL
* 格式: https://ci.xiaohongshu.com/{path}
*/
/**
* 将小红书签名 URL 转换为永久可访问的 URL
*/
export function proxyImage(url) {
if (!url) return ''
try {
const parsed = new URL(url)
// sns-webpic-qc.xhscdn.com/{timestamp}/{hash}/{actual_path}
// 提取 actual_path 部分,转到 ci.xiaohongshu.com
if (parsed.hostname === 'sns-webpic-qc.xhscdn.com') {
const parts = parsed.pathname.split('/')
// 去掉前导空字符串、timestamp、hash,剩下的就是图片路径
// pathname: /202603231146/hash/notes_pre_post/image_id
if (parts.length >= 4) {
const imagePath = parts.slice(3).join('/')
return `https://ci.xiaohongshu.com/${imagePath}`
}
}
// 已经是 ci.xiaohongshu.com 的永久链接,直接用
if (parsed.hostname === 'ci.xiaohongshu.com') {
return url
}
} catch {
// 不是合法 URL可能是本地路径,直接返回
}
return url
}