From 9f7d54cb885812f152218132929be3249642cb0d Mon Sep 17 00:00:00 2001 From: kPherox Date: Sat, 27 Apr 2019 18:21:18 +0900 Subject: [PATCH] Add setter for non authorized clients --- src/main/Client.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/Client.ts b/src/main/Client.ts index a240dac3..17a0be21 100644 --- a/src/main/Client.ts +++ b/src/main/Client.ts @@ -16,21 +16,22 @@ export default class Clients { let clients = protocol === 'http' ? this.nonAuthorizedHTTP : this.nonAuthorizedWebsocket if (!clients.has(domain)) { - this.createNoAuthClient(domain) + this.setNoAuthClient(protocol, domain, this.createNoAuthClient(protocol, domain)) } return clients.get(domain)! } - private static createNoAuthClient(domain: string) { + public static setNoAuthClient(protocol: Protocol, domain: string, client: Mastodon) { + let clients = protocol === 'http' ? this.nonAuthorizedHTTP : this.nonAuthorizedWebsocket + clients.set(domain, client) + } - this.nonAuthorizedHTTP.set(domain, new Mastodon( + private static createNoAuthClient(protocol: Protocol, domain: string): Mastodon { + let scheme = protocol === 'http' ? 'https://' : 'wss://' + return new Mastodon( '', - 'https://' + domain + '/api/v1' - )) - this.nonAuthorizedWebsocket.set(domain, new Mastodon( - '', - 'wss://' + domain + '/api/v1' - )) + scheme + domain + '/api/v1' + ) } } \ No newline at end of file