Skip to content

Commit 0ca4429

Browse files
authored
Merge pull request #275 from zetalpha/main
补充
2 parents 843220b + 032cf3b commit 0ca4429

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

src/renderer/src/locales/lang/zh_CN/pages/setting.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ export default {
475475
filterInfo: '详细',
476476
excludeKeys: '键移除',
477477
try: '执行',
478+
br:'批量结果',
478479
reg: '正则',
479480
plot: '剧情',
480481
area: '地区',

src/renderer/src/pages/setting/editSource/Sift.vue

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
:placeholder="$t('pages.setting.editSource.sift.placeholder.linkTip')" class="input w-100%" />
7272
<t-button block @click="actionClass">{{ $t('pages.setting.editSource.sift.rule.try') }}</t-button>
7373
</div>
74+
<div class="code-op-item card">
75+
<t-button block @click="batchResults">{{ $t('pages.setting.editSource.sift.rule.br') }}</t-button>
76+
</div>
7477
<div class="code-op-item card">
7578
<t-input v-model="form.filter" :label="$t('pages.setting.editSource.sift.rule.filter')"
7679
:placeholder="$t('pages.setting.editSource.sift.placeholder.filterTip')" class="input w-100%" />
@@ -144,6 +147,9 @@ import { t } from '@/locales';
144147
import { useSettingStore } from '@/store';
145148
import { getHtml, copyToClipboardApi, encodeGzip, encodeBtoa } from '@/utils/tool';
146149
import { getFilters, processCategories } from '@/utils/drpy/lab/hipyFilter';
150+
import axios from 'axios';
151+
import { json } from 'node:stream/consumers';
152+
147153
148154
const storeSetting = useSettingStore();
149155
@@ -402,7 +408,6 @@ const actionClass = () => {
402408
MessagePlugin.warning(t('pages.setting.editSource.sift.message.sourceFirst'));
403409
return;
404410
}
405-
406411
const response = processCategories(contentHtml, class_parse, cate_exclude, reurl, url);
407412
408413
const transformData = (data) => {
@@ -411,14 +416,80 @@ const actionClass = () => {
411416
412417
return titles.map((title, index) => ({
413418
title: title.trim(),
414-
value: ms[index].trim()
419+
id: ms[index].trim(),
420+
surl: form.value.reurl.replace("fyclass", ms[index].trim())
415421
}));
416422
}
417423
if (response?.title && response?.m) form.value.content.debug = transformData(response);
418424
changeNav('debug', 'class');
419425
};
420426
427+
428+
const batchResults = () => {
429+
let r = form.value.content.debug;
430+
//console.log(r);
431+
const { filterInfo = '', filter = '', matchs } = form.value;
432+
if (!(filterInfo && filter)) {
433+
MessagePlugin.warning(t('pages.setting.editSource.sift.message.inputNoFilterAndFilterInfo'));
434+
return;
435+
};
436+
// 调用batchFetch并处理结果
437+
batchFetch(r)
438+
.then(results => {
439+
let rs = {};
440+
results.map(item => {
441+
const newMatchs = {
442+
'剧情': matchs.plot,
443+
'地区': matchs.area,
444+
'语言': matchs.lang,
445+
'年份': matchs.year,
446+
'字母': matchs.letter,
447+
'排序': matchs.sort,
448+
}
449+
const response: any = getFilters(item.body, item.id, filter, filterInfo, newMatchs, '').filters;
450+
//console.log(response)
451+
if (response) {
452+
rs[item.id] = response;
453+
}
454+
})
455+
console.log(rs);
456+
form.value.content.debug = JSON.stringify(rs, null, 2);
457+
changeNav('debug', 'class');
458+
})
459+
.catch(error => {
460+
console.error('Failed to fetch data:', error);
461+
});
462+
};
463+
464+
465+
466+
467+
const batchFetch = async (obj) => {
468+
const promises = obj.map(x => {
469+
return axios.get(x.surl);
470+
});
471+
try {
472+
// 等待所有请求完成
473+
const responses = await Promise.all(promises);
474+
// 所有请求都成功后,提取结果数据并关联id
475+
const results = responses.map((response, index) => {
476+
console.log(index)
477+
const { id } = obj[index]; // 获取对应的id
478+
return {
479+
id: id,
480+
body: response.data // 假设响应体的数据在response.data中
481+
};
482+
});
483+
return results; // 返回结果数组
484+
} catch (error) {
485+
// 如果有任何一个请求失败,则捕捉错误
486+
console.error('There was an error with one of the requests:', error);
487+
throw error; // 抛出错误,以便调用者可以处理
488+
}
489+
};
490+
421491
const actionFilter = () => {
492+
console.log(form.value)
422493
const { filterInfo = '', filter = '', matchs } = form.value;
423494
const contentHtml = form.value.content.source;
424495
if (!(filterInfo && filter)) {

0 commit comments

Comments
 (0)