From 3aef5e6748777b821e8bcb3ad58410ac52b848e2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 13 Oct 2018 19:16:47 +0900 Subject: [PATCH] Better id --- src/client/app/boot.js | 2 +- src/client/app/common/scripts/stream.ts | 4 ++-- src/client/app/common/views/widgets/posts-monitor.vue | 2 +- src/client/app/mios.ts | 2 +- src/server/api/streaming.ts | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/app/boot.js b/src/client/app/boot.js index 6e06a88aa3..063749caee 100644 --- a/src/client/app/boot.js +++ b/src/client/app/boot.js @@ -142,7 +142,7 @@ localStorage.setItem('shouldFlush', 'false'); // Random - localStorage.setItem('salt', Math.random().toString()); + localStorage.setItem('salt', Math.random().toString().substr(2, 8)); // Clear cache (service worker) try { diff --git a/src/client/app/common/scripts/stream.ts b/src/client/app/common/scripts/stream.ts index 7456c0b074..70180bc5b7 100644 --- a/src/client/app/common/scripts/stream.ts +++ b/src/client/app/common/scripts/stream.ts @@ -156,7 +156,7 @@ class Pool { this.channel = channel; this.stream = stream; - this.id = Math.random().toString(); + this.id = Math.random().toString().substr(2, 8); this.stream.on('_disconnected_', this.onStreamDisconnected); } @@ -275,7 +275,7 @@ class NonSharedConnection extends Connection { super(stream, channel); this.params = params; - this.id = Math.random().toString(); + this.id = Math.random().toString().substr(2, 8); this.connect(); } diff --git a/src/client/app/common/views/widgets/posts-monitor.vue b/src/client/app/common/views/widgets/posts-monitor.vue index cb307715d8..c62533d1ee 100644 --- a/src/client/app/common/views/widgets/posts-monitor.vue +++ b/src/client/app/common/views/widgets/posts-monitor.vue @@ -114,7 +114,7 @@ export default define({ this.connection.on('stats', this.onStats); this.connection.on('statsLog', this.onStatsLog); this.connection.send('requestLog',{ - id: Math.random().toString() + id: Math.random().toString().substr(2, 8) }); }, beforeDestroy() { diff --git a/src/client/app/mios.ts b/src/client/app/mios.ts index 558c53dcf1..abbd23e3d4 100644 --- a/src/client/app/mios.ts +++ b/src/client/app/mios.ts @@ -446,7 +446,7 @@ export default class MiOS extends EventEmitter { const viaStream = this.stream && this.store.state.device.apiViaStream && !forceFetch; if (viaStream) { - const id = Math.random().toString(); + const id = Math.random().toString().substr(2, 8); this.stream.once(`api:${id}`, res => { if (res == null || Object.keys(res).length == 0) { diff --git a/src/server/api/streaming.ts b/src/server/api/streaming.ts index 1a0543b364..8c0e6f6372 100644 --- a/src/server/api/streaming.ts +++ b/src/server/api/streaming.ts @@ -64,14 +64,14 @@ module.exports = (server: http.Server) => { })); }; - main.connectChannel(Math.random().toString(), null, + main.connectChannel(Math.random().toString().substr(2, 8), null, request.resourceURL.pathname === '/' ? 'homeTimeline' : request.resourceURL.pathname === '/local-timeline' ? 'localTimeline' : request.resourceURL.pathname === '/hybrid-timeline' ? 'hybridTimeline' : request.resourceURL.pathname === '/global-timeline' ? 'globalTimeline' : null); if (request.resourceURL.pathname === '/') { - main.connectChannel(Math.random().toString(), null, 'main'); + main.connectChannel(Math.random().toString().substr(2, 8), null, 'main'); } }