提交 fbfc8066 编写于 作者: 雪洛's avatar 雪洛

feat: save device info into opendb-device

上级 8b15df03
...@@ -160,49 +160,39 @@ function validate (value = {}, schema = {}) { ...@@ -160,49 +160,39 @@ function validate (value = {}, schema = {}) {
} }
function checkClientInfo (clientInfo) { function checkClientInfo (clientInfo) {
const stringNotRequired = {
required: false,
type: 'string'
}
const numberNotRequired = {
required: false,
type: 'string'
}
const schema = { const schema = {
uniPlatform: 'string', uniPlatform: 'string',
appId: 'string', appId: 'string',
deviceId: { deviceId: stringNotRequired,
required: false, osName: stringNotRequired,
type: 'string' locale: stringNotRequired,
}, clientIP: stringNotRequired,
osName: { appName: stringNotRequired,
required: false, appVersion: stringNotRequired,
type: 'string' appVersionCode: stringNotRequired,
}, channel: stringNotRequired,
locale: { userAgent: stringNotRequired,
required: false, uniIdToken: stringNotRequired,
type: 'string' deviceBrand: stringNotRequired,
}, deviceModel: stringNotRequired,
clientIP: { osVersion: stringNotRequired,
required: false, osLanguage: stringNotRequired,
type: 'string' osTheme: stringNotRequired,
}, romName: stringNotRequired,
appName: { romVersion: stringNotRequired,
required: false, devicePixelRatio: numberNotRequired,
type: 'string' windowWidth: numberNotRequired,
}, windowHeight: numberNotRequired,
appVersion: { screenWidth: numberNotRequired,
required: false, screenHeight: numberNotRequired
type: 'string'
},
appVersionCode: {
required: false,
type: 'string'
},
channel: {
required: false,
type: 'string'
},
userAgent: {
required: false,
type: 'string'
},
uniIdToken: {
required: false,
type: 'string'
}
} }
const validateRes = validate(clientInfo, schema) const validateRes = validate(clientInfo, schema)
if (validateRes) { if (validateRes) {
......
...@@ -87,7 +87,7 @@ module.exports = { ...@@ -87,7 +87,7 @@ module.exports = {
break break
case 'web': case 'web':
case 'h5': case 'h5':
clientPlatform = 'h5' clientPlatform = 'web'
break break
default: default:
break break
......
...@@ -5,6 +5,67 @@ const { ...@@ -5,6 +5,67 @@ const {
ERROR ERROR
} = require('../../common/error') } = require('../../common/error')
async function setOpendbDevice ({
pushClientId
} = {}) {
// 仅新增,如果存在进行更新操作
const {
appId,
deviceId,
deviceBrand,
deviceModel,
osName,
osVersion,
osLanguage,
osTheme,
devicePixelRatio,
windowWidth,
windowHeight,
screenWidth,
screenHeight,
romName,
romVersion
} = this.getClientInfo()
const platform = this.clientPlatform
const now = Date.now()
const db = uniCloud.database()
const opendbDeviceCollection = db.collection('opendb-device')
const getDeviceRes = await opendbDeviceCollection.where({
device_id: deviceId
}).get()
const data = {
appid: appId,
device_id: deviceId,
vendor: deviceBrand,
model: deviceModel,
uni_platform: platform,
os_name: osName,
os_version: osVersion,
os_language: osLanguage,
os_theme: osTheme,
pixel_ratio: devicePixelRatio,
window_width: windowWidth,
window_height: windowHeight,
screen_width: screenWidth,
screen_height: screenHeight,
rom_name: romName,
rom_version: romVersion,
last_update_date: now,
push_clientid: pushClientId
}
if (getDeviceRes.data.length > 0) {
await opendbDeviceCollection.where({
device_id: deviceId
}).update(data)
return
}
data.create_date = now
await opendbDeviceCollection.where({
device_id: deviceId
}).add(data)
}
/** /**
* 更新device表的push_clien_id * 更新device表的push_clien_id
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#set-push-cid * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#set-push-cid
...@@ -19,15 +80,14 @@ module.exports = async function (params = {}) { ...@@ -19,15 +80,14 @@ module.exports = async function (params = {}) {
this.middleware.validate(params, schema) this.middleware.validate(params, schema)
const { const {
deviceId, deviceId,
"appId":dcloud_appid, appId,
uniPlatform, osName
osName
} = this.getClientInfo() } = this.getClientInfo()
let platform = uniPlatform let platform = this.clientPlatform
if(platform == "app"){ if (platform === 'app') {
platform += osName platform += osName
} }
const { const {
uid, uid,
exp exp
...@@ -44,14 +104,16 @@ module.exports = async function (params = {}) { ...@@ -44,14 +104,16 @@ module.exports = async function (params = {}) {
} }
} }
const deviceRecord = getDeviceRes.data[0] const deviceRecord = getDeviceRes.data[0]
await setOpendbDevice({
pushClientId
})
if (!deviceRecord) { if (!deviceRecord) {
await deviceCollection.add({ await deviceCollection.add({
user_id: uid, user_id: uid,
device_id: deviceId, device_id: deviceId,
token_expired: tokenExpired, token_expired: tokenExpired,
push_clientid: pushClientId, push_clientid: pushClientId,
dcloud_appid, dcloud_appid: appId
platform
}) })
return { return {
errCode: 0 errCode: 0
...@@ -68,8 +130,7 @@ module.exports = async function (params = {}) { ...@@ -68,8 +130,7 @@ module.exports = async function (params = {}) {
user_id: uid, user_id: uid,
token_expired: tokenExpired, token_expired: tokenExpired,
push_clientid: pushClientId, push_clientid: pushClientId,
dcloud_appid, dcloud_appid: appId
platform
}) })
return { return {
errCode: 0 errCode: 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册