From 1e61ab4fba18a02e291b45fbbeaf413c4747d986 Mon Sep 17 00:00:00 2001 From: cnliucheng Date: Wed, 24 Jun 2026 13:13:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=5Fopenid=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=E4=B9=9F=E5=BA=94=E5=85=81=E8=AE=B8add()=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E4=BA=91=E7=AB=AF=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前当getOpenid未部署时,_doPush直接return,永远跳过了 db.collection().add(),导致集合无法自动创建、数据不能上云。 改为跳过locate+update但允许add(),CloudBase会自动填充_openid。 Co-Authored-By: Claude --- utils/cloud.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/utils/cloud.js b/utils/cloud.js index d65896a..4d11ced 100644 --- a/utils/cloud.js +++ b/utils/cloud.js @@ -195,13 +195,12 @@ const _doPush = async () => { return } } - } else { - console.log('[cloud] _doPush no openid available, aborting (avoid duplicate add)') - return - } + } // else: openid is null — skip locate+update, go straight to add() - // Reached only when we've positively confirmed no doc exists for our - // openid in the cloud — safe to add() the first document. + // Reached when: (a) openid exists but no doc found, OR (b) openid is + // null (getOpenid not deployed). In both cases add() is safe — CloudBase + // auto-populates _openid on document creation. + console.log('[cloud] _doPush adding new doc (openid=' + (openid || 'null') + ')') const res = await db.collection(DB_COLLECTION).add({ data }) if (res && res._id) _docId = res._id if (res && res._openid) _openid = res._openid