From 633c072a523183968b41c99a881442e3cbdfb3ec Mon Sep 17 00:00:00 2001 From: Lfish <39884529+LLLLLFish@users.noreply.github.com> Date: Tue, 11 Jun 2024 02:54:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E4=BC=98=E5=8C=96=E5=B0=91?= =?UTF-8?q?=E6=95=B0=E6=B4=BE=E7=B3=BB=E5=88=97=E8=B7=AF=E7=94=B1=E6=AF=8F?= =?UTF-8?q?=E7=AF=87=E6=96=87=E7=AB=A0=E7=9A=84=E5=B0=81=E9=9D=A2=E5=9B=BE?= =?UTF-8?q?=E7=89=87,=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E5=BF=85=E5=BA=94=E8=B7=AF=E7=94=B1=E4=B8=A4=E4=B8=AA=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=8F=82=E6=95=B0=20(#15859)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update index.ts * Update index.ts * sspai index image * update * update2 * update3 * update4 * --屎山代码😢 * Update lib/routes/bing/daily-wallpaper.ts Co-authored-by: Tony * 😉done😢 * 添加参数来控制输出中文或英文 * 😭添加参数来控制输出中文或英文😭 * remove some Unnecessary codes --------- --- lib/routes/bing/daily-wallpaper.ts | 75 +++++++++++++++++++++++------- lib/routes/sspai/author.ts | 8 +++- lib/routes/sspai/index.ts | 5 +- lib/routes/sspai/matrix.ts | 8 +++- lib/routes/sspai/tag.ts | 8 +++- lib/routes/sspai/topic.ts | 8 +++- lib/routes/sspai/topics.ts | 2 +- 7 files changed, 87 insertions(+), 27 deletions(-) diff --git a/lib/routes/bing/daily-wallpaper.ts b/lib/routes/bing/daily-wallpaper.ts index 10b1460ac..2a6a3d907 100644 --- a/lib/routes/bing/daily-wallpaper.ts +++ b/lib/routes/bing/daily-wallpaper.ts @@ -4,38 +4,77 @@ import { parseDate } from '@/utils/parse-date'; import timezone from '@/utils/timezone'; export const route: Route = { - path: '/', + path: '/:routeParams?', + parameters: { + routeParams: '额外参数type,story和lang:请参阅以下说明和表格', + }, radar: [ { - source: ['cn.bing.com/'], + source: ['www.bing.com/', 'cn.bing.com/'], target: '', }, ], name: '每日壁纸', - maintainers: ['FHYunCai'], + maintainers: ['FHYunCai', 'LLLLLFish'], handler, - url: 'cn.bing.com/', + url: 'www.bing.com/', + example: '/bing/type=UHD&story=1&lang=zh-CN', + description: `| 参数 | 含义 | 接受的值 | 默认值 | 备注 | +|-------|--------------------|-----------------------------------------------------------|-----------|--------------------------------------------------------| +| type | 输出壁纸的像素类型 | UHD/1920x1080/1920x1200/768x1366/1080x1920/1080x1920_logo | 1920x1080 | 1920x1200与1080x1920_logo带有水印,输入的值不在接受范围内都会输出成1920x1080 | +| story | 是否输出壁纸的故事 | 1/0 | 0 | 输入的值不为1都不会输出故事 | +| lang | 输出壁纸图文的地区(中文或者是英文) | zh/en | zh | zh/en输出的壁纸图文不一定是一样的;如果en不生效,试着部署到其他地方 | +`, }; async function handler(ctx) { - const response = await ofetch('HPImageArchive.aspx', { - baseURL: 'https://cn.bing.com', + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); + let type = routeParams.get('type') || '1920x1080'; + let lang = routeParams.get('lang'); + let apiUrl = ''; + const allowedTypes = ['UHD', '1920x1080', '1920x1200', '768x1366', '1080x1920', '1080x1920_logo']; + if (lang !== 'zh' && lang !== 'en') { + lang = 'zh'; + } + if (lang === 'zh') { + lang = 'zh-CN'; + apiUrl = 'https://cn.bing.com'; + } else { + lang = 'en-US'; + apiUrl = 'https://www.bing.com'; + } + if (!allowedTypes.includes(type)) { + type = '1920x1080'; + } + const story = routeParams.get('story') === '1'; + const resp = await ofetch('/hp/api/model', { + baseURL: apiUrl, + method: 'GET', query: { - format: 'js', - idx: 0, - n: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 7, - mkt: 'zh-CN', + mtk: lang, }, }); - const data = response; + const items = resp.MediaContents.map((item) => { + const ssd = item.Ssd; + const link = `${apiUrl}${item.ImageContent.Image.Url.match(/\/th\?id=[^_]+_[^_]+/)[0].replace(/(_\d+x\d+\.webp)$/i, '')}_${type}.jpg`; + let description = `Article Cover Image
`; + if (story) { + description += `${item.ImageContent.Headline}`; + description += `${item.ImageContent.QuickFact.MainText}
`; + description += `

${item.ImageContent.Description}

`; + } + return { + title: item.ImageContent.Title, + description, + link: `${apiUrl}${item.ImageContent.BackstageUrl}`, + author: item.ImageContent.Copyright, + pubDate: timezone(parseDate(ssd, 'YYYYMMDD_HHmm'), 0), + }; + }); return { title: 'Bing每日壁纸', - link: 'https://cn.bing.com/', - item: data.images.map((item) => ({ - title: item.copyright, - description: ``, - link: item.copyrightlink, - pubDate: timezone(parseDate(item.fullstartdate), 0), - })), + link: apiUrl, + description: 'Bing每日壁纸', + item: items, }; } diff --git a/lib/routes/sspai/author.ts b/lib/routes/sspai/author.ts index fced3b0cf..f9d3666b9 100644 --- a/lib/routes/sspai/author.ts +++ b/lib/routes/sspai/author.ts @@ -61,7 +61,13 @@ async function handler(ctx) { const key = `sspai: ${item.id}`; return cache.tryGet(key, async () => { const response = await got(link); - description = response.data.data.body; + // description = response.data.data.body; + const articleData = response.data.data; + const banner = articleData.promote_image; + if (banner) { + description = `Article Cover Image
`; + } + description += articleData.body; return { title: item.title.trim(), diff --git a/lib/routes/sspai/index.ts b/lib/routes/sspai/index.ts index ad27475f8..6216d0011 100644 --- a/lib/routes/sspai/index.ts +++ b/lib/routes/sspai/index.ts @@ -42,10 +42,7 @@ async function handler() { return cache.tryGet(key, async () => { const response = await got({ method: 'get', url: link }); const articleData = response.data.data; - let banner = articleData.banner; - if (articleData.keywords.includes('派早报')) { - banner = `https://cdnfile.sspai.com/${banner}`; - } + const banner = articleData.promote_image; if (banner) { description = `Article Cover Image
`; } diff --git a/lib/routes/sspai/matrix.ts b/lib/routes/sspai/matrix.ts index 2ade91768..0adfd5c3f 100644 --- a/lib/routes/sspai/matrix.ts +++ b/lib/routes/sspai/matrix.ts @@ -42,7 +42,13 @@ async function handler() { const key = `sspai: ${item.id}`; return cache.tryGet(key, async () => { const response = await got(link); - description = response.data.data.body; + // description = response.data.data.body; + const articleData = response.data.data; + const banner = articleData.promote_image; + if (banner) { + description = `Article Cover Image
`; + } + description += articleData.body; return { title: item.title.trim(), diff --git a/lib/routes/sspai/tag.ts b/lib/routes/sspai/tag.ts index 5e4c40e7f..b56547b8f 100644 --- a/lib/routes/sspai/tag.ts +++ b/lib/routes/sspai/tag.ts @@ -46,7 +46,13 @@ async function handler(ctx) { const key = `sspai: ${item.id}`; return cache.tryGet(key, async () => { const response = await got({ method: 'get', url: link, headers: { Referer: host } }); - description = response.data.data.body; + // description = response.data.data.body; + const articleData = response.data.data; + const banner = articleData.promote_image; + if (banner) { + description = `Article Cover Image
`; + } + description += articleData.body; return { title: item.title.trim(), diff --git a/lib/routes/sspai/topic.ts b/lib/routes/sspai/topic.ts index 5ca450d5e..bb90ece19 100644 --- a/lib/routes/sspai/topic.ts +++ b/lib/routes/sspai/topic.ts @@ -52,7 +52,13 @@ async function handler(ctx) { } return cache.tryGet(`sspai: ${item.id}`, async () => { const response = await got(link); - const description = response.data.data.body; + let description = ''; + const articleData = response.data.data; + const banner = articleData.promote_image; + if (banner) { + description = `Article Cover Image
`; + } + description += articleData.body; const single = { title, diff --git a/lib/routes/sspai/topics.ts b/lib/routes/sspai/topics.ts index c23b96df7..90d7ecfd7 100644 --- a/lib/routes/sspai/topics.ts +++ b/lib/routes/sspai/topics.ts @@ -42,7 +42,7 @@ async function handler() { const key = `sspai:topics:${item.id}`; return cache.tryGet(key, () => { - description = `${item.intro}

如有兴趣,请复制链接订阅

https://rsshub.app/sspai/topic/${item.id}

`; + description = `
Article Cover Image${item.intro}
如有兴趣,请复制链接订阅

https://rsshub.app/sspai/topic/${item.id}

`; return { title: item.title.trim(),