mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-07-04 06:09:19 +00:00
浏览器截图工具
This commit is contained in:
parent
6f94537295
commit
7942c59a32
0
apps/rssPush.js
Normal file
0
apps/rssPush.js
Normal file
@ -9,6 +9,13 @@
|
|||||||
"wsReConnectInterval": "5000",
|
"wsReConnectInterval": "5000",
|
||||||
"token": ""
|
"token": ""
|
||||||
},
|
},
|
||||||
|
"feeds": [
|
||||||
|
{
|
||||||
|
"url": "",
|
||||||
|
"targetGroups": [114,154],
|
||||||
|
"screenshot": true
|
||||||
|
}
|
||||||
|
],
|
||||||
"fanqieConfig": {
|
"fanqieConfig": {
|
||||||
"url": "http://127.0.0.1:6868",
|
"url": "http://127.0.0.1:6868",
|
||||||
"outDir": "/home/user/debian/cache/Downloads"
|
"outDir": "/home/user/debian/cache/Downloads"
|
||||||
|
@ -19,6 +19,7 @@ const Path = {
|
|||||||
pkg: path.join(rootDir, 'package.json'),
|
pkg: path.join(rootDir, 'package.json'),
|
||||||
yunzai: path.join(rootDir, '../../'),
|
yunzai: path.join(rootDir, '../../'),
|
||||||
data: path.join(rootDir, '../../data/crystelf/data'),
|
data: path.join(rootDir, '../../data/crystelf/data'),
|
||||||
|
rssHTML: path.join(rootDir, 'constants/rss/rss_template.html'),
|
||||||
};
|
};
|
||||||
|
|
||||||
const configFile = fs.readFileSync(Path.defaultConfig, 'utf8');
|
const configFile = fs.readFileSync(Path.defaultConfig, 'utf8');
|
||||||
|
43
constants/rss/rss_template.html
Normal file
43
constants/rss/rss_template.html
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<!-- TODO 美观html -->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: '微软雅黑', sans-serif;
|
||||||
|
background: #f9f9f9;
|
||||||
|
padding: 40px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: auto;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 4px 16px rgba(0,0,0,0.1);
|
||||||
|
padding: 30px;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 22px;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #1e90ff;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="card">
|
||||||
|
<h1>{{title}}</h1>
|
||||||
|
<p>{{description}}</p>
|
||||||
|
<p><a href="{{link}}">{{link}}</a></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
34
lib/rss/screenshot.js
Normal file
34
lib/rss/screenshot.js
Normal file
@ -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<string>} 图片所在目录
|
||||||
|
*/
|
||||||
|
// 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;
|
@ -20,6 +20,7 @@
|
|||||||
"chalk": "^5.4.1",
|
"chalk": "^5.4.1",
|
||||||
"form-data": "^4.0.2",
|
"form-data": "^4.0.2",
|
||||||
"openai": "^4.89.0",
|
"openai": "^4.89.0",
|
||||||
|
"rss-parser": "^3.13.0",
|
||||||
"ws": "^8.18.1"
|
"ws": "^8.18.1"
|
||||||
},
|
},
|
||||||
"imports": {},
|
"imports": {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user