Skip to content

Commit

Permalink
Merge pull request #1332 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Apr 1, 2024
2 parents 4e44c32 + 255f04b commit ef5bc1a
Show file tree
Hide file tree
Showing 127 changed files with 2,038 additions and 1,443 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
github: DIYgod
patreon: DIYgod
open_collective: RSSHub
custom: ['https://afdian.net/a/diygod', 'https://docs.rsshub.app/support']
custom: ['https://afdian.net/a/diygod', 'https://docs.rsshub.app/sponsor']
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ body:
- type: markdown
attributes:
value: |
Please ensure you have read [documentation](https://docs.rsshub.app/en), and provide all the information required by this template, otherwise the issue will be closed immediately.
Please ensure you have read [documentation](https://docs.rsshub.app/), and provide all the information required by this template, otherwise the issue will be closed immediately.
Due to the anti-crawling policy implemented by certain websites, some RSS routes provided by the demo will return status code 403. This is not an issue caused by RSSHub and please do not report it.
- type: textarea
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ body:
- type: markdown
attributes:
value: |
Please ensure the feature requested is not listed in [documentation](https://docs.rsshub.app/en) or [issue](https://github.com/DIYgod/RSSHub/issues), and is not a [new RSS proposal](https://github.com/DIYgod/RSSHub/issues/new?assignees=&labels=RSS+proposal&template=rss_request_en.yml), and provide all the information required by this template.
Please ensure the feature requested is not listed in [documentation](https://docs.rsshub.app/) or [issue](https://github.com/DIYgod/RSSHub/issues), and is not a [new RSS proposal](https://github.com/DIYgod/RSSHub/issues/new?assignees=&labels=RSS+proposal&template=rss_request_en.yml), and provide all the information required by this template.
Otherwise the issue will be closed immediately.
- type: textarea
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/rss_request_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ body:
- type: markdown
attributes:
value: |
Please ensure the RSS proposal is not listed in [documentation](https://docs.rsshub.app/en) or [issue](https://github.com/DIYgod/RSSHub/issues), website doesn't provide this kind of RSS feed, and provide all the information required by this template.
Please ensure the RSS proposal is not listed in [documentation](https://docs.rsshub.app/) or [issue](https://github.com/DIYgod/RSSHub/issues), website doesn't provide this kind of RSS feed, and provide all the information required by this template.
Otherwise the issue will be closed immediately.
We are flooded with feature requests and short-handed, please try to make it yourself, the [guide](https://docs.rsshub.app/joinus) is a good place to start. Submit a pull request when done!
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## Please refer to [Join Us](https://docs.rsshub.app/joinus/quick-start)
## Please refer to [Join Us](https://docs.rsshub.app/joinus/)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RSSHub can be used with browser extension [RSSHub Radar](https://github.com/DIYg
<a href="https://rss3.io" target="_blank"><img height="50px" src="https://i.imgur.com/lb1dDGK.png"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://xlog.app/" target="_blank"><img height="50px" src="https://i.imgur.com/JuhHTKD.png"></a>
</p>

[![](https://opencollective.com/static/images/become_sponsor.svg)](https://docs.rsshub.app/support/)
[![](https://opencollective.com/static/images/become_sponsor.svg)](https://docs.rsshub.app/sponsor/)

### Contributors

Expand All @@ -54,15 +54,15 @@ Logo designer [sheldonrrr](https://dribbble.com/sheldonrrr)

We welcome all pull requests. Suggestions and feedback are also welcomed [here](https://github.com/DIYgod/RSSHub/issues).

Refer to [Join Us](https://docs.rsshub.app/joinus/quick-start)
Refer to [Join Us](https://docs.rsshub.app/joinus/)

## Deployment

Refer to [Deployment](https://docs.rsshub.app/install/)
Refer to [Deployment](https://docs.rsshub.app/deploy/)

## Support RSSHub

Refer to [Support RSSHub](https://docs.rsshub.app/support/)
Refer to [Support RSSHub](https://docs.rsshub.app/sponsor/)

RSSHub is open source and completely free under the MIT license. However, just like any other open source project, as the project grows, the hosting, development and maintenance requires funding support.

Expand Down
2 changes: 1 addition & 1 deletion api/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ const app = require('../lib/app');
const logger = require('../lib/utils/logger');

logger.info(`🎉 RSSHub is running! Cheers!`);
logger.info('💖 Can you help keep this open source project alive? Please sponsor 👉 https://docs.rsshub.app/support');
logger.info('💖 Can you help keep this open source project alive? Please sponsor 👉 https://docs.rsshub.app/sponsor');

module.exports = handle(app);
2 changes: 1 addition & 1 deletion lib/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@/utils/request-wrapper';
import '@/utils/request-rewriter';

import { Hono } from 'hono';

Expand Down
6 changes: 0 additions & 6 deletions lib/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { describe, expect, it, afterEach, vi } from 'vitest';
import nock from 'nock';

afterEach(() => {
vi.resetModules();
Expand Down Expand Up @@ -93,11 +92,6 @@ describe('config', () => {
it('remote config', async () => {
process.env.REMOTE_CONFIG = 'http://rsshub.test/config';

nock(/rsshub\.test/)
.get('/config')
.reply(200, {
UA: 'test',
});
const { config } = await import('./config');
await new Promise((resolve) => setTimeout(resolve, 100));
expect(config.ua).toBe('test');
Expand Down
7 changes: 3 additions & 4 deletions lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dotenv/config';
import randUserAgent from '@/utils/rand-user-agent';
import got from 'got';
import { ofetch } from 'ofetch';

let envs = process.env;

Expand Down Expand Up @@ -634,9 +634,8 @@ const calculateValue = () => {
calculateValue();

if (envs.REMOTE_CONFIG) {
got.get(envs.REMOTE_CONFIG)
.then(async (response) => {
const data = JSON.parse(response.body);
ofetch(envs.REMOTE_CONFIG)
.then(async (data) => {
if (data) {
envs = Object.assign(envs, data);
calculateValue();
Expand Down
2 changes: 1 addition & 1 deletion lib/errors/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('httperror', () => {
it(`httperror`, async () => {
const response = await request.get('/test/httperror');
expect(response.status).toBe(503);
expect(response.text).toMatch('Response code 404 (Not Found): target website might be blocking our access, you can host your own RSSHub instance for a better usability.');
expect(response.text).toMatch('404 Not Found: target website might be blocking our access, you can host your own RSSHub instance for a better usability.');
}, 20000);
});

Expand Down
2 changes: 1 addition & 1 deletion lib/errors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const errorHandler: ErrorHandler = (error, ctx) => {
}

let message = '';
if (error.name && (error.name === 'HTTPError' || error.name === 'RequestError')) {
if (error.name && (error.name === 'HTTPError' || error.name === 'RequestError' || error.name === 'FetchError')) {
ctx.status(503);
message = `${error.message}: target website might be blocking our access, you can host your own RSSHub instance for a better usability.`;
} else if (error instanceof RequestInProgressError) {
Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const port = config.connect.port;
const hostIPList = getLocalhostAddress();

logger.info(`🎉 RSSHub is running on port ${port}! Cheers!`);
logger.info('💖 Can you help keep this open source project alive? Please sponsor 👉 https://docs.rsshub.app/support');
logger.info('💖 Can you help keep this open source project alive? Please sponsor 👉 https://docs.rsshub.app/sponsor');
logger.info(`🔗 Local: 👉 http://localhost:${port}`);
for (const ip of hostIPList) {
logger.info(`🔗 Network: 👉 http://${ip}:${port}`);
Expand Down
10 changes: 5 additions & 5 deletions lib/middleware/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Parser from 'rss-parser';
import wait from '@/utils/wait';

process.env.CACHE_EXPIRE = '1';
process.env.CACHE_CONTENT_EXPIRE = '3';
process.env.CACHE_CONTENT_EXPIRE = '2';

const parser = new Parser();

Expand Down Expand Up @@ -38,7 +38,7 @@ describe('cache', () => {
expect(response3.headers).not.toHaveProperty('rsshub-cache-status');
const parsed3 = await parser.parseString(await response3.text());

await wait(3 * 1000 + 100);
await wait(2 * 1000 + 100);
const response4 = await app.request('/test/cache');
const parsed4 = await parser.parseString(await response4.text());

Expand All @@ -51,7 +51,7 @@ describe('cache', () => {
await wait(1 * 1000 + 100);
const response5 = await app.request('/test/refreshCache');
const parsed5 = await parser.parseString(await response5.text());
await wait(2 * 1000 + 100);
await wait(1 * 1000 + 100);
const response6 = await app.request('/test/refreshCache');
const parsed6 = await parser.parseString(await response6.text());

Expand Down Expand Up @@ -86,7 +86,7 @@ describe('cache', () => {
expect(response3.headers).not.toHaveProperty('rsshub-cache-status');
const parsed3 = await parser.parseString(await response3.text());

await wait(3 * 1000 + 100);
await wait(2 * 1000 + 100);
const response4 = await app.request('/test/cache');
const parsed4 = await parser.parseString(await response4.text());

Expand All @@ -99,7 +99,7 @@ describe('cache', () => {
await wait(1 * 1000 + 100);
const response5 = await app.request('/test/refreshCache');
const parsed5 = await parser.parseString(await response5.text());
await wait(2 * 1000 + 100);
await wait(1 * 1000 + 100);
const response6 = await app.request('/test/refreshCache');
const parsed6 = await parser.parseString(await response6.text());

Expand Down
30 changes: 7 additions & 23 deletions lib/middleware/parameter.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { describe, expect, it, vi } from 'vitest';
import app from '@/app';
import Parser from 'rss-parser';
import { config } from '@/config';
import nock from 'nock';

process.env.OPENAI_API_KEY = 'sk-1234567890';
process.env.OPENAI_API_ENDPOINT = 'https://api.openai.mock/v1';

vi.mock('@/utils/request-rewriter', () => ({ default: null }));
const { config } = await import('@/config');
const { default: app } = await import('@/app');

const parser = new Parser();

Expand Down Expand Up @@ -424,26 +428,6 @@ describe('multi parameter', () => {

describe('openai', () => {
it(`chatgpt`, async () => {
vi.resetModules();

process.env.OPENAI_API_KEY = 'sk-1234567890';
const app = (await import('@/app')).default;
const { config } = await import('@/config');
nock(config.openai.endpoint)
.post('/chat/completions')
.reply(() => [
200,
{
choices: [
{
message: {
content: 'Summary of the article.',
},
},
],
},
]);

const responseWithGpt = await app.request('/test/gpt?chatgpt=true');
const responseNormal = await app.request('/test/gpt');

Expand Down
15 changes: 7 additions & 8 deletions lib/middleware/parameter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as entities from 'entities';
import { load, type CheerioAPI, type Element } from 'cheerio';
import { simplecc } from 'simplecc-wasm';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { config } from '@/config';
import { RE2JS } from 're2js';
import markdownit from 'markdown-it';
Expand Down Expand Up @@ -34,8 +34,9 @@ const resolveRelativeLink = ($: CheerioAPI, elem: Element, attr: string, baseUrl

const summarizeArticle = async (articleText: string) => {
const apiUrl = `${config.openai.endpoint}/chat/completions`;
const response = await got.post(apiUrl, {
json: {
const response = await ofetch(apiUrl, {
method: 'POST',
body: {
model: config.openai.model,
max_tokens: config.openai.maxTokens,
messages: [
Expand All @@ -49,8 +50,7 @@ const summarizeArticle = async (articleText: string) => {
},
});

// @ts-expect-error custom field
return response.data.choices[0].message.content;
return response.choices[0].message.content;
};

const getAuthorString = (item) => {
Expand Down Expand Up @@ -305,8 +305,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
if (link) {
// if parser failed, return default description and not report error
try {
// @ts-expect-error custom field
const { data: res } = await got(link);
const res = await ofetch(link);
const $ = load(res);
const result = await Parser.parse(link, {
html: $.html(),
Expand Down Expand Up @@ -380,7 +379,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
}
}
} else {
throw new Error(`Invalid parameter brief. Please check the doc https://docs.rsshub.app/parameter#shu-chu-jian-xun`);
throw new Error(`Invalid parameter brief. Please check the doc https://docs.rsshub.app/guide/parameters#shu-chu-jian-xun`);
}
}
// some parameters are processed in `anti-hotlink.js`
Expand Down
6 changes: 3 additions & 3 deletions lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if (Object.keys(modules).length) {
| {
namespace: Namespace;
};
const namespace = module.split('/')[1];
const namespace = module.split(/[/\\]/)[1];
if ('namespace' in content) {
namespaces[namespace] = Object.assign(
{
Expand All @@ -65,13 +65,13 @@ if (Object.keys(modules).length) {
for (const path of content.route.path) {
namespaces[namespace].routes[path] = {
...content.route,
location: module.split('/').slice(2).join('/'),
location: module.split(/[/\\]/).slice(2).join('/'),
};
}
} else {
namespaces[namespace].routes[content.route.path] = {
...content.route,
location: module.split('/').slice(2).join('/'),
location: module.split(/[/\\]/).slice(2).join('/'),
};
}
}
Expand Down
24 changes: 0 additions & 24 deletions lib/routes-deprecated/005tv/zx.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/routes-deprecated/disqus/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = require('@/config').value;

module.exports = async (ctx) => {
if (!config.disqus || !config.disqus.api_key) {
throw new Error('Disqus RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
throw new Error('Disqus RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}
const forum = ctx.params.forum;

Expand Down
2 changes: 1 addition & 1 deletion lib/routes-deprecated/fanfou/favorites.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const utils = require('./utils');

module.exports = async (ctx) => {
if (!config.fanfou || !config.fanfou.consumer_key || !config.fanfou.consumer_secret || !config.fanfou.username || !config.fanfou.password) {
throw new Error('Fanfou RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
throw new Error('Fanfou RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}

const uid = ctx.params.uid;
Expand Down
2 changes: 1 addition & 1 deletion lib/routes-deprecated/fanfou/home-timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const utils = require('./utils');

module.exports = async (ctx) => {
if (!config.fanfou || !config.fanfou.consumer_key || !config.fanfou.consumer_secret || !config.fanfou.username || !config.fanfou.password) {
throw new Error('Fanfou RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
throw new Error('Fanfou RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}

const fanfou = await utils.getFanfou();
Expand Down
2 changes: 1 addition & 1 deletion lib/routes-deprecated/fanfou/public-timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const utils = require('./utils');

module.exports = async (ctx) => {
if (!config.fanfou || !config.fanfou.consumer_key || !config.fanfou.consumer_secret || !config.fanfou.username || !config.fanfou.password) {
throw new Error('Fanfou RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
throw new Error('Fanfou RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}

const keyword = ctx.params.keyword;
Expand Down
2 changes: 1 addition & 1 deletion lib/routes-deprecated/fanfou/user-timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const utils = require('./utils');

module.exports = async (ctx) => {
if (!config.fanfou || !config.fanfou.consumer_key || !config.fanfou.consumer_secret || !config.fanfou.username || !config.fanfou.password) {
throw new Error('Fanfou RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
throw new Error('Fanfou RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}

const uid = ctx.params.uid;
Expand Down
2 changes: 1 addition & 1 deletion lib/routes-deprecated/lastfm/loved.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = require('@/config').value;

module.exports = async (ctx) => {
if (!config.lastfm || !config.lastfm.api_key) {
throw new Error('Last.fm RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
throw new Error('Last.fm RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}

const user = ctx.params.user;
Expand Down
2 changes: 1 addition & 1 deletion lib/routes-deprecated/lastfm/recent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = require('@/config').value;

module.exports = async (ctx) => {
if (!config.lastfm || !config.lastfm.api_key) {
throw new Error('Last.fm RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
throw new Error('Last.fm RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}

const user = ctx.params.user;
Expand Down
Loading

0 comments on commit ef5bc1a

Please sign in to comment.