diff --git a/apps/user.js b/apps/user.js index d3797a4..96bd9fe 100644 --- a/apps/user.js +++ b/apps/user.js @@ -30,10 +30,16 @@ export async function userInfo(e,{render}){ let sumData=await user.getCkData() let week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; let day = moment(new Date()).format("yyyy年MM月DD日 HH:mm") + " " + week[new Date().getDay()]; - let ck= user.getCookieMap(e.cookie); + if(Object.keys(sumData).length==0){ + return true; + } + let ck=""; + if(e.cookie){ + ck= user.getCookieMap(e.cookie); + } return await Common.render(`user/userInfo`, { uid: e.user_id, - ltuid:ck.get("ltuid"), + ltuid:ck.get("ltuid")||e.user_id, save_id:e.user_id, day, sumData diff --git a/model/mys/mihoyo-api.js b/model/mys/mihoyo-api.js index 7f23a0c..d93c737 100644 --- a/model/mys/mihoyo-api.js +++ b/model/mys/mihoyo-api.js @@ -93,6 +93,7 @@ export default class MihoYoApi { let data = this.getStoken(this.e.user_id); if (data) { this.cookies = `stuid=${data.stuid};stoken=${data.stoken};ltoken=${data.ltoken};`; + this.e.cookies=this.cookies } } Data.createDir("", YamlDataUrl, false); diff --git a/model/user.js b/model/user.js index 92c12c2..81c6cae 100644 --- a/model/user.js +++ b/model/user.js @@ -28,52 +28,58 @@ export default class user { let sumData={}; await this.cookie(this.e) this.miHoYoApi = new MihoYoApi(this.e); - let yunres = await promiseRetry((retry, number) => { - return this.miHoYoApi.logyunGenshen().catch((e) => { - return retry(e); - }); - }, RETRY_OPTIONS); - let mysres = await promiseRetry((retry, number) => { - return this.miHoYoApi.getTasksList().catch((e) => { - return retry(e); - }); - }, RETRY_OPTIONS); - - let yundata = yunres.data - if(mysres.retcode===0){ - sumData["米游社"]={ - "米游币余额":mysres.data.total_points, - "今日剩余可获取":mysres.data.can_get_points - } - } - if(yunres.retcode===0){ - sumData["云原神"]={ - "今日可获取":yundata?.coin?.coin_num, - "免费时长":yundata?.free_time?.free_time, - "总时长":yundata.total_time - } - } - for(let name of nameData){ - let resSign = await promiseRetry((retry, number) => { - return this.miHoYoApi.honkai3rdSignTask(name).catch((e) => { + if(this.e.yuntoken){ + let yunres = await promiseRetry((retry, number) => { + return this.miHoYoApi.logyunGenshen().catch((e) => { return retry(e); }); }, RETRY_OPTIONS); - if(resSign?.upData){ - // console.log(resSign?.upData) - for(let item of resSign?.upData){ - let num= lodash.random(0, 9999); - item.upName=item.upName=="原神"?"ys":item.upName=="崩坏3"?"bh3":item.upName=="崩坏2"?"bh2":item.upName=="未定事件簿"?"wdy":"" - sumData[item.upName+""+num]={ - "uid":item.game_uid, - "游戏昵称":item.nickname, - "等级":item.level, - "今日签到":item.is_sign?"已签到":"未签到" + + let yundata = yunres.data + if(yunres.retcode===0){ + sumData["云原神"]={ + "今日可获取":yundata?.coin?.coin_num, + "免费时长":yundata?.free_time?.free_time, + "总时长":yundata.total_time + } + } + } + if(this.e.cookies){ + let mysres = await promiseRetry((retry, number) => { + return this.miHoYoApi.getTasksList().catch((e) => { + return retry(e); + }); + }, RETRY_OPTIONS); + if(mysres.retcode===0){ + sumData["米游社"]={ + "米游币余额":mysres.data.total_points, + "今日剩余可获取":mysres.data.can_get_points + } + } + + } + if(this.e.cookie){ + for(let name of nameData){ + let resSign = await promiseRetry((retry, number) => { + return this.miHoYoApi.honkai3rdSignTask(name).catch((e) => { + return retry(e); + }); + }, RETRY_OPTIONS); + if(resSign?.upData){ + // console.log(resSign?.upData) + for(let item of resSign?.upData){ + let num= lodash.random(0, 9999); + item.upName=item.upName=="原神"?"ys":item.upName=="崩坏3"?"bh3":item.upName=="崩坏2"?"bh2":item.upName=="未定事件簿"?"wdy":"" + sumData[item.upName+""+num]={ + "uid":item.game_uid, + "游戏昵称":item.nickname, + "等级":item.level, + "今日签到":item.is_sign?"已签到":"未签到" + } } } } } - return sumData; } getCookieMap(cookie) {