mirror of
https://github.com/Jonnyan404/memos-bber.git
synced 2026-08-23 00:41:39 +09:00
fix: 适配 Memos 0.29.x 附件 API
This commit is contained in:
+11
-4
@@ -480,6 +480,15 @@ function buildV1ResourceStreamUrl(info, resource) {
|
||||
}
|
||||
if (root && !root.endsWith('/')) root += '/'
|
||||
|
||||
if (resource.externalLink) return resource.externalLink
|
||||
|
||||
const name = typeof resource.name === 'string' ? resource.name.trim() : ''
|
||||
const filename = typeof resource.filename === 'string' ? resource.filename : ''
|
||||
if (name.indexOf('attachments/') === 0 && filename) {
|
||||
const url = root + 'file/' + name.split('/').map(encodeURIComponent).join('/') + '/' + encodeURIComponent(filename)
|
||||
return isImageResource(resource) ? url + '?thumbnail=true' : url
|
||||
}
|
||||
|
||||
function isImageResource(r) {
|
||||
if (!r) return false
|
||||
const t = typeof r.type === 'string' ? r.type.toLowerCase() : ''
|
||||
@@ -517,13 +526,11 @@ function buildV1ResourceStreamUrl(info, resource) {
|
||||
if (id) return buildStreamUrl(id)
|
||||
|
||||
// Fallback for older resource shapes.
|
||||
const name = typeof resource.name === 'string' ? resource.name : ''
|
||||
|
||||
// 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 || resource.filename
|
||||
const fileId = resource.publicId || filename
|
||||
if (name && fileId) return root + 'file/' + name + '/' + fileId
|
||||
return ''
|
||||
}
|
||||
@@ -1283,4 +1290,4 @@ function sendText(preparedContent) {
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user