Skip to content

Commit

Permalink
Added Subscriptions URI path and custom fallback domain.
Browse files Browse the repository at this point in the history
  • Loading branch information
bia-pain-bache committed Jan 14, 2025
1 parent 80a379a commit d00cc03
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function handlePanel(request, env) {

export async function fallback(request) {
const url = new URL(request.url);
url.hostname = 'speed.cloudflare.com';
url.hostname = globalThis.fallbackDomain;
url.protocol = 'https:';
request = new Request(url, request);
return await fetch(request);
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function initializeParams(request, env) {
const proxyIPs = env.PROXYIP?.split(',').map(proxyIP => proxyIP.trim());
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
globalThis.panelVersion = '3';
globalThis.panelVersion = '3.0.1';
globalThis.defaultHttpPorts = ['80', '8080', '2052', '2082', '2086', '2095', '8880'];
globalThis.defaultHttpsPorts = ['443', '8443', '2053', '2083', '2087', '2096'];
globalThis.userID = env.UUID;
Expand All @@ -15,6 +15,8 @@ export function initializeParams(request, env) {
globalThis.client = searchParams.get('app');
globalThis.urlOrigin = url.origin;
globalThis.dohURL = env.DOH_URL || 'https://cloudflare-dns.com/dns-query';
globalThis.fallbackDomain = env.FALLBACK || 'speed.cloudflare.com';
globalThis.subPath = env.SUB_PATH || userID;
if (pathName !== '/secrets') {
if (!userID || !globalThis.TRPassword) throw new Error(`Please set UUID and Trojan password first. Please visit <a href="https://${hostName}/secrets" target="_blank">here</a> to generate them.`, { cause: "init"});
if (userID && !isValidUUID(userID)) throw new Error(`Invalid UUID: ${userID}`, { cause: "init"});
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export async function renderHomePage (proxySettings, isPassSet) {
</div>`).join('');

const subQR = (path, app, tag, title, sbType) => {
const url = `${sbType ? 'sing-box://import-remote-profile?url=' : ''}https://${globalThis.hostName}/${path}/${globalThis.userID}${app ? `?app=${app}` : ''}#${tag}`;
const url = `${sbType ? 'sing-box://import-remote-profile?url=' : ''}https://${globalThis.hostName}/${path}/${globalThis.subPath}${app ? `?app=${app}` : ''}#${tag}`;
return `
<button onclick="openQR('${url}', '${title}')" style="margin-bottom: 8px;">
QR Code&nbsp;<span class="material-symbols-outlined">qr_code</span>
</button>`;
};

const subURL = (path, app, tag) => {
const url = `https://${globalThis.hostName}/${path}/${globalThis.userID}${app ? `?app=${app}` : ''}#${tag}`;
const url = `https://${globalThis.hostName}/${path}/${globalThis.subPath}${app ? `?app=${app}` : ''}#${tag}`;
return `
<button onclick="copyToClipboard('${url}')">
Copy Sub<span class="material-symbols-outlined">format_list_bulleted</span>
Expand Down
6 changes: 3 additions & 3 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ export default {
case '/update-warp':
return await updateWarpConfigs(request, env);

case `/sub/${globalThis.userID}`:
case `/sub/${globalThis.subPath}`:
if (globalThis.client === 'sfa') return await getSingBoxCustomConfig(request, env, false);
if (globalThis.client === 'clash') return await getClashNormalConfig(request, env);
if (globalThis.client === 'xray') return await getXrayCustomConfigs(request, env, false);
return await getNormalConfigs(request, env);

case `/fragsub/${globalThis.userID}`:
case `/fragsub/${globalThis.subPath}`:
return globalThis.client === 'hiddify'
? await getSingBoxCustomConfig(request, env, true)
: await getXrayCustomConfigs(request, env, true);

case `/warpsub/${globalThis.userID}`:
case `/warpsub/${globalThis.subPath}`:
if (globalThis.client === 'clash') return await getClashWarpConfig(request, env);
if (globalThis.client === 'singbox' || globalThis.client === 'hiddify') return await getSingBoxWarpConfig(request, env, globalThis.client);
return await getXrayWarpConfigs(request, env, globalThis.client);
Expand Down

0 comments on commit d00cc03

Please sign in to comment.