From 703e46de70bc8f96398ed22f131e1924615ff005 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 23 Jul 2024 15:14:21 +0800 Subject: [PATCH] feat: add view --- lib/routes/apnews/rss.ts | 3 ++- lib/routes/apnews/topics.ts | 3 ++- lib/routes/bilibili/dynamic.ts | 3 ++- lib/routes/bilibili/ranking.ts | 3 ++- lib/routes/bilibili/video.ts | 3 ++- lib/routes/dockerhub/build.ts | 3 ++- lib/routes/douban/other/group.ts | 3 ++- lib/routes/fediverse/timeline.ts | 3 ++- lib/routes/github/issue.ts | 3 ++- lib/routes/instagram/private-api/index.ts | 3 ++- lib/routes/javbus/index.ts | 3 ++- lib/routes/lofter/user.ts | 3 ++- lib/routes/pixiv/ranking.ts | 3 ++- lib/routes/pixiv/search.ts | 3 ++- lib/routes/pixiv/user.ts | 3 ++- lib/routes/reuters/common.ts | 3 ++- lib/routes/rsshub/routes.ts | 3 ++- lib/routes/telegram/channel.ts | 3 ++- lib/routes/twitter/keyword.ts | 3 ++- lib/routes/twitter/media.ts | 3 ++- lib/routes/twitter/user.ts | 3 ++- lib/routes/weibo/keyword.ts | 3 ++- lib/routes/weibo/user.ts | 3 ++- lib/routes/xiaoyuzhou/podcast.ts | 3 ++- lib/routes/youtube/user.ts | 3 ++- lib/routes/zhihu/activities.ts | 3 ++- lib/types.ts | 14 ++++++++++++++ 27 files changed, 66 insertions(+), 26 deletions(-) diff --git a/lib/routes/apnews/rss.ts b/lib/routes/apnews/rss.ts index 8e7ffcbcefe73c..a6a6270d911cc1 100644 --- a/lib/routes/apnews/rss.ts +++ b/lib/routes/apnews/rss.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import parser from '@/utils/rss-parser'; import { fetchArticle } from './utils'; const HOME_PAGE = 'https://apnews.com'; @@ -7,6 +7,7 @@ export const route: Route = { path: '/rss/:category?', categories: ['traditional-media', 'popular'], example: '/apnews/rss/business', + view: ViewType.Articles, parameters: { category: { description: 'Category from the first segment of the corresponding site, or `index` for the front page.', diff --git a/lib/routes/apnews/topics.ts b/lib/routes/apnews/topics.ts index 5f89a5204260d0..ddb8b9deeeb084 100644 --- a/lib/routes/apnews/topics.ts +++ b/lib/routes/apnews/topics.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import { load } from 'cheerio'; import { fetchArticle, removeDuplicateByKey } from './utils'; @@ -8,6 +8,7 @@ export const route: Route = { path: '/topics/:topic?', categories: ['traditional-media', 'popular'], example: '/apnews/topics/apf-topnews', + view: ViewType.Articles, parameters: { topic: { description: 'Topic name, can be found in URL. For example: the topic name of AP Top News [https://apnews.com/apf-topnews](https://apnews.com/apf-topnews) is `apf-topnews`', diff --git a/lib/routes/bilibili/dynamic.ts b/lib/routes/bilibili/dynamic.ts index 455a816d535312..3f8f7cd7796489 100644 --- a/lib/routes/bilibili/dynamic.ts +++ b/lib/routes/bilibili/dynamic.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import cache from '@/utils/cache'; import got from '@/utils/got'; import JSONbig from 'json-bigint'; @@ -11,6 +11,7 @@ import { BilibiliWebDynamicResponse, Item2, Modules } from './api-interface'; export const route: Route = { path: '/user/dynamic/:uid/:routeParams?', categories: ['social-media', 'popular'], + view: ViewType.SocialMedia, example: '/bilibili/user/dynamic/2267573', parameters: { uid: '用户 id, 可在 UP 主主页中找到', diff --git a/lib/routes/bilibili/ranking.ts b/lib/routes/bilibili/ranking.ts index 0680ddbba13d8b..59d316cb954bcc 100644 --- a/lib/routes/bilibili/ranking.ts +++ b/lib/routes/bilibili/ranking.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import utils from './utils'; @@ -7,6 +7,7 @@ export const route: Route = { name: '排行榜', maintainers: ['DIYgod'], categories: ['social-media', 'popular'], + view: ViewType.Videos, example: '/bilibili/ranking/0/3/1', parameters: { rid: { diff --git a/lib/routes/bilibili/video.ts b/lib/routes/bilibili/video.ts index 762786f7836f33..221ae715ed347e 100644 --- a/lib/routes/bilibili/video.ts +++ b/lib/routes/bilibili/video.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import cache from './cache'; import utils from './utils'; @@ -7,6 +7,7 @@ import logger from '@/utils/logger'; export const route: Route = { path: '/user/video/:uid/:disableEmbed?', categories: ['social-media', 'popular'], + view: ViewType.Videos, example: '/bilibili/user/video/2267573', parameters: { uid: '用户 id, 可在 UP 主主页中找到', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' }, features: { diff --git a/lib/routes/dockerhub/build.ts b/lib/routes/dockerhub/build.ts index 84cee0105185f7..c38344e6d8991e 100644 --- a/lib/routes/dockerhub/build.ts +++ b/lib/routes/dockerhub/build.ts @@ -1,10 +1,11 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import { hash } from './utils'; export const route: Route = { path: '/build/:owner/:image/:tag?', categories: ['program-update', 'popular'], + view: ViewType.Notifications, example: '/dockerhub/build/diygod/rsshub', parameters: { owner: 'Image owner, the owner of the official image fills in the library, for example: /dockerhub/build/library/mysql', diff --git a/lib/routes/douban/other/group.ts b/lib/routes/douban/other/group.ts index d94df05edec560..54798f01ecdb37 100644 --- a/lib/routes/douban/other/group.ts +++ b/lib/routes/douban/other/group.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -6,6 +6,7 @@ import { load } from 'cheerio'; export const route: Route = { path: '/group/:groupid/:type?', categories: ['social-media', 'popular'], + view: ViewType.SocialMedia, example: '/douban/group/648102', parameters: { groupid: '豆瓣小组的 id', diff --git a/lib/routes/fediverse/timeline.ts b/lib/routes/fediverse/timeline.ts index da4dc964247331..14d8c9945d6580 100644 --- a/lib/routes/fediverse/timeline.ts +++ b/lib/routes/fediverse/timeline.ts @@ -1,5 +1,5 @@ import InvalidParameterError from '@/errors/types/invalid-parameter'; -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import { parseDate } from '@/utils/parse-date'; import ofetch from '@/utils/ofetch'; @@ -9,6 +9,7 @@ import ConfigNotFoundError from '@/errors/types/config-not-found'; export const route: Route = { path: '/timeline/:account', categories: ['social-media', 'popular'], + view: ViewType.SocialMedia, example: '/fediverse/timeline/Mastodon@mastodon.social', parameters: { account: 'username@domain' }, features: { diff --git a/lib/routes/github/issue.ts b/lib/routes/github/issue.ts index e8079d45a1e9f5..319aaa5d84b5b0 100644 --- a/lib/routes/github/issue.ts +++ b/lib/routes/github/issue.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import { config } from '@/config'; import MarkdownIt from 'markdown-it'; @@ -12,6 +12,7 @@ import { parseDate } from '@/utils/parse-date'; export const route: Route = { path: '/issue/:user/:repo/:state?/:labels?', categories: ['programming', 'popular'], + view: ViewType.Notifications, example: '/github/issue/DIYgod/RSSHub/open', parameters: { user: 'GitHub username', diff --git a/lib/routes/instagram/private-api/index.ts b/lib/routes/instagram/private-api/index.ts index 0b9e818254d6d0..45e6f481fde14c 100644 --- a/lib/routes/instagram/private-api/index.ts +++ b/lib/routes/instagram/private-api/index.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import cache from '@/utils/cache'; import { ig, login } from './utils'; import logger from '@/utils/logger'; @@ -59,6 +59,7 @@ async function loadContent(category, nameOrId, tryGet) { export const route: Route = { path: '/:category/:key', categories: ['social-media', 'popular'], + view: ViewType.SocialMedia, example: '/instagram/user/stefaniejoosten', parameters: { category: { diff --git a/lib/routes/javbus/index.ts b/lib/routes/javbus/index.ts index 747e72ca2728a8..f07d9b3ebcfe11 100644 --- a/lib/routes/javbus/index.ts +++ b/lib/routes/javbus/index.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import { getCurrentPath } from '@/utils/helpers'; const __dirname = getCurrentPath(import.meta.url); @@ -30,6 +30,7 @@ export const route: Route = { name: 'Works', maintainers: ['MegrezZhu', 'CoderTonyChan', 'nczitzk', 'Felix2yu'], categories: ['multimedia', 'popular'], + view: ViewType.Videos, handler, url: 'www.javbus.com', example: '/javbus/star/rwt', diff --git a/lib/routes/lofter/user.ts b/lib/routes/lofter/user.ts index a9f0a6dc1b8db0..5cfda73cc8193e 100644 --- a/lib/routes/lofter/user.ts +++ b/lib/routes/lofter/user.ts @@ -1,5 +1,5 @@ import InvalidParameterError from '@/errors/types/invalid-parameter'; -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import { parseDate } from '@/utils/parse-date'; import { isValidHost } from '@/utils/valid-host'; @@ -8,6 +8,7 @@ export const route: Route = { path: '/user/:name?', categories: ['social-media', 'popular'], example: '/lofter/user/i', + view: ViewType.Articles, parameters: { name: 'Lofter user name, can be found in the URL' }, features: { requireConfig: false, diff --git a/lib/routes/pixiv/ranking.ts b/lib/routes/pixiv/ranking.ts index 8138a31ef12556..834721479e5c6e 100644 --- a/lib/routes/pixiv/ranking.ts +++ b/lib/routes/pixiv/ranking.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import cache from '@/utils/cache'; import { getToken } from './token'; import getRanking from './api/get-ranking'; @@ -61,6 +61,7 @@ const alias = { export const route: Route = { path: '/ranking/:mode/:date?', categories: ['social-media', 'popular'], + view: ViewType.Pictures, example: '/pixiv/ranking/week', parameters: { mode: { diff --git a/lib/routes/pixiv/search.ts b/lib/routes/pixiv/search.ts index eeee96090ebc2f..315da57f28b50e 100644 --- a/lib/routes/pixiv/search.ts +++ b/lib/routes/pixiv/search.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import cache from '@/utils/cache'; import { getToken } from './token'; import searchPopularIllust from './api/search-popular-illust'; @@ -11,6 +11,7 @@ import ConfigNotFoundError from '@/errors/types/config-not-found'; export const route: Route = { path: '/search/:keyword/:order?/:mode?', categories: ['social-media', 'popular'], + view: ViewType.Pictures, example: '/pixiv/search/Nezuko/popular', parameters: { keyword: 'keyword', diff --git a/lib/routes/pixiv/user.ts b/lib/routes/pixiv/user.ts index 8dc274b267d67c..4bdd6e6b8afa94 100644 --- a/lib/routes/pixiv/user.ts +++ b/lib/routes/pixiv/user.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import cache from '@/utils/cache'; import { getToken } from './token'; import getIllusts from './api/get-illusts'; @@ -10,6 +10,7 @@ import ConfigNotFoundError from '@/errors/types/config-not-found'; export const route: Route = { path: '/user/:id', categories: ['social-media', 'popular'], + view: ViewType.Pictures, example: '/pixiv/user/15288095', parameters: { id: "user id, available in user's homepage URL" }, features: { diff --git a/lib/routes/reuters/common.ts b/lib/routes/reuters/common.ts index 4571c900452501..5ae962ab299adf 100644 --- a/lib/routes/reuters/common.ts +++ b/lib/routes/reuters/common.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import { getCurrentPath } from '@/utils/helpers'; const __dirname = getCurrentPath(import.meta.url); @@ -12,6 +12,7 @@ import path from 'node:path'; export const route: Route = { path: '/:category/:topic?', categories: ['traditional-media', 'popular'], + view: ViewType.Articles, example: '/reuters/world/us', parameters: { category: 'find it in the URL, or tables below', topic: 'find it in the URL, or tables below' }, features: { diff --git a/lib/routes/rsshub/routes.ts b/lib/routes/rsshub/routes.ts index 1c148136656420..041c7afc60e22e 100644 --- a/lib/routes/rsshub/routes.ts +++ b/lib/routes/rsshub/routes.ts @@ -1,10 +1,11 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import { load } from 'cheerio'; export const route: Route = { path: '/routes/:lang?', categories: ['program-update', 'popular'], + view: ViewType.Notifications, example: '/rsshub/routes/en', parameters: { lang: { diff --git a/lib/routes/telegram/channel.ts b/lib/routes/telegram/channel.ts index 6821068930edb6..dcdd62e252d775 100644 --- a/lib/routes/telegram/channel.ts +++ b/lib/routes/telegram/channel.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import { getCurrentPath } from '@/utils/helpers'; import cache from '@/utils/cache'; import { config } from '@/config'; @@ -58,6 +58,7 @@ const mediaTagDict = { export const route: Route = { path: '/channel/:username/:routeParams?', categories: ['social-media', 'popular'], + view: ViewType.SocialMedia, example: '/telegram/channel/awesomeRSSHub', parameters: { username: 'channel username', diff --git a/lib/routes/twitter/keyword.ts b/lib/routes/twitter/keyword.ts index 0cf2c74ab10333..990ead5a4d7730 100644 --- a/lib/routes/twitter/keyword.ts +++ b/lib/routes/twitter/keyword.ts @@ -1,10 +1,11 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import api from './api'; import utils from './utils'; export const route: Route = { path: '/keyword/:keyword/:routeParams?', categories: ['social-media', 'popular'], + view: ViewType.SocialMedia, example: '/twitter/keyword/RSSHub', parameters: { keyword: 'keyword', routeParams: 'extra parameters, see the table above' }, features: { diff --git a/lib/routes/twitter/media.ts b/lib/routes/twitter/media.ts index d2a155ea9fe242..bd3dba7195b510 100644 --- a/lib/routes/twitter/media.ts +++ b/lib/routes/twitter/media.ts @@ -1,10 +1,11 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import api from './api'; import utils from './utils'; export const route: Route = { path: '/media/:id/:routeParams?', categories: ['social-media', 'popular'], + view: ViewType.Pictures, example: '/twitter/media/_RSSHub', parameters: { id: 'username; in particular, if starts with `+`, it will be recognized as a [unique ID](https://github.com/DIYgod/RSSHub/issues/12221), e.g. `+44196397`', routeParams: 'extra parameters, see the table above.' }, features: { diff --git a/lib/routes/twitter/user.ts b/lib/routes/twitter/user.ts index d3422945955646..025de9a1b469af 100644 --- a/lib/routes/twitter/user.ts +++ b/lib/routes/twitter/user.ts @@ -1,10 +1,11 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import utils from './utils'; import api from './api'; export const route: Route = { path: '/user/:id/:routeParams?', categories: ['social-media', 'popular'], + view: ViewType.SocialMedia, example: '/twitter/user/_RSSHub', parameters: { id: 'username; in particular, if starts with `+`, it will be recognized as a [unique ID](https://github.com/DIYgod/RSSHub/issues/12221), e.g. `+44196397`', diff --git a/lib/routes/weibo/keyword.ts b/lib/routes/weibo/keyword.ts index 2f11268170fd4b..27baeea1aa6eb8 100644 --- a/lib/routes/weibo/keyword.ts +++ b/lib/routes/weibo/keyword.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import cache from '@/utils/cache'; import querystring from 'querystring'; import got from '@/utils/got'; @@ -10,6 +10,7 @@ import { config } from '@/config'; export const route: Route = { path: '/keyword/:keyword/:routeParams?', categories: ['social-media', 'popular'], + view: ViewType.SocialMedia, example: '/weibo/keyword/RSSHub', parameters: { keyword: '你想订阅的微博关键词', routeParams: '额外参数;请参阅上面的说明和表格' }, features: { diff --git a/lib/routes/weibo/user.ts b/lib/routes/weibo/user.ts index e356b89883a693..9f2a5bdb2a9d79 100644 --- a/lib/routes/weibo/user.ts +++ b/lib/routes/weibo/user.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import cache from '@/utils/cache'; import querystring from 'querystring'; import got from '@/utils/got'; @@ -11,6 +11,7 @@ import { fallback, queryToBoolean } from '@/utils/readable-social'; export const route: Route = { path: '/user/:uid/:routeParams?', categories: ['social-media', 'popular'], + view: ViewType.SocialMedia, example: '/weibo/user/1195230310', parameters: { uid: '用户 id, 博主主页打开控制台执行 `$CONFIG.oid` 获取', routeParams: '额外参数;请参阅上面的说明和表格;特别地,当 `routeParams=1` 时开启微博视频显示' }, features: { diff --git a/lib/routes/xiaoyuzhou/podcast.ts b/lib/routes/xiaoyuzhou/podcast.ts index d4493aa354d709..6cedcbd44b9cf6 100644 --- a/lib/routes/xiaoyuzhou/podcast.ts +++ b/lib/routes/xiaoyuzhou/podcast.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -6,6 +6,7 @@ import { parseDate } from '@/utils/parse-date'; export const route: Route = { path: '/podcast/:id', categories: ['multimedia', 'popular'], + view: ViewType.Audios, example: '/xiaoyuzhou/podcast/6021f949a789fca4eff4492c', parameters: { id: '播客id,可以在小宇宙播客的 URL 中找到' }, features: { diff --git a/lib/routes/youtube/user.ts b/lib/routes/youtube/user.ts index f773b160992434..a9dc403b67ba95 100644 --- a/lib/routes/youtube/user.ts +++ b/lib/routes/youtube/user.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import cache from '@/utils/cache'; import utils from './utils'; import { config } from '@/config'; @@ -10,6 +10,7 @@ import ConfigNotFoundError from '@/errors/types/config-not-found'; export const route: Route = { path: '/user/:username/:embed?', categories: ['social-media', 'popular'], + view: ViewType.Videos, example: '/youtube/user/@JFlaMusic', parameters: { username: 'YouTuber username with @', embed: 'Default to embed the video, set to any value to disable embedding' }, features: { diff --git a/lib/routes/zhihu/activities.ts b/lib/routes/zhihu/activities.ts index ee3738e1cb3c57..29c8b8cc19c095 100644 --- a/lib/routes/zhihu/activities.ts +++ b/lib/routes/zhihu/activities.ts @@ -1,4 +1,4 @@ -import { Route } from '@/types'; +import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import { header, processImage, getSignedHeader } from './utils'; import { parseDate } from '@/utils/parse-date'; @@ -6,6 +6,7 @@ import { parseDate } from '@/utils/parse-date'; export const route: Route = { path: '/people/activities/:id', categories: ['social-media', 'popular'], + view: ViewType.Articles, example: '/zhihu/people/activities/diygod', parameters: { id: '作者 id,可在用户主页 URL 中找到' }, features: { diff --git a/lib/types.ts b/lib/types.ts index 6c09c7b4ddff62..bd576f01d819c6 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -125,6 +125,15 @@ interface Namespace extends NamespaceItem { export type { Namespace }; +export enum ViewType { + Articles = 0, + SocialMedia = 1, + Pictures = 2, + Videos = 3, + Audios = 4, + Notifications = 5, +} + // route interface RouteItem { /** @@ -223,6 +232,11 @@ interface RouteItem { * The [RSSHub-Radar](https://github.com/DIYgod/RSSHub-Radar) rule of the route */ radar?: RadarItem[]; + + /** + * The [Follow](https://github.com/RSSNext/follow) default view of the route, default to `ViewType.Articles` + */ + view?: ViewType; } interface Route extends RouteItem {