Skip to content

Commit

Permalink
feat: support vless
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-jerry committed Nov 5, 2024
1 parent d397e5c commit e3fa42d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
41 changes: 30 additions & 11 deletions src/logic/v2fly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,28 @@ export interface V2rayConfOption {
* @returns
*/
export function getOutboundConfFromBase64(opt: V2rayConfOption): V4.outbounds.OutboundObject {
const [_protocol, conf] = opt.b64.split('://')
const [protocol, conf] = opt.b64.split('://')

const config: V2rayBase64 = JSON.parse(window.atob(conf))

const outbound: V4.outbounds.OutboundObject = {
protocol: 'vmess',
protocol,
streamSettings: {
wsSettings: {
path: config.path,
headers: {
host: config.host,
},
path: config.path + '?ed=2560',
},
tlsSettings: {
serverName: config.host,
fingerprint: 'chrome',
allowInsecure: false,
},
security: 'tls',
network: 'ws',
},
settings: {
}

if (protocol === 'vmess') {
outbound.settings = {
_t: 'vmess',
vnext: [
{
Expand All @@ -79,7 +80,25 @@ export function getOutboundConfFromBase64(opt: V2rayConfOption): V4.outbounds.Ou
],
},
],
},
}
}

if (protocol === 'vless') {
outbound.settings = {
_t: 'vless',
vnext: [
{
address: config.add,
port: config.port,
users: [
{
id: config.id,
encryption: 'none',
},
],
},
],
}
}

if (opt.mux) {
Expand All @@ -94,9 +113,9 @@ export function getOutboundConfFromBase64(opt: V2rayConfOption): V4.outbounds.Ou

// ----------

export async function getLogConf(): Promise<V4.overview.LogObject> {
export function getLogConf(): V4.overview.LogObject {
return {
loglevel: 'warning',
loglevel: 'debug',
}
}

Expand Down Expand Up @@ -234,7 +253,7 @@ export async function getV2rayConfig(
}

return {
log: await getLogConf(),
log: getLogConf(),
inbounds,
outbounds: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index/server.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function getLabel(itemConf: string) {
const item: V4.outbounds.OutboundObject = JSON.parse(itemConf)
const protocol = item.protocol
if (protocol === 'vmess') {
if (protocol === 'vmess' || protocol === 'vless') {
const address = item.settings?.vnext?.[0].address
const port = item.settings?.vnext?.[0].port
Expand Down

0 comments on commit e3fa42d

Please sign in to comment.