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:
@@ -187,6 +187,7 @@
|
||||
|
||||
function normalizeUploadedItem(entity, fallbackFilename) {
|
||||
if (!entity) return null
|
||||
entity = entity.attachment || entity.resource || entity
|
||||
const inferredId = (function () {
|
||||
const value = entity.id != null ? entity.id : entity.ID != null ? entity.ID : entity.Id
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return Math.floor(value)
|
||||
@@ -204,7 +205,11 @@
|
||||
name: name,
|
||||
filename: entity.filename || fallbackFilename || name,
|
||||
createTime: entity.createTime || entity.createdTs || entity.createdAt,
|
||||
type: entity.type
|
||||
type: entity.type,
|
||||
uid: entity.uid,
|
||||
size: entity.size,
|
||||
memo: entity.memo,
|
||||
externalLink: entity.externalLink
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +401,7 @@
|
||||
info,
|
||||
payload,
|
||||
function (resp) {
|
||||
const entity = (resp && resp.resource) || resp
|
||||
const entity = (resp && (resp.attachment || resp.resource)) || resp
|
||||
if (success) success(normalizeUploadedItem(entity, nextName))
|
||||
},
|
||||
fail
|
||||
@@ -458,24 +463,35 @@
|
||||
return
|
||||
}
|
||||
|
||||
const uploadedItems = Array.isArray(payload.resourceIdList) ? payload.resourceIdList : []
|
||||
const attachmentReferences = uploadedItems
|
||||
.filter(function (item) {
|
||||
return item && typeof item.name === 'string' && item.name.indexOf('attachments/') === 0
|
||||
})
|
||||
.map(function (item) {
|
||||
return { name: item.name }
|
||||
})
|
||||
const canCreateWithAttachments = flavor === 'modern' && attachmentReferences.length === uploadedItems.length
|
||||
|
||||
requestJson({
|
||||
url: info.apiUrl + 'api/v1/memos',
|
||||
type: 'POST',
|
||||
data: JSON.stringify({
|
||||
content: payload.content,
|
||||
visibility: payload.visibility
|
||||
visibility: payload.visibility,
|
||||
...(canCreateWithAttachments ? { attachments: attachmentReferences } : {})
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
headers: { Authorization: 'Bearer ' + info.apiTokens }
|
||||
}, function (data) {
|
||||
const createdName = data && data.name ? data.name : data && data.memo && data.memo.name ? data.memo.name : ''
|
||||
const resources = Array.isArray(payload.resourceIdList) ? payload.resourceIdList : []
|
||||
const resources = uploadedItems
|
||||
if (!createdName) {
|
||||
if (success) success(data)
|
||||
return
|
||||
}
|
||||
if (resources.length === 0) {
|
||||
if (resources.length === 0 || canCreateWithAttachments) {
|
||||
getMemo(createdName, success, fail)
|
||||
return
|
||||
}
|
||||
@@ -497,7 +513,7 @@
|
||||
return {
|
||||
flavor: flavor,
|
||||
needsAuthenticatedImagePreview: function () {
|
||||
return flavor === FLAVOR_V020_V021
|
||||
return true
|
||||
},
|
||||
listTags: listTags,
|
||||
searchMemos: searchMemos,
|
||||
@@ -518,4 +534,4 @@
|
||||
probeFlavor: probeFlavor,
|
||||
resolve: resolve
|
||||
}
|
||||
})(window)
|
||||
})(window)
|
||||
|
||||
Reference in New Issue
Block a user