|
|
@@ -13,6 +13,8 @@ import yjbdc from '../../model/yjbdc.js';
|
|
13
|
13
|
import PDFDocument from 'pdfkit';
|
|
14
|
14
|
import tencentcloud from 'tencentcloud-sdk-nodejs-ocr';
|
|
15
|
15
|
|
|
|
16
|
+const ONE_DAY_MAX_BUILD_COUNT=12;//一天最大生成数
|
|
|
17
|
+
|
|
16
|
18
|
const OcrClient = tencentcloud.ocr.v20181119.Client;
|
|
17
|
19
|
const headers = {
|
|
18
|
20
|
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36',
|
|
|
@@ -254,26 +256,31 @@ export async function GenerateArticle(ctx) {
|
|
254
|
256
|
"content": content,
|
|
255
|
257
|
}
|
|
256
|
258
|
]};
|
|
257
|
|
- const response = await axios.post(encodeURI(url), postJSON, { headers });
|
|
258
|
|
- //console.log("parsedBody:" + JSON.stringify(response.data.choices[0].message.content));
|
|
259
|
|
-
|
|
260
|
|
- let result2=response.data.choices[0].message.content;
|
|
261
|
|
- let param2={};
|
|
262
|
|
- param2.UserID=ctx.query.UserID;
|
|
263
|
|
- param2.CreateTime=moment().format('YYYY-MM-DD HH:mm:ss');
|
|
264
|
|
- param2.Words=words;
|
|
265
|
|
- param2.Level=params.Level;
|
|
266
|
|
- param2.articleStyle=params.ArticleStyle;
|
|
267
|
|
- param2.BuildStr=content;
|
|
268
|
|
- param2.ArticleStart=JSON.parse(result2).ArticleEnglish[0];
|
|
269
|
|
- // 去除JSON字符串中的所有换行符(\r\n, \n, \r)
|
|
270
|
|
- param2.JSONString=JSON.stringify(result2.replace(/[\r\n]+/g, ''));
|
|
271
|
|
- param2.Flag=0;
|
|
272
|
|
- await yjbdc.AddArticleInfo(param2);
|
|
273
|
|
-
|
|
274
|
|
- result = { errcode: 10000, result: result2 };
|
|
275
|
|
- globalCache.set(url, result, config.BufferMemoryTime);
|
|
276
|
|
- console.log("缓存60秒");
|
|
|
259
|
+ try{
|
|
|
260
|
+ const response = await axios.post(encodeURI(url), postJSON, { headers });
|
|
|
261
|
+ console.log("parsedBody:" + JSON.stringify(response.data.choices[0].message.content));
|
|
|
262
|
+
|
|
|
263
|
+ let result2=response.data.choices[0].message.content;
|
|
|
264
|
+ let param2={};
|
|
|
265
|
+ param2.UserID=ctx.query.UserID;
|
|
|
266
|
+ param2.CreateTime=moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
267
|
+ param2.Words=words;
|
|
|
268
|
+ param2.Level=params.Level;
|
|
|
269
|
+ param2.articleStyle=params.ArticleStyle;
|
|
|
270
|
+ param2.BuildStr=content;
|
|
|
271
|
+ param2.ArticleStart=JSON.parse(result2).ArticleEnglish[0];
|
|
|
272
|
+ // 去除JSON字符串中的所有换行符(\r\n, \n, \r)
|
|
|
273
|
+ param2.JSONString=JSON.stringify(result2.replace(/[\r\n]+/g, ''));
|
|
|
274
|
+ param2.Flag=0;
|
|
|
275
|
+ await yjbdc.AddArticleInfo(param2);
|
|
|
276
|
+
|
|
|
277
|
+ result = { errcode: 10000, result: result2 };
|
|
|
278
|
+ globalCache.set(url, result, config.BufferMemoryTime);
|
|
|
279
|
+ console.log("缓存60秒");
|
|
|
280
|
+ }
|
|
|
281
|
+ catch(err){
|
|
|
282
|
+ result = { errcode: 10000, result: "-1" };
|
|
|
283
|
+ }
|
|
277
|
284
|
}
|
|
278
|
285
|
|
|
279
|
286
|
ctx.body = result;
|
|
|
@@ -295,7 +302,8 @@ export async function GetYJBDCArticleList(ctx) {
|
|
295
|
302
|
for(let i=0;i<result.length;i++){
|
|
296
|
303
|
let item=result[i];
|
|
297
|
304
|
item.CreateTime=moment(item.CreateTime).format("YYYY年MM月DD日 HH:mm");
|
|
298
|
|
- switch (item.Level){
|
|
|
305
|
+ //debugger;
|
|
|
306
|
+ switch (Number(item.Level)){
|
|
299
|
307
|
case 0:
|
|
300
|
308
|
item.LevelStr="小学";
|
|
301
|
309
|
break;
|
|
|
@@ -323,9 +331,14 @@ export async function GetYJBDCArticleList(ctx) {
|
|
323
|
331
|
if (result[i].CreateTime>=today)
|
|
324
|
332
|
count++;
|
|
325
|
333
|
}
|
|
|
334
|
+
|
|
|
335
|
+ let maxcount=ONE_DAY_MAX_BUILD_COUNT;
|
|
|
336
|
+ if (param.UserID<4){
|
|
|
337
|
+ maxcount=100;
|
|
|
338
|
+ }
|
|
326
|
339
|
result={
|
|
327
|
340
|
TodayCount:count,
|
|
328
|
|
- MaxCount:12,
|
|
|
341
|
+ MaxCount:maxcount,
|
|
329
|
342
|
};
|
|
330
|
343
|
}
|
|
331
|
344
|
|