Skip to content

Commit

Permalink
feat: add view
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jul 23, 2024
1 parent d7e02eb commit 703e46d
Show file tree
Hide file tree
Showing 27 changed files with 66 additions and 26 deletions.
3 changes: 2 additions & 1 deletion lib/routes/apnews/rss.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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.',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/apnews/topics.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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`',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/bilibili/dynamic.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 主主页中找到',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/bilibili/ranking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Route } from '@/types';
import { Route, ViewType } from '@/types';
import got from '@/utils/got';
import utils from './utils';

Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/bilibili/video.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/dockerhub/build.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/douban/other/group.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Route } from '@/types';
import { Route, ViewType } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
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',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/fediverse/timeline.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/github/issue.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/instagram/private-api/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/javbus/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Route } from '@/types';
import { Route, ViewType } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

Expand Down Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/lofter/user.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/pixiv/ranking.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/pixiv/search.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/pixiv/user.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/reuters/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Route } from '@/types';
import { Route, ViewType } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/rsshub/routes.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/telegram/channel.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/twitter/keyword.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/twitter/media.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/twitter/user.ts
Original file line number Diff line number Diff line change
@@ -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`',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/weibo/keyword.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/weibo/user.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/xiaoyuzhou/podcast.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Route } from '@/types';
import { Route, ViewType } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/youtube/user.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/zhihu/activities.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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';

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: {
Expand Down
14 changes: 14 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 703e46d

Please sign in to comment.