[Client] Drop apiViaStream option

Resolve #3911
This commit is contained in:
syuilo 2019-01-18 16:46:56 +09:00
parent 4ba43b69b6
commit 9fc1cc5255
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
7 changed files with 36 additions and 74 deletions

View File

@ -870,9 +870,6 @@ desktop/views/components/settings.vue:
web-search-engine-desc: "例: https://www.google.com/?#q={{query}}" web-search-engine-desc: "例: https://www.google.com/?#q={{query}}"
auto-popout: "ウィンドウの自動ポップアウト" auto-popout: "ウィンドウの自動ポップアウト"
auto-popout-desc: "ウィンドウが開かれるとき、ポップアウト(ブラウザ外に切り離す)可能なら自動でポップアウトします。この設定はブラウザに記憶されます。" auto-popout-desc: "ウィンドウが開かれるとき、ポップアウト(ブラウザ外に切り離す)可能なら自動でポップアウトします。この設定はブラウザに記憶されます。"
advanced: "詳細設定"
api-via-stream: "ストリームを経由したAPIリクエスト"
api-via-stream-desc: "この設定をオンにすると、websocket接続を経由してAPIリクエストが行われます(パフォーマンス向上が期待できます)。オフにすると、ネイティブの fetch APIが利用されます。この設定はこのデバイスのみ有効です。"
deck-nav: "デッキ内ナビゲーション" deck-nav: "デッキ内ナビゲーション"
deck-nav-desc: "デッキを使用しているとき、ナビゲーションが発生する際にページ遷移を行わずに一時的なカラムで受けるようにします。" deck-nav-desc: "デッキを使用しているとき、ナビゲーションが発生する際にページ遷移を行わずに一時的なカラムで受けるようにします。"
deck-default: "デッキをデフォルトのUIにする" deck-default: "デッキをデフォルトのUIにする"

View File

@ -148,7 +148,7 @@ export default Vue.extend({
}, },
updateStats() { updateStats() {
this.$root.api('stats', {}, false, true).then(stats => { this.$root.api('stats', {}, true).then(stats => {
this.stats = stats; this.stats = stats;
}); });
} }

View File

@ -72,7 +72,7 @@ export default Vue.extend({
username: this.username, username: this.username,
password: this.password, password: this.password,
token: this.user && this.user.twoFactorEnabled ? this.token : undefined token: this.user && this.user.twoFactorEnabled ? this.token : undefined
}, true).then(res => { }).then(res => {
localStorage.setItem('i', res.i); localStorage.setItem('i', res.i);
location.reload(); location.reload();
}).catch(() => { }).catch(() => {

View File

@ -142,11 +142,11 @@ export default Vue.extend({
password: this.password, password: this.password,
invitationCode: this.invitationCode, invitationCode: this.invitationCode,
'g-recaptcha-response': this.meta.enableRecaptcha ? (window as any).grecaptcha.getResponse() : null 'g-recaptcha-response': this.meta.enableRecaptcha ? (window as any).grecaptcha.getResponse() : null
}, true).then(() => { }).then(() => {
this.$root.api('signin', { this.$root.api('signin', {
username: this.username, username: this.username,
password: this.password password: this.password
}, true).then(res => { }).then(res => {
localStorage.setItem('i', res.i); localStorage.setItem('i', res.i);
location.reload(); location.reload();
}); });

View File

@ -32,13 +32,6 @@
<span slot="desc">{{ $t('auto-popout-desc') }}</span> <span slot="desc">{{ $t('auto-popout-desc') }}</span>
</ui-switch> </ui-switch>
<ui-switch v-model="deckNav">{{ $t('deck-nav') }}<span slot="desc">{{ $t('deck-nav-desc') }}</span></ui-switch> <ui-switch v-model="deckNav">{{ $t('deck-nav') }}<span slot="desc">{{ $t('deck-nav-desc') }}</span></ui-switch>
<details>
<summary>{{ $t('advanced') }}</summary>
<ui-switch v-model="apiViaStream">{{ $t('api-via-stream') }}
<span slot="desc">{{ $t('api-via-stream-desc') }}</span>
</ui-switch>
</details>
</section> </section>
<section> <section>
@ -333,11 +326,6 @@ export default Vue.extend({
set(value) { this.$store.commit('device/set', { key: 'reduceMotion', value }); } 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: { autoPopout: {
get() { return this.$store.state.device.autoPopout; }, get() { return this.$store.state.device.autoPopout; },
set(value) { this.$store.commit('device/set', { key: 'autoPopout', value }); } set(value) { this.$store.commit('device/set', { key: 'autoPopout', value }); }

View File

@ -385,7 +385,7 @@ export default class MiOS extends EventEmitter {
* @param data * @param data
*/ */
@autobind @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 (!silent) {
if (++pending === 1) { if (++pending === 1) {
spinner = document.createElement('div'); spinner = document.createElement('div');
@ -401,66 +401,44 @@ export default class MiOS extends EventEmitter {
}; };
const promise = new Promise((resolve, reject) => { 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 req = {
const id = Math.random().toString().substr(2, 8); id: uuid(),
date: new Date(),
name: endpoint,
data,
res: null,
status: null
};
this.stream.once(`api:${id}`, res => { if (this.debug) {
if (res == null || Object.keys(res).length == 0) { this.requests.push(req);
resolve(null); }
} else if (res.res) {
resolve(res.res);
} else {
reject(res.e);
}
});
this.stream.send('api', { // Send request
id: id, fetch(endpoint.indexOf('://') > -1 ? endpoint : `${apiUrl}/${endpoint}`, {
ep: endpoint, method: 'POST',
data: data body: JSON.stringify(data),
}); credentials: endpoint === 'signin' ? 'include' : 'omit',
} else { cache: 'no-cache'
// Append a credential }).then(async (res) => {
if (this.store.getters.isSignedIn) (data as any).i = this.store.state.i.token; const body = res.status === 204 ? null : await res.json();
const req = {
id: uuid(),
date: new Date(),
name: endpoint,
data,
res: null,
status: null
};
if (this.debug) { if (this.debug) {
this.requests.push(req); req.status = res.status;
req.res = body;
} }
// Send request if (res.status === 200) {
fetch(endpoint.indexOf('://') > -1 ? endpoint : `${apiUrl}/${endpoint}`, { resolve(body);
method: 'POST', } else if (res.status === 204) {
body: JSON.stringify(data), resolve();
credentials: endpoint === 'signin' ? 'include' : 'omit', } else {
cache: 'no-cache' reject(body.error);
}).then(async (res) => { }
const body = res.status === 204 ? null : await res.json(); }).catch(reject);
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);
}
}); });
promise.then(onFinally, onFinally); promise.then(onFinally, onFinally);

View File

@ -47,7 +47,6 @@ const defaultSettings = {
const defaultDeviceSettings = { const defaultDeviceSettings = {
reduceMotion: false, reduceMotion: false,
apiViaStream: true,
autoPopout: false, autoPopout: false,
darkmode: false, darkmode: false,
darkTheme: 'dark', darkTheme: 'dark',