yuanjiajun commited on
Commit ·
c13766b
1
Parent(s): 22ae2e3
测试
Browse files- .vscode/extensions.json +3 -0
- .vscode/settings.json +12 -0
- src/service/article-service.ts +9 -10
.vscode/extensions.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"recommendations": ["dbaeumer.vscode-eslint"]
|
| 3 |
+
}
|
.vscode/settings.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"prettier.enable": true,
|
| 3 |
+
"eslint.enable": true,
|
| 4 |
+
"editor.codeActionsOnSave": {
|
| 5 |
+
"source.fixAll.eslint": "explicit"
|
| 6 |
+
},
|
| 7 |
+
"eslint.workingDirectories": [
|
| 8 |
+
{
|
| 9 |
+
"mode": "auto"
|
| 10 |
+
}
|
| 11 |
+
]
|
| 12 |
+
}
|
src/service/article-service.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import axios from 'axios';
|
| 2 |
import fs from 'fs';
|
| 3 |
import htmlDocx from 'html-docx-js';
|
| 4 |
import path from 'path';
|
|
@@ -7,13 +6,13 @@ import { delay, getImageBuffer, getSummaryText, getTranslatedText } from '@/util
|
|
| 7 |
|
| 8 |
const uploadDir = path.join(__dirname, '../../uploads');
|
| 9 |
|
| 10 |
-
async function getImageBufferByText(text: string, apiKey:string) {
|
| 11 |
-
// 使用axios以async/await形式调用API接口生成图片
|
| 12 |
-
const translatedText = await getTranslatedText(text, apiKey);
|
| 13 |
-
const summaryText = await getSummaryText(translatedText, apiKey);
|
| 14 |
-
console.log(summaryText);
|
| 15 |
-
// 使用axios以async/await形式调用API接口生成图片
|
| 16 |
-
const buffer = await getImageBuffer(summaryText, apiKey);
|
| 17 |
return buffer;
|
| 18 |
}
|
| 19 |
|
|
@@ -27,7 +26,7 @@ export const processArticleServe = async (data: { title: string; content: string
|
|
| 27 |
|
| 28 |
// 预热
|
| 29 |
try {
|
| 30 |
-
|
| 31 |
} catch (error) {}
|
| 32 |
|
| 33 |
// 遍历段落,根据段落内容调用接口生成图片并插入到HTML中
|
|
@@ -40,7 +39,7 @@ export const processArticleServe = async (data: { title: string; content: string
|
|
| 40 |
try {
|
| 41 |
// 如果是文章开头(i === 0)或者符合每两或三个段落插入图片的规则(且不在最后两段内)
|
| 42 |
if (i === 0 || (i % 3 === 0 && i <= paragraphs.length - 2)) {
|
| 43 |
-
const buffer = await getImageBufferByText(description, config.hfApiKey)
|
| 44 |
|
| 45 |
const outputFilename = `image-${Date.now()}.jpg`;
|
| 46 |
const outputPath = path.join(uploadDir, outputFilename);
|
|
|
|
|
|
|
| 1 |
import fs from 'fs';
|
| 2 |
import htmlDocx from 'html-docx-js';
|
| 3 |
import path from 'path';
|
|
|
|
| 6 |
|
| 7 |
const uploadDir = path.join(__dirname, '../../uploads');
|
| 8 |
|
| 9 |
+
async function getImageBufferByText(text: string, apiKey: string) {
|
| 10 |
+
// 使用axios以async/await形式调用API接口生成图片
|
| 11 |
+
const translatedText = await getTranslatedText(text, apiKey);
|
| 12 |
+
const summaryText = await getSummaryText(translatedText, apiKey);
|
| 13 |
+
console.log(summaryText);
|
| 14 |
+
// 使用axios以async/await形式调用API接口生成图片
|
| 15 |
+
const buffer = await getImageBuffer(summaryText, apiKey);
|
| 16 |
return buffer;
|
| 17 |
}
|
| 18 |
|
|
|
|
| 26 |
|
| 27 |
// 预热
|
| 28 |
try {
|
| 29 |
+
await getImageBufferByText('预热', config.hfApiKey);
|
| 30 |
} catch (error) {}
|
| 31 |
|
| 32 |
// 遍历段落,根据段落内容调用接口生成图片并插入到HTML中
|
|
|
|
| 39 |
try {
|
| 40 |
// 如果是文章开头(i === 0)或者符合每两或三个段落插入图片的规则(且不在最后两段内)
|
| 41 |
if (i === 0 || (i % 3 === 0 && i <= paragraphs.length - 2)) {
|
| 42 |
+
const buffer = await getImageBufferByText(description, config.hfApiKey);
|
| 43 |
|
| 44 |
const outputFilename = `image-${Date.now()}.jpg`;
|
| 45 |
const outputPath = path.join(uploadDir, outputFilename);
|