feat(route): add AzurLane JP news (#20374)

* feat(route): add AzurLane JP news

* fix(route): azurlane jp incorrect namespace

* Update lib/routes/azurlane/news.ts
This commit is contained in:
AnitsuriW 2025-10-29 19:53:58 +08:00 committed by GitHub
parent 2c39ff0ca9
commit 283cc9cb93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,8 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Azur Lane',
url: 'azurlane.jp',
categories: ['game'],
lang: 'ja',
};

View File

@ -0,0 +1,90 @@
import type { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
type Mapping = Record<string, string>;
const JP: Mapping = {
'0': 'すべて',
'1': 'お知らせ',
'2': 'イベント',
'3': 'メインテナンス',
'4': '重要',
};
const mkTable = (mapping: Mapping): string => {
const heading: string[] = [];
const separator: string[] = [];
const body: string[] = [];
for (const key in mapping) {
heading.push(mapping[key]);
separator.push(':--:');
body.push(key);
}
return [heading.join(' | '), separator.join(' | '), body.join(' | ')].map((s) => `| ${s} |`).join('\n');
};
const handler: Route['handler'] = async (ctx) => {
const { server } = ctx.req.param();
switch (server.toUpperCase()) {
case 'JP':
return await ja(ctx);
default:
throw new Error('Unsupported server');
}
};
const ja: Route['handler'] = async (ctx) => {
const { type = '0' } = ctx.req.param();
const response = await ofetch<{ data: { rows: { id: number; content: string; title: string; publishTime: number }[] } }>('https://www.azurlane.jp/api/news/list', {
query: {
type,
index: 1,
size: 15,
},
});
const list = response.data?.rows || [];
const items = list.map((item) => ({
title: item.title,
description: item.content,
link: `https://www.azurlane.jp/news/${item.id}`,
pubDate: parseDate(item.publishTime),
}));
return {
title: `アズールレーン - ${JP[type]}`,
link: 'https://www.azurlane.jp/news',
language: 'ja-JP',
image: 'https://play-lh.googleusercontent.com/9QTLYD2_Jd6OIKHwRHkEBnFAgPmVKJwf2xmHjzPk-5w0SRLZumsCoQZGlO8d_kB3Gdld=w480-h960-rw',
icon: 'https://play-lh.googleusercontent.com/9QTLYD2_Jd6OIKHwRHkEBnFAgPmVKJwf2xmHjzPk-5w0SRLZumsCoQZGlO8d_kB3Gdld=w480-h960-rw',
logo: 'https://play-lh.googleusercontent.com/9QTLYD2_Jd6OIKHwRHkEBnFAgPmVKJwf2xmHjzPk-5w0SRLZumsCoQZGlO8d_kB3Gdld=w480-h960-rw',
item: items,
};
};
export const route: Route = {
path: '/news/:server/:type?',
name: 'News',
categories: ['game'],
maintainers: ['AnitsuriW'],
example: '/azurlane/news/jp/0',
parameters: {
server: 'game server (ISO 3166 two-letter country code, case-insensitive), only `JP` is supported for now',
type: 'news type, see the table below, `0` by default',
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
handler,
description: mkTable(JP),
};