From 518de2e919fd2845a8f80a6d92f25c80bc8a7763 Mon Sep 17 00:00:00 2001 From: xream Date: Sun, 10 Mar 2024 23:08:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A2=E9=98=85=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=AF=8F=E6=9C=88=E9=87=8D=E7=BD=AE=E5=A4=A9=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../src/core/proxy-utils/processors/index.js | 2 ++ backend/src/restful/subscriptions.js | 12 ++++++++--- backend/src/utils/flow.js | 20 +++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/backend/package.json b/backend/package.json index b83f9a7..48e5e54 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.245", + "version": "2.14.246", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/processors/index.js b/backend/src/core/proxy-utils/processors/index.js index a8c6d27..eee74a2 100644 --- a/backend/src/core/proxy-utils/processors/index.js +++ b/backend/src/core/proxy-utils/processors/index.js @@ -16,6 +16,7 @@ import { parseFlowHeaders, validCheck, flowTransfer, + getRmainingDays, } from '@/utils/flow'; /** @@ -863,6 +864,7 @@ function createDynamicFunction(name, script, $arguments) { parseFlowHeaders, flowTransfer, validCheck, + getRmainingDays, }; if ($.env.isLoon) { return new Function( diff --git a/backend/src/restful/subscriptions.js b/backend/src/restful/subscriptions.js index a798e7b..4861882 100644 --- a/backend/src/restful/subscriptions.js +++ b/backend/src/restful/subscriptions.js @@ -6,7 +6,11 @@ import { } from './errors'; import { deleteByName, findByName, updateByName } from '@/utils/database'; import { SUBS_KEY, COLLECTIONS_KEY, ARTIFACTS_KEY } from '@/constants'; -import { getFlowHeaders, parseFlowHeaders } from '@/utils/flow'; +import { + getFlowHeaders, + parseFlowHeaders, + getRmainingDays, +} from '@/utils/flow'; import { success, failed } from './response'; import $ from '@/core/app'; @@ -105,8 +109,10 @@ async function getFlowInfo(req, res) { ); return; } - - success(res, parseFlowHeaders(flowHeaders)); + success(res, { + ...parseFlowHeaders(flowHeaders), + remainingDays: getRmainingDays($arguments.resetDay), + }); } catch (err) { failed( res, diff --git a/backend/src/utils/flow.js b/backend/src/utils/flow.js index 8c8116a..12fc6e4 100644 --- a/backend/src/utils/flow.js +++ b/backend/src/utils/flow.js @@ -143,3 +143,23 @@ export function validCheck(flow) { } } } + +export function getRmainingDays(_resetDay) { + if (!_resetDay) return; + const resetDay = parseInt(_resetDay); + if (isNaN(resetDay) || resetDay <= 0 || resetDay > 31) return; + + let now = new Date(); + let today = now.getDate(); + let month = now.getMonth(); + let year = now.getFullYear(); + let daysInMonth; + + if (resetDay > today) { + daysInMonth = 0; + } else { + daysInMonth = new Date(year, month + 1, 0).getDate(); + } + + return daysInMonth - today + resetDay; +}