Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(www): support server name on dynamic keys #1483

Merged
merged 8 commits into from
Nov 30, 2022
15 changes: 12 additions & 3 deletions src/www/app/outline_server_repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ function isDynamicAccessKey(accessKey: string): boolean {
// NOTE: For extracting a name that the user has explicitly set, only.
// (Currenly done by setting the hash on the URI)
function serverNameFromAccessKey(accessKey: string): string {
if (isDynamicAccessKey(accessKey)) {
return new URL(accessKey.replace(/^ssconf:\/\//, 'https://')).hostname;
const {hostname, hash} = new URL(accessKey.replace(/^ss(?:conf)?:\/\//, 'https://'));

let result;
if (hash && hash !== '#') {
// locates the first key-value pair in the search params-compliant
// string that has no value (i.e. thing=a&My%20Server%20Name&thing=b)
const {groups} = hash.slice(1).match(/(?:^|&)(?<name>[^=]+)(?:&|$)/);

result = groups?.name;
}

return SHADOWSOCKS_URI.parse(accessKey).tag.data;
result ??= hostname;

return decodeURIComponent(result);
}

// DEPRECATED: V0 server persistence format.
Expand Down