Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions lib/routes/aiera/latest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/latest',
categories: ['new-media'],
example: '/aiera/latest',
url: 'aiera.com.cn',
name: '最新文章',
maintainers: ['panqingjie00'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['aiera.com.cn'],
target: '/latest',
},
],
handler,
};

async function handler(ctx) {

Check failure

Code scanning / oxlint

eslint(no-unused-vars) Error

Parameter 'ctx' is declared but never used. Unused parameters should start with a '_'.
Consider removing this parameter.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
const response = await cache.tryGet('aiera:latest', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't cache the response as it will refresh the cache duration on each request. This means the entries won't be updated once it's cached.

const { data } = await got('https://aiera.com.cn/wp-json/wp/v2/posts', {
searchParams: {
per_page: 20,
_embed: '',
},
});
return data;
});

if (!Array.isArray(response)) {

Check failure

Code scanning / oxlint

unicorn(prefer-type-error) Error

Prefer throwing a TypeError over a generic Error after a type checking if-statement
Change to throw new TypeError(...)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
throw new Error('Invalid API response');
}

const items = response.map((item) => ({
title: item.title.rendered,
description: item.content.rendered,
pubDate: parseDate(item.date_gmt),
link: item.link,
guid: item.guid.rendered,
author: item._embedded?.author?.[0]?.name,
}));

return {
title: '新智元 - 最新文章',
link: 'https://aiera.com.cn',
description: '新智元最新 AI 新闻资讯',
language: 'zh-CN',
item: items,
};
}
8 changes: 8 additions & 0 deletions lib/routes/aiera/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '新智元',
url: 'aiera.com.cn',
lang: 'zh-CN',
description: '新智元 - AI 新闻资讯平台',
};