refactor: bangumi 每日放送添加id 修改缓存时间 (#2097)
* update: bangumi 每日放送添加id 修改缓存时间 * update: 恢复计算今日的方法
This commit is contained in:
parent
e978b81f04
commit
a434c9a50b
|
|
@ -1,5 +1,19 @@
|
|||
const axios = require('../../../utils/axios');
|
||||
|
||||
/** @type { (timezoneOffset: number) => Date } */
|
||||
const tomorrowMidnight = (timezoneOffset) => {
|
||||
const result = new Date(Date.now());
|
||||
const localHour = result.getHours() + timezoneOffset;
|
||||
if (localHour < 0) {
|
||||
result.setUTCHours(-timezoneOffset, 0, 0, 0);
|
||||
} else if (localHour < 24) {
|
||||
result.setUTCHours(24 - timezoneOffset, 0, 0, 0);
|
||||
} else {
|
||||
result.setUTCHours(48 - timezoneOffset, 0, 0, 0);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const bgmCalendarUrl = 'https://api.bgm.tv/calendar';
|
||||
const bgmDataUrl = 'https://cdn.jsdelivr.net/npm/bangumi-data/dist/data.json';
|
||||
|
|
@ -33,7 +47,7 @@ module.exports = async (ctx) => {
|
|||
data.items = items;
|
||||
}
|
||||
|
||||
ctx.cache.set(url[i], JSON.stringify(data), 86400);
|
||||
ctx.cache.set(url[i], JSON.stringify(data), tomorrowMidnight(8).getTime() - Date.now());
|
||||
return Promise.resolve(data);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ module.exports = async (ctx) => {
|
|||
const [list, data] = await getData(ctx);
|
||||
const siteMeta = data.siteMeta;
|
||||
|
||||
const now = new Date(Date.now());
|
||||
const today = new Date(Date.now());
|
||||
|
||||
now.setHours(now.getHours() + 9);
|
||||
const day = now.getUTCDay();
|
||||
// 将 UTC 时间向前移动9小时,即可在数值上表示东京时间
|
||||
today.setUTCHours(today.getUTCHours() + 9);
|
||||
|
||||
const day = today.getUTCDay();
|
||||
|
||||
const todayList = list.filter((l) => l.weekday.id % 7 === day)[0];
|
||||
|
||||
|
|
@ -33,6 +35,9 @@ module.exports = async (ctx) => {
|
|||
updated.setMinutes(begin.getMinutes());
|
||||
updated.setSeconds(begin.getSeconds());
|
||||
|
||||
const link = `http://bangumi.tv/subject/${bgm.bgm_id}`;
|
||||
const id = `${link}#${new Intl.DateTimeFormat('zh-CN').format(updated)}`;
|
||||
|
||||
const image = `<img referrerpolicy="no-referrer" src=${bgm.image} />`;
|
||||
const html =
|
||||
image +
|
||||
|
|
@ -51,6 +56,8 @@ module.exports = async (ctx) => {
|
|||
'</ul>';
|
||||
|
||||
return {
|
||||
id,
|
||||
guid: id,
|
||||
title: [
|
||||
bgm.title,
|
||||
Object.values(bgm.titleTranslate)
|
||||
|
|
@ -59,7 +66,7 @@ module.exports = async (ctx) => {
|
|||
].join('|'),
|
||||
updated: updated.toISOString(),
|
||||
pubDate: updated.toUTCString(),
|
||||
link: `http://bangumi.tv/subject/${bgm.bgm_id}`,
|
||||
link,
|
||||
description: html,
|
||||
content: { html },
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue