Skip to content

Commit 5cd0839

Browse files
committed
clean uuid urlencode library
1 parent c54c60a commit 5cd0839

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

library/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ module.exports = {
22
sls: require('./sls'),
33
cam: require('./cam'),
44
scf: require('./scf'),
5-
common: require('./common')
5+
common: require('./common'),
6+
uuid: require('./uuid')
67
}

library/uuid.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
var crypto = require('crypto');
2+
3+
function rng() {
4+
return crypto.randomBytes(16);
5+
};
6+
7+
var byteToHex = [];
8+
for (var i = 0; i < 256; ++i) {
9+
byteToHex[i] = (i + 0x100).toString(16).substr(1);
10+
}
11+
12+
function bytesToUuid(buf, offset) {
13+
var i = offset || 0;
14+
var bth = byteToHex;
15+
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
16+
return ([
17+
bth[buf[i++]], bth[buf[i++]],
18+
bth[buf[i++]], bth[buf[i++]], '-',
19+
bth[buf[i++]], bth[buf[i++]], '-',
20+
bth[buf[i++]], bth[buf[i++]], '-',
21+
bth[buf[i++]], bth[buf[i++]], '-',
22+
bth[buf[i++]], bth[buf[i++]],
23+
bth[buf[i++]], bth[buf[i++]],
24+
bth[buf[i++]], bth[buf[i++]]
25+
]).join('');
26+
}
27+
28+
function v4(options, buf, offset) {
29+
var i = buf && offset || 0;
30+
31+
if (typeof(options) == 'string') {
32+
buf = options === 'binary' ? new Array(16) : null;
33+
options = null;
34+
}
35+
options = options || {};
36+
37+
var rnds = options.random || (options.rng || rng)();
38+
39+
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
40+
rnds[6] = (rnds[6] & 0x0f) | 0x40;
41+
rnds[8] = (rnds[8] & 0x3f) | 0x80;
42+
43+
// Copy bytes to buffer, if provided
44+
if (buf) {
45+
for (var ii = 0; ii < 16; ++ii) {
46+
buf[i + ii] = rnds[ii];
47+
}
48+
}
49+
50+
return buf || bytesToUuid(rnds);
51+
}
52+
53+
module.exports = v4;

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
"author": "Dfounderliu",
1919
"license": "Apache",
2020
"dependencies": {
21-
"urlencode": "^1.1.0",
22-
"uuid": "^3.3.3",
2321
"qrcode": "^1.4.4"
2422
},
2523
"devDependencies": {

sdk/login/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const util = require('util')
22
const http = require('http')
33
const os = require('os')
4-
const uuidv4 = require('uuid/v4')
4+
const uuidv4 = require('../../library/uuid')
55
const QRCode = require('qrcode')
66
const apiBaseUrl = 'scfdev.tencentserverless.com'
77
const apiShortUrl = '/login/url'

sdk/logs/scfRealTimeLogs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ScfRealTimeLogs {
4545
const keys = Object.keys(params)
4646
keys.sort()
4747
for (const k in keys) {
48-
const tempStr = keys[k] == 'Signature' ? urlencode(params[keys[k]]) : params[keys[k]]
48+
const tempStr = keys[k] == 'Signature' ? encodeURIComponent(params[keys[k]]) : params[keys[k]]
4949
strParam += '&' + keys[k] + '=' + tempStr
5050
}
5151
return strParam
@@ -66,7 +66,7 @@ class ScfRealTimeLogs {
6666
const keys = Object.keys(params)
6767
keys.sort()
6868
for (const k in keys) {
69-
const tempStr = keys[k] == 'Signature' ? urlencode(params[keys[k]]) : params[keys[k]]
69+
const tempStr = keys[k] == 'Signature' ? encodeURIComponent(params[keys[k]]) : params[keys[k]]
7070
strParam += '&' + keys[k] + '=' + tempStr
7171
}
7272

@@ -77,7 +77,7 @@ class ScfRealTimeLogs {
7777
'&Timeout=' +
7878
timeout +
7979
'&AppidSignature=' +
80-
urlencode(this.getAppid(auth))
80+
encodeURIComponent(this.getAppid(auth))
8181
)
8282
}
8383
}

0 commit comments

Comments
 (0)