Skip to content

Commit

Permalink
Merge pull request #1328 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 Mar 24, 2024
2 parents 407ddaa + 7ac4ffd commit d7db129
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 68 deletions.
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ coverage
.vscode
docker-compose.yml
!/.github
!/docs/.vuepress
lib/routes-deprecated
lib/router.js
babel.config.js
scripts/docker/minify-docker.js
10 changes: 1 addition & 9 deletions .github/workflows/build-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
build:
runs-on: ubuntu-latest
name: Build assets
timeout-minutes: 5
timeout-minutes: 60
permissions:
contents: write
steps:
Expand All @@ -34,16 +34,8 @@ jobs:
run: pnpm i
- name: Build assets
run: pnpm build
- name: Build full routes test result
run: pnpm vitest:fullroutes
- name: Build docs
run: pnpm build:docs
- name: Commit files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git status
git diff-index --quiet HEAD || (git commit -m "chore: auto build" -a --no-verify && git push "https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:master)
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/test-full-routes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build assets

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
name: Build assets
timeout-minutes: 60
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8
- name: Use Node.js Active LTS
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'pnpm'
- name: Install dependencies (yarn)
run: pnpm i
- name: Build assets
run: pnpm build
- name: Build full routes test result
continue-on-error: true
run: pnpm vitest:fullroutes
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./assets
user_name: 'github-actions[bot]'
user_email: '41898282+github-actions[bot]@users.noreply.github.com'
keep_files: true
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/routes-deprecated
lib/router.js
babel.config.js
scripts/docker/minify-docker.js
3 changes: 0 additions & 3 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,6 @@ router.get('/geekpark/breakingnews', lazyloadRouteHandler('./routes/geekpark/bre
// 香港天文台
router.get('/hko/weather', lazyloadRouteHandler('./routes/hko/weather'));

// 技术头条
router.get('/blogread/newest', lazyloadRouteHandler('./routes/blogread/newest'));

// gnn游戏新闻
router.get('/gnn/gnn', lazyloadRouteHandler('./routes/gnn/gnn'));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
import { Route } from '@/types';
import got from '@/utils/got';
import * as cheerio from 'cheerio';

module.exports = async (ctx) => {
const url = 'http://blogread.cn/news/newest.php';
export const route: Route = {
path: '/newest',
categories: ['programming'],
example: '/blogread/newest',
radar: [
{
source: ['blogread.cn/news/newest.php'],
},
],
name: '最新文章',
maintainers: ['fashioncj'],
handler,
};

async function handler() {
const url = 'https://blogread.cn/news/newest.php';
const response = await got({
method: 'get',
url,
Expand All @@ -12,19 +27,19 @@ module.exports = async (ctx) => {
.map((index, elem) => {
elem = $(elem);
const $link = elem.find('dt a');

return {
title: $link.text(),
description: elem.find('dd').eq(0).text(),
link: $link.attr('href'),
author: elem.find('.small a').eq(0).text(),
pubDate: elem.find('dd').eq(1).text().split('\n')[2],
};
})
.get();

ctx.state.data = {
return {
title: '技术头条',
link: url,
item: resultItem,
};
};
}
6 changes: 6 additions & 0 deletions lib/routes/blogread/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '技术头条',
url: 'blogread.cn',
};
18 changes: 0 additions & 18 deletions lib/routes/telegram/tglib/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import readline from 'node:readline/promises';
import { Api, TelegramClient } from 'telegram';
import { UserAuthParams } from 'telegram/client/auth';
import { StringSession } from 'telegram/sessions';
Expand Down Expand Up @@ -187,20 +186,3 @@ function streamDocument(obj, thumbSize = '', offset, limit) {
}

export { client, getMediaLink, decodeMedia, getFilename, streamDocument, streamThumbnail };

if (require.main === module) {
Promise.resolve().then(async () => {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const client = await getClient(
{
phoneNumber: () => rl.question('Please enter your phone number: '),
password: () => rl.question('Please enter your password: '),
phoneCode: () => rl.question('Please enter the code you received: '),
onError: (err) => process.stderr.write(err.toString()),
},
''
);
process.stdout.write(`TELEGRAM_SESSION=${client.session.save()}\n`);
process.exit(0);
});
}
8 changes: 4 additions & 4 deletions lib/utils/proxy/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { config } from '@/config';
import { PacProxyAgent } from 'pac-proxy-agent';
import { HttpsProxyAgent } from 'https-proxy-agent';
import { SocksProxyAgent } from 'socks-proxy-agent';

const proxyIsPAC = config.pacUri || config.pacScript;

Expand All @@ -20,16 +23,13 @@ if (proxyIsPAC) {
proxyUrlHandler = proxy.proxyUrlHandler;
}

let agent = null;
let agent: PacProxyAgent<string> | HttpsProxyAgent<string> | SocksProxyAgent | null = null;
if (proxyIsPAC) {
const { PacProxyAgent } = require('pac-proxy-agent');
agent = new PacProxyAgent(`pac+${proxyUri}`);
} else if (proxyUri) {
if (proxyUri.startsWith('http')) {
const { HttpsProxyAgent } = require('https-proxy-agent');
agent = new HttpsProxyAgent(proxyUri);
} else if (proxyUri.startsWith('socks')) {
const { SocksProxyAgent } = require('socks-proxy-agent');
agent = new SocksProxyAgent(proxyUri);
}
}
Expand Down
25 changes: 1 addition & 24 deletions lib/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { config } from '@/config';
import puppeteer from 'puppeteer';
import logger from './logger';
import proxy from './proxy';

const proxyChain = require('proxy-chain');
import proxyChain from 'proxy-chain';

import { type PuppeteerExtra, addExtra } from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
Expand All @@ -27,28 +26,6 @@ const outPuppeteer = async (
let insidePuppeteer: PuppeteerExtra | typeof puppeteer = puppeteer;
if (extraOptions.stealth) {
insidePuppeteer = addExtra(puppeteer);

// workaround for vercel/nft #54, #283, #304
require('puppeteer-extra-plugin-stealth/evasions/chrome.app');
require('puppeteer-extra-plugin-stealth/evasions/chrome.csi');
require('puppeteer-extra-plugin-stealth/evasions/chrome.loadTimes');
require('puppeteer-extra-plugin-stealth/evasions/chrome.runtime');
require('puppeteer-extra-plugin-stealth/evasions/defaultArgs');
require('puppeteer-extra-plugin-stealth/evasions/iframe.contentWindow');
require('puppeteer-extra-plugin-stealth/evasions/media.codecs');
require('puppeteer-extra-plugin-stealth/evasions/navigator.hardwareConcurrency');
require('puppeteer-extra-plugin-stealth/evasions/navigator.languages');
require('puppeteer-extra-plugin-stealth/evasions/navigator.permissions');
require('puppeteer-extra-plugin-stealth/evasions/navigator.plugins');
require('puppeteer-extra-plugin-stealth/evasions/navigator.vendor');
require('puppeteer-extra-plugin-stealth/evasions/navigator.webdriver');
require('puppeteer-extra-plugin-stealth/evasions/sourceurl');
require('puppeteer-extra-plugin-stealth/evasions/user-agent-override');
require('puppeteer-extra-plugin-stealth/evasions/webgl.vendor');
require('puppeteer-extra-plugin-stealth/evasions/window.outerdimensions');
require('puppeteer-extra-plugin-user-preferences');
require('puppeteer-extra-plugin-user-data-dir');

insidePuppeteer.use(StealthPlugin());
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/workflow/build-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { namespaces } from '../../lib/registry';
import fs from 'node:fs';
import * as path from 'node:path';
import { categories } from './data';
import fullTests from '../../assets/build/test-full-routes.json';
import { getCurrentPath } from '../../lib/utils/helpers';

const fullTests = await (await fetch('https://raw.githubusercontent.com/DIYgod/RSSHub/gh-pages/build/test-full-routes.json')).json();
const testResult = fullTests.testResults[0].assertionResults;

const __dirname = getCurrentPath(import.meta.url);
Expand Down Expand Up @@ -106,7 +106,7 @@ function generateMd(lang) {
}
: undefined;
md[category] += `### ${data.name} ${data.url || docs[category][namespace].url ? `<Site url="${data.url || docs[category][namespace].url}" size="sm" />` : ''}\n\n`;
md[category] += `<Route namespace="${namespace}" :data='${JSON.stringify(data).replaceAll(`'`, '&#39;')}' :test='${JSON.stringify(parsedTest)}' />\n\n`;
md[category] += `<Route namespace="${namespace}" :data='${JSON.stringify(data).replaceAll(`'`, '&#39;')}' :test='${JSON.stringify(parsedTest)?.replaceAll(`'`, '&#39;')}' />\n\n`;
if (data.description) {
md[category] += `${data.description}\n\n`;
}
Expand Down

0 comments on commit d7db129

Please sign in to comment.