@dongdev/fca-unofficial 2.0.21 → 2.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/package.json +1 -1
- package/src/api/http/httpGet.js +22 -40
- package/src/api/http/httpPost.js +26 -38
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/api/http/httpGet.js
CHANGED
@@ -1,64 +1,46 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const
|
4
|
-
const { get } = require("../../utils/request");
|
5
|
-
const { getType } = require("../../utils/format");
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
-
return function httpGet(url, form, customHeader, callback, notAPI) {
|
8
|
-
let resolveFunc = function() {};
|
9
|
-
let rejectFunc = function() {};
|
3
|
+
const { getType } = require("../../utils/format.js");
|
4
|
+
const { get } = require("../../utils/request.js");
|
10
5
|
|
11
|
-
|
6
|
+
const httpGetFactory = function (defaultFuncs, api, ctx) {
|
7
|
+
return function httpGet(url, form, callback, notAPI) {
|
8
|
+
let resolveFunc = () => { };
|
9
|
+
let rejectFunc = () => { };
|
10
|
+
|
11
|
+
const returnPromise = new Promise((resolve, reject) => {
|
12
12
|
resolveFunc = resolve;
|
13
13
|
rejectFunc = reject;
|
14
14
|
});
|
15
15
|
|
16
16
|
if (
|
17
|
-
|
18
|
-
getType(form)
|
17
|
+
!callback &&
|
18
|
+
(getType(form) === "Function" || getType(form) === "AsyncFunction")
|
19
19
|
) {
|
20
20
|
callback = form;
|
21
21
|
form = {};
|
22
22
|
}
|
23
23
|
|
24
|
-
|
25
|
-
getType(customHeader) == "Function" ||
|
26
|
-
getType(customHeader) == "AsyncFunction"
|
27
|
-
) {
|
28
|
-
callback = customHeader;
|
29
|
-
customHeader = {};
|
30
|
-
}
|
31
|
-
|
32
|
-
customHeader = customHeader || {};
|
24
|
+
form = form || {};
|
33
25
|
|
34
26
|
callback =
|
35
27
|
callback ||
|
36
|
-
function(err, data) {
|
28
|
+
function (err, data) {
|
37
29
|
if (err) return rejectFunc(err);
|
38
30
|
resolveFunc(data);
|
39
31
|
};
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
.
|
47
|
-
|
48
|
-
|
49
|
-
});
|
50
|
-
} else {
|
51
|
-
defaultFuncs
|
52
|
-
.get(url, ctx.jar, form, null, customHeader)
|
53
|
-
.then(function(resData) {
|
54
|
-
callback(null, resData.data.toString());
|
55
|
-
})
|
56
|
-
.catch(function(err) {
|
57
|
-
log.error("httpGet", err);
|
58
|
-
return callback(err);
|
59
|
-
});
|
60
|
-
}
|
33
|
+
const executor = notAPI ? get : defaultFuncs.get;
|
34
|
+
|
35
|
+
executor(url, ctx.jar, form)
|
36
|
+
.then((resData) => callback(null, resData.data))
|
37
|
+
.catch(function (err) {
|
38
|
+
console.error("httpGet", err);
|
39
|
+
return callback(err);
|
40
|
+
});
|
61
41
|
|
62
42
|
return returnPromise;
|
63
43
|
};
|
64
44
|
};
|
45
|
+
|
46
|
+
module.exports = httpGetFactory;
|
package/src/api/http/httpPost.js
CHANGED
@@ -1,64 +1,52 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const log = require("npmlog");
|
4
3
|
const { post } = require("../../utils/request");
|
5
4
|
const { getType } = require("../../utils/format");
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
-
return function httpPost(url, form, customHeader, callback, notAPI) {
|
8
|
-
let resolveFunc = function() {};
|
9
|
-
let rejectFunc = function() {};
|
10
5
|
|
11
|
-
|
6
|
+
const httpPostFactory = function (defaultFuncs, api, ctx) {
|
7
|
+
return function httpPost(url, form, callback, notAPI) {
|
8
|
+
let resolveFunc = () => { };
|
9
|
+
let rejectFunc = () => { };
|
10
|
+
|
11
|
+
const returnPromise = new Promise((resolve, reject) => {
|
12
12
|
resolveFunc = resolve;
|
13
13
|
rejectFunc = reject;
|
14
14
|
});
|
15
15
|
|
16
16
|
if (
|
17
|
-
|
18
|
-
getType(form)
|
17
|
+
!callback &&
|
18
|
+
(getType(form) === "Function" || getType(form) === "AsyncFunction")
|
19
19
|
) {
|
20
20
|
callback = form;
|
21
21
|
form = {};
|
22
22
|
}
|
23
23
|
|
24
|
-
|
25
|
-
getType(customHeader) == "Function" ||
|
26
|
-
getType(customHeader) == "AsyncFunction"
|
27
|
-
) {
|
28
|
-
callback = customHeader;
|
29
|
-
customHeader = {};
|
30
|
-
}
|
31
|
-
|
32
|
-
customHeader = customHeader || {};
|
24
|
+
form = form || {};
|
33
25
|
|
34
26
|
callback =
|
35
27
|
callback ||
|
36
|
-
function(err, data) {
|
28
|
+
function (err, data) {
|
37
29
|
if (err) return rejectFunc(err);
|
38
30
|
resolveFunc(data);
|
39
31
|
};
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
.
|
53
|
-
|
54
|
-
|
55
|
-
})
|
56
|
-
.catch(function(err) {
|
57
|
-
log.error("httpPost", err);
|
58
|
-
return callback(err);
|
59
|
-
});
|
60
|
-
}
|
33
|
+
const executor = notAPI ? post : defaultFuncs.post;
|
34
|
+
|
35
|
+
executor(url, ctx.jar, form, ctx.globalOptions)
|
36
|
+
.then((resData) => {
|
37
|
+
let data = resData.data;
|
38
|
+
if (typeof data === "object") {
|
39
|
+
data = JSON.stringify(data, null, 2);
|
40
|
+
}
|
41
|
+
callback(null, data);
|
42
|
+
})
|
43
|
+
.catch((err) => {
|
44
|
+
console.error("httpPost", err);
|
45
|
+
return callback(err);
|
46
|
+
});
|
61
47
|
|
62
48
|
return returnPromise;
|
63
49
|
};
|
64
50
|
};
|
51
|
+
|
52
|
+
module.exports = httpPostFactory;
|