feat: 优化流量解析规则

This commit is contained in:
xream 2024-01-20 23:00:37 +08:00
parent 9b6d9d49f9
commit e5c1ae9ed8
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 17 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.14.188", "version": "2.14.189",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

View File

@ -88,17 +88,27 @@ export async function getFlowHeaders(rawUrl, ua, timeout) {
export function parseFlowHeaders(flowHeaders) { export function parseFlowHeaders(flowHeaders) {
if (!flowHeaders) return; if (!flowHeaders) return;
// unit is KB // unit is KB
const uploadMatch = flowHeaders.match(/upload=(-?)([E+.\d]+)/); const uploadMatch = flowHeaders.match(
/upload=([-+]?)([0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)/,
);
const upload = Number(uploadMatch[1] + uploadMatch[2]); const upload = Number(uploadMatch[1] + uploadMatch[2]);
const downloadMatch = flowHeaders.match(/download=(-?)([E+.\d]+)/); const downloadMatch = flowHeaders.match(
/download=([-+]?)([0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)/,
);
const download = Number(downloadMatch[1] + downloadMatch[2]); const download = Number(downloadMatch[1] + downloadMatch[2]);
const totalMatch = flowHeaders.match(
const total = Number(flowHeaders.match(/total=([E+.\d]+)/)[1]); /total=([-+]?)([0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)/,
);
const total = Number(totalMatch[1] + totalMatch[2]);
// optional expire timestamp // optional expire timestamp
const match = flowHeaders.match(/expire=(\d+)/); const expireMatch = flowHeaders.match(
const expires = match ? Number(match[1]) : undefined; /expire=([-+]?)([0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)/,
);
const expires = expireMatch
? Number(expireMatch[1] + expireMatch[2])
: undefined;
return { expires, total, usage: { upload, download } }; return { expires, total, usage: { upload, download } };
} }