2022-07-27 18:36:49 +00:00
|
|
|
import lodash from 'lodash'
|
2022-08-20 23:40:32 +00:00
|
|
|
import { Data } from '../index.js'
|
|
|
|
import { ProfileServ } from '../../models/index.js'
|
|
|
|
import MiaoData from './miao-data.js'
|
2022-06-14 22:07:24 +00:00
|
|
|
|
2022-08-20 23:40:32 +00:00
|
|
|
export default new ProfileServ({
|
2022-07-27 18:36:49 +00:00
|
|
|
key: 'miao',
|
2022-10-21 14:48:19 +00:00
|
|
|
name: '喵喵Api',
|
2022-08-20 23:40:32 +00:00
|
|
|
cfgKey: 'miaoApi',
|
|
|
|
async response (data, req) {
|
|
|
|
if (data.status !== 0) {
|
|
|
|
return req.err(data.msg || 'error', 60)
|
2022-06-14 22:07:24 +00:00
|
|
|
}
|
2022-08-22 13:38:34 +00:00
|
|
|
data = data.data || {}
|
2022-08-20 23:40:32 +00:00
|
|
|
if (!data.showAvatarInfoList || data.showAvatarInfoList.length === 0) {
|
|
|
|
return req.err('empty', 5 * 60)
|
2022-08-16 20:04:12 +00:00
|
|
|
}
|
2022-08-20 23:40:32 +00:00
|
|
|
return data
|
2022-06-14 22:07:24 +00:00
|
|
|
},
|
|
|
|
|
2022-08-20 23:40:32 +00:00
|
|
|
userData (data) {
|
|
|
|
return Data.getData(data, 'name:nickname,avatar:profilePicture.avatarID,level,signature')
|
2022-06-14 22:07:24 +00:00
|
|
|
},
|
|
|
|
|
2022-08-20 23:40:32 +00:00
|
|
|
profileData (data) {
|
2022-07-27 18:36:49 +00:00
|
|
|
let ret = {}
|
2022-08-20 23:40:32 +00:00
|
|
|
lodash.forEach(data.showAvatarInfoList, (ds) => {
|
|
|
|
let profile = MiaoData.getProfile(ds)
|
|
|
|
if (profile && profile.id) {
|
|
|
|
ret[profile.id] = profile
|
2022-06-14 22:07:24 +00:00
|
|
|
}
|
|
|
|
})
|
2022-08-03 18:32:10 +00:00
|
|
|
return ret
|
2022-08-20 23:40:32 +00:00
|
|
|
},
|
2022-06-14 22:07:24 +00:00
|
|
|
|
2022-08-20 23:40:32 +00:00
|
|
|
// 获取冷却时间
|
|
|
|
cdTime (data = {}) {
|
|
|
|
if (data.cacheExpireAt) {
|
|
|
|
let exp = Math.max(0, Math.round(data.cacheExpireAt - (new Date() / 1000)))
|
|
|
|
return Math.max(60, exp)
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
2022-08-20 23:40:32 +00:00
|
|
|
return 60
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
|
|
|
})
|