Skip to content

Commit

Permalink
feat: 设置 noFlow 的订阅在前端也不发起查询请求
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 19, 2024
1 parent 0434354 commit ab59213
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store-front-end",
"version": "2.14.84",
"version": "2.14.85",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down
7 changes: 6 additions & 1 deletion src/components/SubListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,12 @@
};
}
if (target.status === 'success') {
if (target.status === 'noFlow') {
return {
firstLine: t('subPage.subItem.noFlow'),
secondLine: ``,
};
} else if (target.status === 'success') {
const {
expires,
total,
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default {
flow: 'Usage / Total',
expires: 'Expires',
noRecord: 'Refresh to get usage',
noFlow: 'No flow',
noFlowInfo: 'No flow info',
noExpiresInfo: 'No expires info',
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default {
flow: '已用/总流量',
expires: '到期时间',
noRecord: '刷新后可获取流量情况',
noFlow: '不查询流量',
noFlowInfo: '无流量信息',
noExpiresInfo: '无有效期信息',
},
Expand Down
10 changes: 7 additions & 3 deletions src/store/subs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ export const useSubsStore = defineStore('subsStore', {
}
},
async fetchFlows(sub?: Sub[]) {
const asyncGetFlow = async ([url, name]) => {
const { data } = await subsApi.getFlow(name);
this.flows[url] = data;
const asyncGetFlow = async ([url, name, noFlow]) => {
if (noFlow) {
this.flows[url] = { status:'noFlow' };
} else {
const { data } = await subsApi.getFlow(name);
this.flows[url] = data;
}
};
// const subs = sub || this.subs;
// getFlowsUrlList(subs).forEach(asyncGetFlow);
Expand Down
2 changes: 1 addition & 1 deletion src/types/store/subsStore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface Artifacts {
}

interface Flow {
status: 'success';
status: 'success' | 'noFlow';
data: {
expires: number;
total: number;
Expand Down
31 changes: 28 additions & 3 deletions src/utils/getFlowsUrlList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,36 @@ export const getFlowsUrlList = (subs: Sub[]): string[][] => {
const urlList = [];

subs.forEach(sub => {

if (!urlList.includes(sub.url) && sub.source === 'remote') {
if (!urlList.includes(sub.url) && sub.source === 'remote' && sub.url) {
urlList.push(sub.url);
nameList.push([sub.url, sub.name]);
}
});
return nameList;
return nameList.map(([raw, name]) => {
let url = `${raw}`
.split(/[\r\n]+/)
.map((i) => i.trim())
.filter((i) => i.length)?.[0]

let $arguments = {} as any;
const rawArgs = url.split('#');
url = url.split('#')[0];
if (rawArgs.length > 1) {
try {
// 支持 `#${encodeURIComponent(JSON.stringify({arg1: "1"}))}`
$arguments = JSON.parse(decodeURIComponent(rawArgs[1]));
} catch (e) {
for (const pair of rawArgs[1].split('&')) {
const key = pair.split('=')[0];
const value = pair.split('=')[1];
// 部分兼容之前的逻辑 const value = pair.split('=')[1] || true;
$arguments[key] =
value == null || value === ''
? true
: decodeURIComponent(value);
}
}
}
return [raw, name, $arguments?.noFlow];
});
};

0 comments on commit ab59213

Please sign in to comment.