Skip to content

Commit 4846653

Browse files
committed
fix: weapp uuid error.
1 parent 66878f2 commit 4846653

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/InstallationController.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
*/
1111

1212
import Storage from './Storage';
13-
const uuidv4 = require('uuid/v4');
13+
let uuidv4 = null;
14+
if (process.env.PARSE_BUILD === 'weapp') {
15+
uuidv4 = require('./uuid.weapp');
16+
} else {
17+
uuidv4 = require('uuid/v4');
18+
}
1419

1520
let iidCache = null;
1621

src/uuid.weapp.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function uuid() {
2+
const s = [];
3+
const hexDigits = '0123456789abcdef';
4+
5+
for (let i = 0; i < 36; i++) {
6+
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
7+
}
8+
9+
s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
10+
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
11+
s[8] = s[13] = s[18] = s[23] = '-';
12+
13+
const uuid = s.join('');
14+
return uuid;
15+
}
16+
17+
module.exports = uuid;

0 commit comments

Comments
 (0)