From 9fc1cc525590fc94431eb6b4beccfeb75acf08bb Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 18 Jan 2019 16:46:56 +0900 Subject: [PATCH] [Client] Drop apiViaStream option Resolve #3911 --- locales/ja-JP.yml | 3 - src/client/app/admin/views/dashboard.vue | 2 +- .../app/common/views/components/signin.vue | 2 +- .../app/common/views/components/signup.vue | 4 +- .../app/desktop/views/components/settings.vue | 12 --- src/client/app/mios.ts | 86 +++++++------------ src/client/app/store.ts | 1 - 7 files changed, 36 insertions(+), 74 deletions(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index a7796c4d1..f644c9e65 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -870,9 +870,6 @@ desktop/views/components/settings.vue: web-search-engine-desc: "例: https://www.google.com/?#q={{query}}" auto-popout: "ウィンドウの自動ポップアウト" auto-popout-desc: "ウィンドウが開かれるとき、ポップアウト(ブラウザ外に切り離す)可能なら自動でポップアウトします。この設定はブラウザに記憶されます。" - advanced: "詳細設定" - api-via-stream: "ストリームを経由したAPIリクエスト" - api-via-stream-desc: "この設定をオンにすると、websocket接続を経由してAPIリクエストが行われます(パフォーマンス向上が期待できます)。オフにすると、ネイティブの fetch APIが利用されます。この設定はこのデバイスのみ有効です。" deck-nav: "デッキ内ナビゲーション" deck-nav-desc: "デッキを使用しているとき、ナビゲーションが発生する際にページ遷移を行わずに一時的なカラムで受けるようにします。" deck-default: "デッキをデフォルトのUIにする" diff --git a/src/client/app/admin/views/dashboard.vue b/src/client/app/admin/views/dashboard.vue index 9fb97f2ef..aa4431e43 100644 --- a/src/client/app/admin/views/dashboard.vue +++ b/src/client/app/admin/views/dashboard.vue @@ -148,7 +148,7 @@ export default Vue.extend({ }, updateStats() { - this.$root.api('stats', {}, false, true).then(stats => { + this.$root.api('stats', {}, true).then(stats => { this.stats = stats; }); } diff --git a/src/client/app/common/views/components/signin.vue b/src/client/app/common/views/components/signin.vue index 7efbde38b..724efdfc1 100644 --- a/src/client/app/common/views/components/signin.vue +++ b/src/client/app/common/views/components/signin.vue @@ -72,7 +72,7 @@ export default Vue.extend({ username: this.username, password: this.password, token: this.user && this.user.twoFactorEnabled ? this.token : undefined - }, true).then(res => { + }).then(res => { localStorage.setItem('i', res.i); location.reload(); }).catch(() => { diff --git a/src/client/app/common/views/components/signup.vue b/src/client/app/common/views/components/signup.vue index f7c4f4bf1..f38aaad8e 100644 --- a/src/client/app/common/views/components/signup.vue +++ b/src/client/app/common/views/components/signup.vue @@ -142,11 +142,11 @@ export default Vue.extend({ password: this.password, invitationCode: this.invitationCode, 'g-recaptcha-response': this.meta.enableRecaptcha ? (window as any).grecaptcha.getResponse() : null - }, true).then(() => { + }).then(() => { this.$root.api('signin', { username: this.username, password: this.password - }, true).then(res => { + }).then(res => { localStorage.setItem('i', res.i); location.reload(); }); diff --git a/src/client/app/desktop/views/components/settings.vue b/src/client/app/desktop/views/components/settings.vue index 5ffe69ef4..78f8d9ccd 100644 --- a/src/client/app/desktop/views/components/settings.vue +++ b/src/client/app/desktop/views/components/settings.vue @@ -32,13 +32,6 @@ {{ $t('auto-popout-desc') }} {{ $t('deck-nav') }}{{ $t('deck-nav-desc') }} - -
- {{ $t('advanced') }} - {{ $t('api-via-stream') }} - {{ $t('api-via-stream-desc') }} - -
@@ -333,11 +326,6 @@ export default Vue.extend({ set(value) { this.$store.commit('device/set', { key: 'reduceMotion', value }); } }, - apiViaStream: { - get() { return this.$store.state.device.apiViaStream; }, - set(value) { this.$store.commit('device/set', { key: 'apiViaStream', value }); } - }, - autoPopout: { get() { return this.$store.state.device.autoPopout; }, set(value) { this.$store.commit('device/set', { key: 'autoPopout', value }); } diff --git a/src/client/app/mios.ts b/src/client/app/mios.ts index fad60f413..dc550b6f7 100644 --- a/src/client/app/mios.ts +++ b/src/client/app/mios.ts @@ -385,7 +385,7 @@ export default class MiOS extends EventEmitter { * @param data パラメータ */ @autobind - public api(endpoint: string, data: { [x: string]: any } = {}, forceFetch = false, silent = false): Promise<{ [x: string]: any }> { + public api(endpoint: string, data: { [x: string]: any } = {}, silent = false): Promise<{ [x: string]: any }> { if (!silent) { if (++pending === 1) { spinner = document.createElement('div'); @@ -401,66 +401,44 @@ export default class MiOS extends EventEmitter { }; const promise = new Promise((resolve, reject) => { - const viaStream = this.stream && this.stream.state == 'connected' && this.store.state.device.apiViaStream && !forceFetch; + // Append a credential + if (this.store.getters.isSignedIn) (data as any).i = this.store.state.i.token; - if (viaStream) { - const id = Math.random().toString().substr(2, 8); + const req = { + id: uuid(), + date: new Date(), + name: endpoint, + data, + res: null, + status: null + }; - this.stream.once(`api:${id}`, res => { - if (res == null || Object.keys(res).length == 0) { - resolve(null); - } else if (res.res) { - resolve(res.res); - } else { - reject(res.e); - } - }); + if (this.debug) { + this.requests.push(req); + } - this.stream.send('api', { - id: id, - ep: endpoint, - data: data - }); - } else { - // Append a credential - if (this.store.getters.isSignedIn) (data as any).i = this.store.state.i.token; - - const req = { - id: uuid(), - date: new Date(), - name: endpoint, - data, - res: null, - status: null - }; + // Send request + fetch(endpoint.indexOf('://') > -1 ? endpoint : `${apiUrl}/${endpoint}`, { + method: 'POST', + body: JSON.stringify(data), + credentials: endpoint === 'signin' ? 'include' : 'omit', + cache: 'no-cache' + }).then(async (res) => { + const body = res.status === 204 ? null : await res.json(); if (this.debug) { - this.requests.push(req); + req.status = res.status; + req.res = body; } - // Send request - fetch(endpoint.indexOf('://') > -1 ? endpoint : `${apiUrl}/${endpoint}`, { - method: 'POST', - body: JSON.stringify(data), - credentials: endpoint === 'signin' ? 'include' : 'omit', - cache: 'no-cache' - }).then(async (res) => { - const body = res.status === 204 ? null : await res.json(); - - if (this.debug) { - req.status = res.status; - req.res = body; - } - - if (res.status === 200) { - resolve(body); - } else if (res.status === 204) { - resolve(); - } else { - reject(body.error); - } - }).catch(reject); - } + if (res.status === 200) { + resolve(body); + } else if (res.status === 204) { + resolve(); + } else { + reject(body.error); + } + }).catch(reject); }); promise.then(onFinally, onFinally); diff --git a/src/client/app/store.ts b/src/client/app/store.ts index 03fc9565d..350826e5e 100644 --- a/src/client/app/store.ts +++ b/src/client/app/store.ts @@ -47,7 +47,6 @@ const defaultSettings = { const defaultDeviceSettings = { reduceMotion: false, - apiViaStream: true, autoPopout: false, darkmode: false, darkTheme: 'dark',