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

feat: save device info into opendb-device

上级 8b15df03
......@@ -160,49 +160,39 @@ function validate (value = {}, schema = {}) {
}
function checkClientInfo (clientInfo) {
const stringNotRequired = {
required: false,
type: 'string'
}
const numberNotRequired = {
required: false,
type: 'string'
}
const schema = {
uniPlatform: 'string',
appId: 'string',
deviceId: {
required: false,
type: 'string'
},
osName: {
required: false,
type: 'string'
},
locale: {
required: false,
type: 'string'
},
clientIP: {
required: false,
type: 'string'
},
appName: {
required: false,
type: 'string'
},
appVersion: {
required: false,
type: 'string'
},
appVersionCode: {
required: false,
type: 'string'
},
channel: {
required: false,
type: 'string'
},
userAgent: {
required: false,
type: 'string'
},
uniIdToken: {
required: false,
type: 'string'
}
deviceId: stringNotRequired,
osName: stringNotRequired,
locale: stringNotRequired,
clientIP: stringNotRequired,
appName: stringNotRequired,
appVersion: stringNotRequired,
appVersionCode: stringNotRequired,
channel: stringNotRequired,
userAgent: stringNotRequired,
uniIdToken: stringNotRequired,
deviceBrand: stringNotRequired,
deviceModel: stringNotRequired,
osVersion: stringNotRequired,
osLanguage: stringNotRequired,
osTheme: stringNotRequired,
romName: stringNotRequired,
romVersion: stringNotRequired,
devicePixelRatio: numberNotRequired,
windowWidth: numberNotRequired,
windowHeight: numberNotRequired,
screenWidth: numberNotRequired,
screenHeight: numberNotRequired
}
const validateRes = validate(clientInfo, schema)
if (validateRes) {
......
......@@ -87,7 +87,7 @@ module.exports = {
break
case 'web':
case 'h5':
clientPlatform = 'h5'
clientPlatform = 'web'
break
default:
break
......
......@@ -5,6 +5,67 @@ const {
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
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#set-push-cid
......@@ -19,15 +80,14 @@ module.exports = async function (params = {}) {
this.middleware.validate(params, schema)
const {
deviceId,
"appId":dcloud_appid,
uniPlatform,
osName
appId,
osName
} = this.getClientInfo()
let platform = uniPlatform
if(platform == "app"){
platform += osName
let platform = this.clientPlatform
if (platform === 'app') {
platform += osName
}
const {
uid,
exp
......@@ -44,14 +104,16 @@ module.exports = async function (params = {}) {
}
}
const deviceRecord = getDeviceRes.data[0]
await setOpendbDevice({
pushClientId
})
if (!deviceRecord) {
await deviceCollection.add({
user_id: uid,
device_id: deviceId,
token_expired: tokenExpired,
push_clientid: pushClientId,
dcloud_appid,
platform
dcloud_appid: appId
})
return {
errCode: 0
......@@ -68,8 +130,7 @@ module.exports = async function (params = {}) {
user_id: uid,
token_expired: tokenExpired,
push_clientid: pushClientId,
dcloud_appid,
platform
dcloud_appid: appId
})
return {
errCode: 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册