Skip to content

Commit

Permalink
refactor(ss): handle non-ss type
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 1, 2024
1 parent 4a23e08 commit ab7bf9d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import * as atom from '../utils/atom';

export function decodeOne(sip002: string): ShadowSocksConfig {
// ss://YWVzLTEyOC1nY206YzMxNWFhOGMtNGU1NC00MGRjLWJkYzctYzFjMjEwZjIxYTNi@ss1.meslink.xyz:10009#%F0%9F%87%AD%F0%9F%87%B0%20HK1%20HKT
const [_type, payload] = sip002.split('://');
const [type, payload] = sip002.split('://');

if (type !== 'ss') {
throw new Error(`[ss.decodeOne] Unsupported type: ${type}`);
}

const [userInfo, server] = payload.split('@');

Expand Down Expand Up @@ -32,7 +36,10 @@ export function decodeOne(sip002: string): ShadowSocksConfig {
} satisfies ShadowSocksConfig;
}

export function decodeBase64Multiline(text: string): string[] {
return atob(text).replaceAll('\r\n', '\n').split('\n').filter(Boolean);
}

export function decodeMultiline(text: string): ShadowSocksConfig[] {
const lines = atob(text).replaceAll('\r\n', '\n').split('\n');
return lines.filter(Boolean).map((line) => decodeOne(line));
return decodeBase64Multiline(text).map((line) => decodeOne(line));
}

0 comments on commit ab7bf9d

Please sign in to comment.