|
@@ -155,6 +155,7 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
this.logger.info(`${scriptName}, 开始执行!`);
|
|
this.logger.info(`${scriptName}, 开始执行!`);
|
|
|
|
|
+ // this.checkRecordRequestBody();
|
|
|
}
|
|
}
|
|
|
get isRequest() {
|
|
get isRequest() {
|
|
|
return typeof $request !== "undefined" && typeof $response === "undefined";
|
|
return typeof $request !== "undefined" && typeof $response === "undefined";
|
|
@@ -178,6 +179,61 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ checkRecordRequestBody() {
|
|
|
|
|
+ if (!this.isRequest) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const reqBody = $request.body;
|
|
|
|
|
+ if (!reqBody) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const env = this.env;
|
|
|
|
|
+ const path = $request.path;
|
|
|
|
|
+ let cacheKey = this.scriptName + "#" + path.replace("/", "_");
|
|
|
|
|
+ cacheKey = cacheKey.replace("?", "#");
|
|
|
|
|
+ if (env.isQuanX) $prefs.setValueForKey(reqBody, cacheKey);
|
|
|
|
|
+ if (env.isLoon || env.isSurge) $persistentStore.write(reqBody, cacheKey);
|
|
|
|
|
+ if (env.isNode) {
|
|
|
|
|
+ const node_fs = require("fs");
|
|
|
|
|
+ node_fs.writeFileSync(
|
|
|
|
|
+ `${cacheKey}.json`,
|
|
|
|
|
+ reqBody,
|
|
|
|
|
+ {
|
|
|
|
|
+ flag: "w"
|
|
|
|
|
+ },
|
|
|
|
|
+ (err) => console.log(err)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getRequestBody() {
|
|
|
|
|
+ const env = this.env;
|
|
|
|
|
+ const path = $request.path;
|
|
|
|
|
+ let cacheKey = this.scriptName + "#" + path.replace("/", "_");
|
|
|
|
|
+ cacheKey = cacheKey.replace("?", "#");
|
|
|
|
|
+ if (env.isSurge || env.isLoon) {
|
|
|
|
|
+ return $persistentStore.read(cacheKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (env.isQuanX) {
|
|
|
|
|
+ return $prefs.valueForKey(cacheKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (env.isNode) {
|
|
|
|
|
+ const fpath = `${cacheKey}.json`;
|
|
|
|
|
+ const node_fs = require("fs");
|
|
|
|
|
+ if (!node_fs.existsSync(fpath)) {
|
|
|
|
|
+ return JSON.parse(
|
|
|
|
|
+ node_fs.readFileSync(fpath)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getResponseBody() {
|
|
|
|
|
+ if ($response) {
|
|
|
|
|
+ return $response.body;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
costTime() {
|
|
costTime() {
|
|
|
let info = `${this.scriptName}执行完毕!`
|
|
let info = `${this.scriptName}执行完毕!`
|
|
|
// if (this.isNode && this.isExecComm) {
|
|
// if (this.isNode && this.isExecComm) {
|
|
@@ -837,15 +893,15 @@ function MagicNotification(scriptName, env, logger, http) {
|
|
|
let newOpts = {};
|
|
let newOpts = {};
|
|
|
if (typeof _opts === "string") {
|
|
if (typeof _opts === "string") {
|
|
|
if(_opts.length > 0){
|
|
if(_opts.length > 0){
|
|
|
- if (this.isLoon){
|
|
|
|
|
|
|
+ if (env.isLoon){
|
|
|
newOpts = {
|
|
newOpts = {
|
|
|
openUrl: _opts
|
|
openUrl: _opts
|
|
|
};
|
|
};
|
|
|
- }else if (this.isQuanX){
|
|
|
|
|
|
|
+ }else if (env.isQuanX){
|
|
|
newOpts = {
|
|
newOpts = {
|
|
|
"open-url": _opts
|
|
"open-url": _opts
|
|
|
};
|
|
};
|
|
|
- }else if (this.isSurge){
|
|
|
|
|
|
|
+ }else if (env.isSurge){
|
|
|
newOpts = {
|
|
newOpts = {
|
|
|
url: _opts
|
|
url: _opts
|
|
|
};
|
|
};
|