Skip to content

Commit

Permalink
feat: 订阅支持每月重置天数
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Mar 10, 2024
1 parent 078bf22 commit 518de2e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/core/proxy-utils/processors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
parseFlowHeaders,
validCheck,
flowTransfer,
getRmainingDays,
} from '@/utils/flow';

/**
Expand Down Expand Up @@ -863,6 +864,7 @@ function createDynamicFunction(name, script, $arguments) {
parseFlowHeaders,
flowTransfer,
validCheck,
getRmainingDays,
};
if ($.env.isLoon) {
return new Function(
Expand Down
12 changes: 9 additions & 3 deletions backend/src/restful/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions backend/src/utils/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 518de2e

Please sign in to comment.