Skip to content

Commit

Permalink
feat: 订阅链接支持 showRemaining 参数, 此时将显示剩余流量而不是已用流量
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Mar 19, 2024
1 parent 7db8c5d commit a436f5f
Show file tree
Hide file tree
Showing 7 changed files with 12 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.201",
"version": "2.14.202",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down
6 changes: 3 additions & 3 deletions src/components/SubListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ const flow = computed(() => {
secondLine = secondLine ? `${secondLine} | ${expiresInfo}` : expiresInfo;
}
return {
firstLine: `${getString(upload + download, total, "B")}`,
firstLine: `${getString(target.showRemaining ? (total - upload - download) : (upload + download), total, "B")}`,
secondLine,
progress
};
Expand All @@ -359,8 +359,8 @@ const flow = computed(() => {
secondLine = secondLine ? `${secondLine} | ${expiresInfo}` : expiresInfo;
}
return {
firstLine: `${t("subPage.subItem.flow")}: ${getString(
upload + download,
firstLine: `${t(target.showRemaining ? "subPage.subItem.showRemainingFlow" : "subPage.subItem.flow")}: ${getString(
target.showRemaining ? (total - upload - download) : (upload + download),
total,
"B"
)}`,
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default {
local: 'Local subscription',
loading: 'Loading...',
flow: 'Usage / Total',
showRemainingFlow: 'Remaining / Total',
expires: 'Expires',
remainingDays: 'Remaining Reset Days',
remainingDaysUnit: '',
Expand Down Expand Up @@ -227,7 +228,7 @@ export default {
},
url: {
label: 'URL',
placeholder: 'Subscription URL (please separate multiple subscriptions with a new line). Supported parameters: validCheck - error will be reported when expired or there is no remaining traffic, flowUserAgent - the User-Agent for fetching subscription usage info, noFlow - do not query for flow, hideExpire - hide expiration time, noCache - do not use cache, resetDay - the day when monthly data usage resets, startDate - subscription start date, cycleDays - reset cycle (in days). For example: http://a.com?token=1#cycleDays=31&startDate=2024-06-04 or http://a.com?token=1#resetDay=15',
placeholder: 'Subscription URL (please separate multiple subscriptions with a new line). Supported parameters: validCheck - error will be reported when expired or there is no remaining traffic, flowUserAgent - the User-Agent for fetching subscription usage info, showRemaining - show remaining traffic instead of usage, noFlow - do not query for flow, hideExpire - hide expiration time, noCache - do not use cache, resetDay - the day when monthly data usage resets, startDate - subscription start date, cycleDays - reset cycle (in days). For example: http://a.com?token=1#cycleDays=31&startDate=2024-06-04 or http://a.com?token=1#resetDay=15',
isEmpty: 'URL cannot be empty',
isIllegal: 'Invalid URL',
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default {
local: '本地订阅',
loading: '加载中...',
flow: '已用/总流量',
showRemainingFlow: '剩余/总流量',
expires: '到期',
remainingDays: '重置',
remainingDaysUnit: ' 天',
Expand Down Expand Up @@ -227,7 +228,7 @@ export default {
},
url: {
label: '链接',
placeholder: '订阅链接(多个订阅请换行) 支持参数: validCheck 过期或无剩余流量时报错, flowUserAgent 查询流量时使用的 User-Agent, noFlow 不查询流量, hideExpire 隐藏到期, noCache 不使用缓存, resetDay 每月流量重置日, startDate 订阅开始日期, cycleDays 订阅重置周期(单位: 天). 例: http://a.com?token=1#cycleDays=31&startDate=2024-06-04 或 http://a.com?token=1#resetDay=15',
placeholder: '订阅链接(多个订阅请换行) 支持参数: validCheck 过期或无剩余流量时报错, flowUserAgent 查询流量时使用的 User-Agent, noFlow 不查询流量, hideExpire 隐藏到期, showRemaining 显示剩余流量而不是已用流量, noCache 不使用缓存, resetDay 每月流量重置日, startDate 订阅开始日期, cycleDays 订阅重置周期(单位: 天). 例: http://a.com?token=1#cycleDays=31&startDate=2024-06-04 或 http://a.com?token=1#resetDay=15',
isEmpty: '订阅链接不能为空',
isIllegal: '订阅链接格式非法',
},
Expand Down
4 changes: 2 additions & 2 deletions src/store/subs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export const useSubsStore = defineStore('subsStore', {
}
},
async fetchFlows(sub?: Sub[]) {
const asyncGetFlow = async ([url, name, noFlow, hideExpire]) => {
const asyncGetFlow = async ([url, name, noFlow, hideExpire, showRemaining]) => {
if (noFlow) {
this.flows[url] = { status:'noFlow' };
} else {
try {
const { data } = await subsApi.getFlow(name);
this.flows[url] = {...data, hideExpire };
this.flows[url] = {...data, hideExpire, showRemaining };
} catch (e) {
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types/store/subsStore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface Artifacts {

interface Flow {
status: 'success' | 'noFlow';
showRemaining?: boolean;
hideExpire?: boolean;
data: {
remainingDays?: number;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getFlowsUrlList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export const getFlowsUrlList = (subs: Sub[]): string[][] => {
}
}
}
return [raw, name, $arguments?.noFlow, $arguments?.hideExpire];
return [raw, name, $arguments?.noFlow, $arguments?.hideExpire, $arguments?.showRemaining];
});
};

0 comments on commit a436f5f

Please sign in to comment.