修复云端数据一致性问题
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
const crypto = require('crypto')
|
||||
|
||||
const memberKey = (openid) =>
|
||||
crypto.createHash('sha256').update(String(openid || '')).digest('hex')
|
||||
|
||||
const publicEntry = (entry) => {
|
||||
if (!entry) return null
|
||||
const { memberKey: _memberKey, openid: _openid, ...publicData } = entry
|
||||
return publicData
|
||||
}
|
||||
|
||||
const publicRanked = (ranked) => (ranked || []).map(publicEntry)
|
||||
|
||||
const findMyEntry = (ranked, key) => {
|
||||
const item = (ranked || []).find(entry => entry.memberKey === key)
|
||||
return item ? { ...publicEntry(item), isMe: true } : null
|
||||
}
|
||||
|
||||
module.exports = { memberKey, publicEntry, publicRanked, findMyEntry }
|
||||
Reference in New Issue
Block a user