Skip to content

Commit

Permalink
feat: remove internal relay service
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Nov 4, 2023
1 parent 2432923 commit 88227d0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/constant/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ export const CATEGORIES = {
SURFBOARD: 'Surfboard',
} as const

export const RELAY_SERVICE = 'https://surgio-cors.herokuapp.com/'

export const TMP_FOLDER_NAME = 'surgio-config'

export const CACHE_KEYS = {
Expand Down
18 changes: 14 additions & 4 deletions src/provider/__tests__/ClashProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import nock from 'nock'
import sinon from 'sinon'

import { NodeTypeEnum, SupportProviderEnum } from '../../types'
import { RELAY_SERVICE } from '../../constant'
import ClashProvider, {
getClashSubscription,
parseClashConfig,
Expand Down Expand Up @@ -578,13 +577,24 @@ test('shadowsocks v2ray mux', async (t) => {
})

test('ClashProvider relayUrl', async (t) => {
const provider = new ClashProvider('test', {
const provider1 = new ClashProvider('test', {
type: SupportProviderEnum.Clash,
url: 'http://example.com/clash-sample.yaml',
relayUrl: true,
relayUrl: 'http://relay.com/%URL%',
})

t.is(provider.url, `${RELAY_SERVICE}http://example.com/clash-sample.yaml`)
t.is(provider1.url, `http://relay.com/http://example.com/clash-sample.yaml`)

const provider2 = new ClashProvider('test', {
type: SupportProviderEnum.Clash,
url: 'http://example.com/clash-sample.yaml',
relayUrl: 'http://relay.com/%%URL%%',
})

t.is(
provider2.url,
`http://relay.com/http%3A%2F%2Fexample.com%2Fclash-sample.yaml`,
)
})

test.serial('ClashProvider requestUserAgent', async (t) => {
Expand Down
4 changes: 0 additions & 4 deletions src/utils/__tests__/relayable-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import test from 'ava'
import relayableUrl from '../relayable-url'

test('relayableUrl', (t) => {
t.is(
relayableUrl('http://example.com', true),
'https://surgio-cors.herokuapp.com/http://example.com',
)
t.is(
relayableUrl('http://example.com', 'http://proxy.example.com/%URL%'),
'http://proxy.example.com/http://example.com',
Expand Down
11 changes: 2 additions & 9 deletions src/utils/relayable-url.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { RELAY_SERVICE } from '../constant'

export default function relayableUrl(
url: string,
relayUrl?: boolean | string,
): string {
if (typeof relayUrl === 'boolean') {
return `${RELAY_SERVICE}${url}`
} else if (typeof relayUrl === 'string') {
export default function relayableUrl(url: string, relayUrl?: string): string {
if (typeof relayUrl === 'string') {
if (relayUrl.includes('%%URL%%')) {
return relayUrl.replace('%%URL%%', encodeURIComponent(url))
} else if (relayUrl.includes('%URL%')) {
Expand Down
2 changes: 1 addition & 1 deletion src/validators/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ProviderValidator = z.object({
tfo: z.oboolean(),
underlyingProxy: z.ostring(),
startPort: z.number().min(1024).max(65535).optional(),
relayUrl: z.union([z.boolean(), z.string().url()]).optional(),
relayUrl: z.string().url().optional(),
requestUserAgent: z.ostring(),
renameNode: z
.function()
Expand Down

0 comments on commit 88227d0

Please sign in to comment.