From 7942c59a322e30a606d60cc15719b8eefada8d2c Mon Sep 17 00:00:00 2001 From: Jerry Date: Thu, 15 May 2025 13:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rssPush.js | 0 config/default.json | 7 ++++++ constants/path.js | 1 + constants/rss/rss_template.html | 43 +++++++++++++++++++++++++++++++++ lib/rss/screenshot.js | 34 ++++++++++++++++++++++++++ package.json | 1 + 6 files changed, 86 insertions(+) create mode 100644 apps/rssPush.js create mode 100644 constants/rss/rss_template.html create mode 100644 lib/rss/screenshot.js diff --git a/apps/rssPush.js b/apps/rssPush.js new file mode 100644 index 0000000..e69de29 diff --git a/config/default.json b/config/default.json index a4201c9..3b49ad8 100644 --- a/config/default.json +++ b/config/default.json @@ -9,6 +9,13 @@ "wsReConnectInterval": "5000", "token": "" }, + "feeds": [ + { + "url": "", + "targetGroups": [114,154], + "screenshot": true + } + ], "fanqieConfig": { "url": "http://127.0.0.1:6868", "outDir": "/home/user/debian/cache/Downloads" diff --git a/constants/path.js b/constants/path.js index c6ee14d..4e2ad4f 100644 --- a/constants/path.js +++ b/constants/path.js @@ -19,6 +19,7 @@ const Path = { pkg: path.join(rootDir, 'package.json'), yunzai: path.join(rootDir, '../../'), data: path.join(rootDir, '../../data/crystelf/data'), + rssHTML: path.join(rootDir, 'constants/rss/rss_template.html'), }; const configFile = fs.readFileSync(Path.defaultConfig, 'utf8'); diff --git a/constants/rss/rss_template.html b/constants/rss/rss_template.html new file mode 100644 index 0000000..235fe92 --- /dev/null +++ b/constants/rss/rss_template.html @@ -0,0 +1,43 @@ + + + + + + + + +
+

{{title}}

+

{{description}}

+

{{link}}

+
+ + diff --git a/lib/rss/screenshot.js b/lib/rss/screenshot.js new file mode 100644 index 0000000..3d06b03 --- /dev/null +++ b/lib/rss/screenshot.js @@ -0,0 +1,34 @@ +import fs from 'fs'; +import paths from './../../constants/path.js'; +import puppeteer from 'puppeteer'; + +const screenshot = { + /** + * 调用浏览器截图 + * @param title 标题 + * @param link 链接 + * @param description 描述 + * @returns {Promise} 图片所在目录 + */ + // TODO 待优化 + async rssScreenshot(title, link, description = '') { + const templatePath = paths.rssHTML; + let html = fs.readFileSync(templatePath, 'utf8'); + + html = html + .replace('{{title}}', title || '') + .replace('{{link}}', link || '') + .replace('{{description}}', description || ''); + + const browser = await puppeteer.launch({ args: ['--no-sandbox'] }); + const page = await browser.newPage(); + await page.setContent(html, { waitUntil: 'networkidle0' }); + + const imagePath = `/tmp/rss_card_${Date.now()}.png`; + await page.screenshot({ path: imagePath }); + await browser.close(); + return imagePath; + }, +}; + +export default screenshot; diff --git a/package.json b/package.json index c561884..9ef5b98 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "chalk": "^5.4.1", "form-data": "^4.0.2", "openai": "^4.89.0", + "rss-parser": "^3.13.0", "ws": "^8.18.1" }, "imports": {},