Skip to content

Commit

Permalink
I think that's it
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse committed Mar 7, 2024
1 parent bbd510b commit 1234265
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 41 deletions.
7 changes: 0 additions & 7 deletions src/www/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,6 @@ export class App {
connectionState: ServerConnectionState.DISCONNECTED,
};

if (server.providerErrorResponse) {
serverListItem.message = {
type: 'error',
content: server.providerErrorResponse.message,
};
}

return serverListItem;
}

Expand Down
15 changes: 4 additions & 11 deletions src/www/app/outline_server_repository/access_key_serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ export function staticKeyToShadowsocksSessionConfig(staticKey: string): Shadowso

function parseShadowsocksSessionConfigJson(
maybeJsonText: string
): ShadowsocksSessionConfig | errors.ProviderErrorResponse | null {
const {method, password, server, server_port, prefix, ...rest} = JSON.parse(maybeJsonText);

if ('code' in rest && 'message' in rest) {
return rest as errors.ProviderErrorResponse;
}
): ShadowsocksSessionConfig | null {
const {method, password, server, server_port, prefix, error} = JSON.parse(maybeJsonText);

// These are the mandatory keys.
const missingKeys = [];
Expand All @@ -64,14 +60,15 @@ function parseShadowsocksSessionConfigJson(
host: server,
port: server_port,
prefix,
error
};
}

// fetches information from a dynamic access key and attempts to parse it
// TODO(daniellacosse): unit tests
export async function fetchShadowsocksSessionConfig(
configLocation: URL
): Promise<ShadowsocksSessionConfig | errors.ProviderErrorResponse> {
): Promise<ShadowsocksSessionConfig> {
let response;
try {
response = await fetch(configLocation, {cache: 'no-store', redirect: 'follow'});
Expand All @@ -86,10 +83,6 @@ export async function fetchShadowsocksSessionConfig(
return staticKeyToShadowsocksSessionConfig(responseBody);
}

if (responseBody.toLocaleUpperCase().includes('ERROR')) {
return {code: 0, message: responseBody, details: {}};
}

return parseShadowsocksSessionConfigJson(responseBody);
} catch (cause) {
throw new errors.ServerAccessKeyInvalid('Failed to parse VPN information fetched from dynamic access key.', {
Expand Down
11 changes: 3 additions & 8 deletions src/www/app/outline_server_repository/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class OutlineServer implements Server {
private static readonly SUPPORTED_CIPHERS = ['chacha20-ietf-poly1305', 'aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm'];

errorMessageId?: string;
providerErrorResponse?: errors.ProviderErrorResponse<{}>;
private sessionConfig?: ShadowsocksSessionConfig;

constructor(
Expand Down Expand Up @@ -97,15 +96,11 @@ export class OutlineServer implements Server {

async connect() {
if (this.type === ServerType.DYNAMIC_CONNECTION) {
const sessionConfigOrError = await fetchShadowsocksSessionConfig(this.sessionConfigLocation);
this.sessionConfig = await fetchShadowsocksSessionConfig(this.sessionConfigLocation);

if ('code' in sessionConfigOrError && 'message' in sessionConfigOrError) {
this.providerErrorResponse = sessionConfigOrError as errors.ProviderErrorResponse;

throw new errors.SessionConfigFetchFailed('Failed to fetch VPN information from dynamic access key.');
if ('error' in this.sessionConfig) {
this.errorMessageId = this.sessionConfig.error.message;
}

this.sessionConfig = sessionConfigOrError as ShadowsocksSessionConfig;
}

try {
Expand Down
3 changes: 3 additions & 0 deletions src/www/app/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import * as errors from '../model/errors';

export interface ShadowsocksSessionConfig {
host?: string;
port?: number;
password?: string;
method?: string;
prefix?: string;
error?: errors.SessionConfigError;
}

export const enum TunnelStatus {
Expand Down
4 changes: 1 addition & 3 deletions src/www/model/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import {Server} from './server';
import {CustomError} from '../../infrastructure/custom_error';

export interface ProviderErrorResponse<T extends object = {}> {
code: number;
export interface SessionConfigError {
message: string;
details: T;
}

export class ServerAlreadyAdded extends CustomError {
Expand Down
5 changes: 0 additions & 5 deletions src/www/model/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {ProviderErrorResponse} from './errors';

// TODO: add guidelines for this file

export enum ServerType {
Expand Down Expand Up @@ -50,9 +48,6 @@ export interface Server {
// must match one of the localized app message.
errorMessageId?: string;

// Provider error returned pertaining to the server's status
providerErrorResponse?: ProviderErrorResponse;

// Connects to the server, redirecting the device's traffic.
connect(): Promise<void>;

Expand Down
7 changes: 0 additions & 7 deletions src/www/views/servers_view/server_list_item/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ export interface ServerListItem {
id: string;
name: string;
connectionState: ServerConnectionState;
message?: {
type: 'error' | 'warning' | 'info';
content: string;
};
contact?: {
email: string;
};
}

/**
Expand Down

0 comments on commit 1234265

Please sign in to comment.