mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 02:58:08 +08:00
feat: dida365, close #6486
This commit is contained in:
@@ -177,6 +177,10 @@ const calculateValue = () => {
|
||||
game4399: {
|
||||
cookie: envs.GAME_4399,
|
||||
},
|
||||
dida365: {
|
||||
username: envs.DIDA365_USERNAME,
|
||||
password: envs.DIDA365_PASSWORD,
|
||||
},
|
||||
};
|
||||
};
|
||||
calculateValue();
|
||||
|
||||
@@ -3727,4 +3727,7 @@ router.get('/mathunion/fields-medal', require('./routes/mathunion/fields-medal')
|
||||
// ACM
|
||||
router.get('/acm/amturingaward', require('./routes/acm/amturingaward'));
|
||||
|
||||
// 滴答清单
|
||||
router.get('/dida365/habit/checkins', require('./routes/dida365/habit-checkins'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
69
lib/routes/dida365/habit-checkins.js
Normal file
69
lib/routes/dida365/habit-checkins.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const got = require('@/utils/got');
|
||||
const { CookieJar } = require('tough-cookie');
|
||||
const config = require('@/config').value;
|
||||
const logger = require('@/utils/logger');
|
||||
|
||||
let loginFlag;
|
||||
const cookieJar = new CookieJar();
|
||||
|
||||
if (config.dida365.username && config.dida365.password) {
|
||||
got({
|
||||
method: 'post',
|
||||
url: 'https://api.dida365.com/api/v2/user/signon?wc=true&remember=true',
|
||||
cookieJar,
|
||||
json: {
|
||||
username: config.dida365.username,
|
||||
password: config.dida365.password,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
loginFlag = true;
|
||||
logger.info('Dida365 login success.');
|
||||
})
|
||||
.catch(() => {
|
||||
logger.error('Dida365 login fail.');
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
if (loginFlag) {
|
||||
const habitsListRes = await got.get({
|
||||
url: 'https://api.dida365.com/api/v2/habits',
|
||||
cookieJar,
|
||||
});
|
||||
const habitsList = habitsListRes.data;
|
||||
|
||||
const paramsList = [];
|
||||
habitsList.forEach((item) => {
|
||||
paramsList.push(['habitIds', item.id]);
|
||||
});
|
||||
const searchParams = new URLSearchParams(paramsList);
|
||||
|
||||
const checkinsRes = await got.get({
|
||||
url: 'https://api.dida365.com/api/v2/habitCheckins',
|
||||
cookieJar,
|
||||
searchParams,
|
||||
});
|
||||
const checkins = checkinsRes.data;
|
||||
let list = [];
|
||||
for (const habitId in checkins.checkins) {
|
||||
const info = habitsList.find((item) => item.id === habitId);
|
||||
list = list.concat(
|
||||
checkins.checkins[habitId].map((checkin, index) => ({
|
||||
title: `第${index + 1}天${info.name}打卡`,
|
||||
pubDate: checkin.checkinTime,
|
||||
link: `https://dida365.com/webapp/#q/all/habit/${checkin.habitId}`,
|
||||
guid: checkin.id,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: '滴答清单打卡',
|
||||
link: 'https://dida365.com/webapp/#q/all/habit/',
|
||||
item: list,
|
||||
};
|
||||
} else {
|
||||
throw Error('Login required');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user