Skip to content

Commit

Permalink
feat: 默认输出格式改为 V2Ray; accept 为 application/json 时, 输出 JSON; 响应增加 X-Po…
Browse files Browse the repository at this point in the history
…wered-By Sub-Store
  • Loading branch information
xream committed Nov 19, 2024
1 parent bc1247e commit 7d8132d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 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.422",
"version": "2.14.423",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
24 changes: 11 additions & 13 deletions backend/src/utils/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ import $ from '@/core/app';
import headersResourceCache from '@/utils/headers-resource-cache';

export function getFlowField(headers) {
let subKey = '';
let webPageKey = '';

Object.keys(headers).some((k) => {
if (/SUBSCRIPTION-USERINFO/i.test(k)) {
subKey = k;
} else if (/PROFILE-WEB-PAGE-URL/i.test(k)) {
webPageKey = k;
const keys = Object.keys(headers);
let sub = '';
let webPage = '';
for (let k of keys) {
const lower = k.toLowerCase();
if (lower === 'subscription-userinfo') {
sub = headers[k];
} else if (lower === 'profile-web-page-url') {
webPage = headers[k];
}
return subKey && webPageKey;
});
}

return `${headers[subKey] || ''}${
webPageKey ? `;app_url=${headers[webPageKey]}` : ''
}`;
return `${sub || ''}${webPage ? `;app_url=${webPage}` : ''}`;
}
export async function getFlowHeaders(
rawUrl,
Expand Down
23 changes: 15 additions & 8 deletions backend/src/utils/user-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ export function getUserAgentFromHeaders(headers) {
const keys = Object.keys(headers);
let UA = '';
let ua = '';
let accept = '';
for (let k of keys) {
if (/USER-AGENT/i.test(k)) {
const lower = k.toLowerCase();
if (lower === 'user-agent') {
UA = headers[k];
ua = UA.toLowerCase();
break;
} else if (lower === 'accept') {
accept = headers[k];
}
}
return { UA, ua };
return { UA, ua, accept };
}
export function getPlatformFromUserAgent({ ua, UA }) {

export function getPlatformFromUserAgent({ ua, UA, accept }) {
if (UA.indexOf('Quantumult%20X') !== -1) {
return 'QX';
} else if (UA.indexOf('Surfboard') !== -1) {
Expand All @@ -35,15 +39,18 @@ export function getPlatformFromUserAgent({ ua, UA }) {
return 'ClashMeta';
} else if (ua.indexOf('clash') !== -1) {
return 'Clash';
} else if (ua.indexOf('v2ray') !== -1) {
} else if (ua.indexOf('v2ray') !== -1 || ua.indexOf('egern') !== -1) {
return 'V2Ray';
} else if (ua.indexOf('sing-box') !== -1) {
return 'sing-box';
} else {
} else if (accept.indexOf('application/json') === 0) {
return 'JSON';
} else {
return 'V2Ray';
}
}

export function getPlatformFromHeaders(headers) {
const { UA, ua } = getUserAgentFromHeaders(headers);
return getPlatformFromUserAgent({ ua, UA });
const { UA, ua, accept } = getUserAgentFromHeaders(headers);
return getPlatformFromUserAgent({ ua, UA, accept });
}
1 change: 1 addition & 0 deletions backend/src/vendor/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function express({ substore: $, port, host }) {
'Access-Control-Allow-Methods': 'POST,GET,OPTIONS,PATCH,PUT,DELETE',
'Access-Control-Allow-Headers':
'Origin, X-Requested-With, Content-Type, Accept',
'X-Powered-By': 'Sub-Store',
};

// node support
Expand Down

0 comments on commit 7d8132d

Please sign in to comment.