From afbb7ac5cc1756868d0ce6f6aa43ac57c32cb44e Mon Sep 17 00:00:00 2001 From: jonny Date: Wed, 5 Aug 2026 12:19:16 +0800 Subject: [PATCH] Fix 0.20.x image preview URLs by prioritizing uid check Reorder fallback checks in buildV1ResourceStreamUrl to prioritize uid-like identifiers before numeric IDs. This fixes image preview URLs in Memos 0.20.x that incorrectly used numeric IDs instead of proper UIDs. Applied to Chrome, Edge, and Firefox extensions. Updated changelog accordingly. --- change.log | 2 +- chrome/js/oper.js | 10 +++++----- edge/js/oper.js | 10 +++++----- firefox/js/oper.js | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/change.log b/change.log index c815983..0e8c369 100644 --- a/change.log +++ b/change.log @@ -1,5 +1,5 @@ ## 更新日志 -- 20260805 适配 Memos 0.29.x Attachment API,修复附件上传、绑定和预览地址 +- 20260805 适配 Memos 0.29.x Attachment API,修复附件上传、绑定和预览地址;修复 0.20.x 图片预览 URL 错误使用 numeric id 的问题 - 20260425 新增德语/法语/西班牙语支持 - 20260423 优化 firefox 抖动问题和支持手机版,支持 edge 浏览器扩展 - 20260422 调整发送设置,支持仅发送附件 diff --git a/chrome/js/oper.js b/chrome/js/oper.js index cdda987..27813bd 100644 --- a/chrome/js/oper.js +++ b/chrome/js/oper.js @@ -516,6 +516,11 @@ function buildV1ResourceStreamUrl(info, resource) { const uid = typeof uidRaw === 'string' ? uidRaw : uidRaw != null ? String(uidRaw) : '' if (uid.trim() !== '') return buildStreamUrl(uid.trim()) + // Fallback for older resource shapes. + // In some memo payloads, the uid may appear as `name` directly. + // Example: name="ETU6hjuR..." should map to /o/r/:uid, not /file/:name/:filename. + if (isProbablyUid(name)) return buildStreamUrl(name.trim()) + // Legacy versions (e.g. v0.18) may only expose numeric `id` without `uid/name`. const idRaw = resource.id != null ? resource.id : resource.ID != null ? resource.ID : resource.Id const id = typeof idRaw === 'number' && Number.isFinite(idRaw) @@ -525,11 +530,6 @@ function buildV1ResourceStreamUrl(info, resource) { : '' if (id) return buildStreamUrl(id) - // Fallback for older resource shapes. - // In some memo payloads, the uid may appear as `name` directly. - // Example: name="ETU6hjuR..." should map to /o/r/:uid, not /file/:name/:filename. - if (isProbablyUid(name)) return buildStreamUrl(name.trim()) - const fileId = resource.publicId || filename if (name && fileId) return root + 'file/' + name + '/' + fileId return '' diff --git a/edge/js/oper.js b/edge/js/oper.js index cdda987..27813bd 100644 --- a/edge/js/oper.js +++ b/edge/js/oper.js @@ -516,6 +516,11 @@ function buildV1ResourceStreamUrl(info, resource) { const uid = typeof uidRaw === 'string' ? uidRaw : uidRaw != null ? String(uidRaw) : '' if (uid.trim() !== '') return buildStreamUrl(uid.trim()) + // Fallback for older resource shapes. + // In some memo payloads, the uid may appear as `name` directly. + // Example: name="ETU6hjuR..." should map to /o/r/:uid, not /file/:name/:filename. + if (isProbablyUid(name)) return buildStreamUrl(name.trim()) + // Legacy versions (e.g. v0.18) may only expose numeric `id` without `uid/name`. const idRaw = resource.id != null ? resource.id : resource.ID != null ? resource.ID : resource.Id const id = typeof idRaw === 'number' && Number.isFinite(idRaw) @@ -525,11 +530,6 @@ function buildV1ResourceStreamUrl(info, resource) { : '' if (id) return buildStreamUrl(id) - // Fallback for older resource shapes. - // In some memo payloads, the uid may appear as `name` directly. - // Example: name="ETU6hjuR..." should map to /o/r/:uid, not /file/:name/:filename. - if (isProbablyUid(name)) return buildStreamUrl(name.trim()) - const fileId = resource.publicId || filename if (name && fileId) return root + 'file/' + name + '/' + fileId return '' diff --git a/firefox/js/oper.js b/firefox/js/oper.js index be72188..1f5dee5 100644 --- a/firefox/js/oper.js +++ b/firefox/js/oper.js @@ -541,6 +541,11 @@ function buildV1ResourceStreamUrl(info, resource) { const uid = typeof uidRaw === 'string' ? uidRaw : uidRaw != null ? String(uidRaw) : '' if (uid.trim() !== '') return buildStreamUrl(uid.trim()) + // Fallback for older resource shapes. + // In some memo payloads, the uid may appear as `name` directly. + // Example: name="ETU6hjuR..." should map to /o/r/:uid, not /file/:name/:filename. + if (isProbablyUid(name)) return buildStreamUrl(name.trim()) + // Legacy versions (e.g. v0.18) may only expose numeric `id` without `uid/name`. const idRaw = resource.id != null ? resource.id : resource.ID != null ? resource.ID : resource.Id const id = typeof idRaw === 'number' && Number.isFinite(idRaw) @@ -550,11 +555,6 @@ function buildV1ResourceStreamUrl(info, resource) { : '' if (id) return buildStreamUrl(id) - // Fallback for older resource shapes. - // In some memo payloads, the uid may appear as `name` directly. - // Example: name="ETU6hjuR..." should map to /o/r/:uid, not /file/:name/:filename. - if (isProbablyUid(name)) return buildStreamUrl(name.trim()) - const fileId = resource.publicId || filename if (name && fileId) return root + 'file/' + name + '/' + fileId return ''