diff options
| author | haishanh <[email protected]> | 2018-10-30 15:55:33 +0800 |
|---|---|---|
| committer | haishanh <[email protected]> | 2018-10-30 16:01:33 +0800 |
| commit | ddebbbf024427a0b10d398a2fb09d8c14a8267f5 (patch) | |
| tree | 9279ccaa1e25d02696f69d8c29e6dac25cb18766 /src/api/logs.js | |
| parent | 58d21fc3d9a38a4847a867929868d091aa822652 (diff) | |
fix(logs): add random str to each log id to prevent key collision
Diffstat (limited to 'src/api/logs.js')
| -rw-r--r-- | src/api/logs.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/api/logs.js b/src/api/logs.js index 291ea26..779a5b4 100644 --- a/src/api/logs.js +++ b/src/api/logs.js @@ -6,6 +6,10 @@ import { const endpoint = '/logs'; const textDecoder = new TextDecoder('utf-8', { stream: true }); +const getRandomStr = () => { + return Math.floor((1 + Math.random()) * 0x10000).toString(16); +}; + function getURLAndInit() { const c = getAPIConfig(); const baseURL = getAPIBaseURL(c); @@ -28,7 +32,7 @@ const store = { const time = now.toLocaleString('zh-Hans'); // mutate input param in place intentionally o.time = time; - o.id = now - 0; + o.id = now - 0 + getRandomStr(); o.even = even = !even; this.logs.unshift(o); if (this.logs.length > this.size) this.logs.pop(); |
