|
|
@@ -1322,7 +1322,59 @@ export async function GetWordChinese(ctx) {
|
|
1322
|
1322
|
ctx.body = { "errcode": 10000, result: selectedResult };
|
|
1323
|
1323
|
}
|
|
1324
|
1324
|
|
|
|
1325
|
+export async function GetWordDetail(ctx) {
|
|
|
1326
|
+ const param = {
|
|
|
1327
|
+ UserID: ctx.query.UserID || 0,
|
|
|
1328
|
+ Word: ctx.query.Word || ''
|
|
|
1329
|
+ };
|
|
|
1330
|
+
|
|
|
1331
|
+ if (!param.Word) {
|
|
|
1332
|
+ ctx.body = { "errcode": 10001, "errStr": "单词不能为空" };
|
|
|
1333
|
+ return;
|
|
|
1334
|
+ }
|
|
|
1335
|
+
|
|
|
1336
|
+ // 使用单词作为缓存键,为每个单词单独缓存结果
|
|
|
1337
|
+ const cacheKey = `GetWordDetail_${param.Word}`;
|
|
|
1338
|
+ let result = globalCache.get(cacheKey);
|
|
1325
|
1339
|
|
|
|
1340
|
+ if (!result) {
|
|
|
1341
|
+ // 缓存未命中,从数据库获取
|
|
|
1342
|
+ let url = "https://www.kylx365.com/api/GetMiaoguoAISearch2?Word=";
|
|
|
1343
|
+ const tokenurl=url + param.Word;
|
|
|
1344
|
+ result = await axios.get(tokenurl);
|
|
|
1345
|
+ result=result.data.result;
|
|
|
1346
|
+
|
|
|
1347
|
+ // 如果没有找到结果,尝试查找单词的原形
|
|
|
1348
|
+ if (!result || result.length === 0) {
|
|
|
1349
|
+ // 使用stringUtils.getWordBaseForm获取可能的原形
|
|
|
1350
|
+ const possibleBaseWords = stringUtils.getWordAllForms(param.Word);
|
|
|
1351
|
+
|
|
|
1352
|
+ // 尝试每个可能的原形
|
|
|
1353
|
+ for (const baseWord of possibleBaseWords) {
|
|
|
1354
|
+ //console.log(`尝试查找单词 ${param.Word} 的可能原形: ${baseWord}`);
|
|
|
1355
|
+ const baseParam = { ...param, Word: baseWord };
|
|
|
1356
|
+
|
|
|
1357
|
+ const tokenurl=url + baseParam;
|
|
|
1358
|
+ let baseResult = await axios.get(tokenurl);
|
|
|
1359
|
+ baseResult=baseResult.data.result;
|
|
|
1360
|
+
|
|
|
1361
|
+ if (baseResult && baseResult.length > 0) {
|
|
|
1362
|
+ //console.log(`找到单词 ${param.Word} 的原形 ${baseWord}`);
|
|
|
1363
|
+ result = baseResult;
|
|
|
1364
|
+ break;
|
|
|
1365
|
+ }
|
|
|
1366
|
+ }
|
|
|
1367
|
+ }
|
|
|
1368
|
+
|
|
|
1369
|
+ // 缓存结果,使用较长的过期时间,因为单词释义很少变化
|
|
|
1370
|
+ if (result && result.length > 0) {
|
|
|
1371
|
+ globalCache.set(cacheKey, result, config.BufferMemoryTimeHighBest);
|
|
|
1372
|
+ //console.log(`缓存单词 ${param.Word} 的释义,7天有效期`);
|
|
|
1373
|
+ }
|
|
|
1374
|
+ }
|
|
|
1375
|
+
|
|
|
1376
|
+ ctx.body = { "errcode": 10000, result: result };
|
|
|
1377
|
+}
|
|
1326
|
1378
|
export async function YJBDC_Articles_Admin(ctx) {
|
|
1327
|
1379
|
//console.log("yjbdc_articles");
|
|
1328
|
1380
|
const data = await fsPromises.readFile("./public/mg/yjbdc_articles.html");
|