|
@@ -110,7 +110,7 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
// }
|
|
// }
|
|
|
// }
|
|
// }
|
|
|
// let msg = logs.join('\n');
|
|
// let msg = logs.join('\n');
|
|
|
- if (!(logLevels[_level] < logLevels[level.toUpperCase()])) console.log(`██[${scriptName}][${level}]`+''+`${logEmoji[level.toUpperCase()]}${msg}`+'\n'+``);
|
|
|
|
|
|
|
+ if (!(logLevels[_level] < logLevels[level.toUpperCase()])) console.log(`██[${scriptName}][${level}]` + '' + `${logEmoji[level.toUpperCase()]}${msg}` + '\n' + ``);
|
|
|
};
|
|
};
|
|
|
const setLevel = logLevel => {
|
|
const setLevel = logLevel => {
|
|
|
_level = logLevel;
|
|
_level = logLevel;
|
|
@@ -126,7 +126,7 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
},
|
|
},
|
|
|
log: (...logs) => {
|
|
log: (...logs) => {
|
|
|
let msg = logs.join(logSeparator);
|
|
let msg = logs.join(logSeparator);
|
|
|
- console.log(`██[${scriptName}]`+''+`${msg}`+'\n'+``);
|
|
|
|
|
|
|
+ console.log(`██[${scriptName}]` + '' + `${msg}` + '\n' + ``);
|
|
|
},
|
|
},
|
|
|
debug: (...logs) => {
|
|
debug: (...logs) => {
|
|
|
let msg = logs.join(logSeparator);
|
|
let msg = logs.join(logSeparator);
|
|
@@ -204,22 +204,22 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- log(...logs){
|
|
|
|
|
|
|
+ log(...logs) {
|
|
|
this.logger.log(logs);
|
|
this.logger.log(logs);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- toStr(data, defVal=null){
|
|
|
|
|
- try{
|
|
|
|
|
|
|
+ toStr(data, defVal = null) {
|
|
|
|
|
+ try {
|
|
|
return JSON.stringify(data);
|
|
return JSON.stringify(data);
|
|
|
- }catch{
|
|
|
|
|
|
|
+ } catch {
|
|
|
return defVal;
|
|
return defVal;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- toObj(str, defVal=null){
|
|
|
|
|
- try{
|
|
|
|
|
|
|
+ toObj(str, defVal = null) {
|
|
|
|
|
+ try {
|
|
|
return JSON.parse(str);
|
|
return JSON.parse(str);
|
|
|
- }catch{
|
|
|
|
|
|
|
+ } catch {
|
|
|
return defVal;
|
|
return defVal;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -280,7 +280,7 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
// 解析cookie字符串的函数
|
|
// 解析cookie字符串的函数
|
|
|
parseCookies(cookieString) {
|
|
parseCookies(cookieString) {
|
|
|
let dict = {};
|
|
let dict = {};
|
|
|
- cookieString && cookieString.split(';').forEach(function(cookie) {
|
|
|
|
|
|
|
+ cookieString && cookieString.split(';').forEach(function (cookie) {
|
|
|
let parts = cookie.split('=');
|
|
let parts = cookie.split('=');
|
|
|
dict[parts.shift().trim()] = decodeURI(parts.join('='));
|
|
dict[parts.shift().trim()] = decodeURI(parts.join('='));
|
|
|
});
|
|
});
|
|
@@ -290,7 +290,7 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
// 系列化为cookie字符串
|
|
// 系列化为cookie字符串
|
|
|
serializeCookies(cookieData) {
|
|
serializeCookies(cookieData) {
|
|
|
const parts = [];
|
|
const parts = [];
|
|
|
- for(let key in cookieData){
|
|
|
|
|
|
|
+ for (let key in cookieData) {
|
|
|
let value = cookieData[key];
|
|
let value = cookieData[key];
|
|
|
let cookiePart = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
let cookiePart = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
|
parts.push(cookiePart);
|
|
parts.push(cookiePart);
|
|
@@ -420,6 +420,66 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
if (obj.S !== 0) date.setMilliseconds(obj.S); // 如果设置了毫秒
|
|
if (obj.S !== 0) date.setMilliseconds(obj.S); // 如果设置了毫秒
|
|
|
return date;
|
|
return date;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ getBaseDoneHeaders(mixHeaders = {}) {
|
|
|
|
|
+ return Object.assign(
|
|
|
|
|
+ {
|
|
|
|
|
+ 'Access-Control-Allow-Origin': '*',
|
|
|
|
|
+ 'Access-Control-Allow-Methods': 'POST,GET,OPTIONS,PUT,DELETE',
|
|
|
|
|
+ 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
|
|
|
|
|
+ },
|
|
|
|
|
+ mixHeaders
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getHtmlDoneHeaders() {
|
|
|
|
|
+ return this.getBaseDoneHeaders({
|
|
|
|
|
+ 'Content-Type': 'text/html;charset=UTF-8'
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getJsonDoneHeaders() {
|
|
|
|
|
+ return this.getBaseDoneHeaders({
|
|
|
|
|
+ 'Content-Type': 'text/json; charset=utf-8',
|
|
|
|
|
+ 'Connection': 'keep-alive'
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 推送微信消息
|
|
|
|
|
+ *
|
|
|
|
|
+ * 通用助手 AT_7wDWqSoT8xpJCQqJtHpshKhw7kXc0XCW
|
|
|
|
|
+ * 光予助手 AT_rTc93GQYIdMU8XLRnoJaSea8WkfhSzhX
|
|
|
|
|
+ * i茅台助手 AT_6b8KjFF3bYqcr7Cv7woUUES7KadNFbvR
|
|
|
|
|
+ * 个人uid UID_6P4B00X6Zv8U2oKC0I2R09emxtqq
|
|
|
|
|
+ */
|
|
|
|
|
+ doWxpusherSend(data) {
|
|
|
|
|
+ // let data = {
|
|
|
|
|
+ // appToken: "AT_rTc93GQYIdMU8XLRnoJaSea8WkfhSzhX",
|
|
|
|
|
+ // content: content,// 这是主体内容
|
|
|
|
|
+ // summary: summary,// 该参数可选,默认为 msg 的前10个字符
|
|
|
|
|
+ // contentType: 1,
|
|
|
|
|
+ // topicIds: [],
|
|
|
|
|
+ // uids: [
|
|
|
|
|
+ // "UID_6P4B00X6Zv8U2oKC0I2R09emxtqq"
|
|
|
|
|
+ // ],
|
|
|
|
|
+ // url: "",
|
|
|
|
|
+ // verifyPay: false
|
|
|
|
|
+ // };
|
|
|
|
|
+ // if (url) {
|
|
|
|
|
+ // data.url = url;
|
|
|
|
|
+ // }
|
|
|
|
|
+ const headers = this.getJsonDoneHeaders();
|
|
|
|
|
+ headers.Host = 'wxpusher.zjiecode.com';
|
|
|
|
|
+ headers['Content-Type'] = 'application/json;charset=UTF-8';
|
|
|
|
|
+ let options = {
|
|
|
|
|
+ url: 'https://wxpusher.zjiecode.com/api/send/message',
|
|
|
|
|
+ headers: headers,
|
|
|
|
|
+ body: JSON.stringify(data),
|
|
|
|
|
+ };
|
|
|
|
|
+ return this.http.post(options);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
costTime() {
|
|
costTime() {
|
|
|
let info = `${this.scriptName}执行完毕!`
|
|
let info = `${this.scriptName}执行完毕!`
|
|
|
// if (this.isNode && this.isExecComm) {
|
|
// if (this.isNode && this.isExecComm) {
|
|
@@ -558,7 +618,7 @@ function MagicHttp(env, logger) {
|
|
|
if (typeof _resp.body === "string") {
|
|
if (typeof _resp.body === "string") {
|
|
|
try {
|
|
try {
|
|
|
_resp.body = JSON.parse(_resp.body);
|
|
_resp.body = JSON.parse(_resp.body);
|
|
|
- } catch {}
|
|
|
|
|
|
|
+ } catch { }
|
|
|
}
|
|
}
|
|
|
delete _resp.data;
|
|
delete _resp.data;
|
|
|
return _resp;
|
|
return _resp;
|
|
@@ -599,13 +659,13 @@ function MagicHttp(env, logger) {
|
|
|
let synchronousRequestInterceptors = true;
|
|
let synchronousRequestInterceptors = true;
|
|
|
function interceptConfig(config) {
|
|
function interceptConfig(config) {
|
|
|
config = paramsToQueryString(config);
|
|
config = paramsToQueryString(config);
|
|
|
- logger.debug(`HTTP ${config["method"].toUpperCase()}:`+'\n'+`${JSON.stringify(config)}`);
|
|
|
|
|
|
|
+ logger.debug(`HTTP ${config["method"].toUpperCase()}:` + '\n' + `${JSON.stringify(config)}`);
|
|
|
return config;
|
|
return config;
|
|
|
}
|
|
}
|
|
|
function interceptResponse(resp) {
|
|
function interceptResponse(resp) {
|
|
|
try {
|
|
try {
|
|
|
resp = !!resp ? modifyResponse(resp) : resp;
|
|
resp = !!resp ? modifyResponse(resp) : resp;
|
|
|
- logger.sniffer(`HTTP ${resp.config["method"].toUpperCase()}:`+'\n'+`${JSON.stringify(resp.config)}`+'\n'+`STATUS CODE:`+'\n'+`${resp.status}`+'\n'+`RESPONSE:`+'\n'+`${typeof resp.body === "object" ? JSON.stringify(resp.body) : resp.body}`);
|
|
|
|
|
|
|
+ logger.sniffer(`HTTP ${resp.config["method"].toUpperCase()}:` + '\n' + `${JSON.stringify(resp.config)}` + '\n' + `STATUS CODE:` + '\n' + `${resp.status}` + '\n' + `RESPONSE:` + '\n' + `${typeof resp.body === "object" ? JSON.stringify(resp.body) : resp.body}`);
|
|
|
const err = raiseExceptionByStatusCode(resp);
|
|
const err = raiseExceptionByStatusCode(resp);
|
|
|
if (!!err) {
|
|
if (!!err) {
|
|
|
return Promise.reject(err);
|
|
return Promise.reject(err);
|
|
@@ -688,11 +748,11 @@ function MagicHttp(env, logger) {
|
|
|
}
|
|
}
|
|
|
let promise;
|
|
let promise;
|
|
|
registerInterceptors(config);
|
|
registerInterceptors(config);
|
|
|
- const defaultRequestInterceptors = [ interceptConfig, undefined ];
|
|
|
|
|
- const defaultResponseInterceptors = [ interceptResponse, undefined ];
|
|
|
|
|
|
|
+ const defaultRequestInterceptors = [interceptConfig, undefined];
|
|
|
|
|
+ const defaultResponseInterceptors = [interceptResponse, undefined];
|
|
|
if (!synchronousRequestInterceptors) {
|
|
if (!synchronousRequestInterceptors) {
|
|
|
logger.debug("Interceptors are executed in asynchronous mode");
|
|
logger.debug("Interceptors are executed in asynchronous mode");
|
|
|
- let chain = [ dispatchRequest, undefined ];
|
|
|
|
|
|
|
+ let chain = [dispatchRequest, undefined];
|
|
|
Array.prototype.unshift.apply(chain, defaultRequestInterceptors);
|
|
Array.prototype.unshift.apply(chain, defaultRequestInterceptors);
|
|
|
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
|
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
|
|
chain = chain.concat(defaultResponseInterceptors);
|
|
chain = chain.concat(defaultResponseInterceptors);
|
|
@@ -720,7 +780,7 @@ function MagicHttp(env, logger) {
|
|
|
} else {
|
|
} else {
|
|
|
logger.debug("Interceptors are executed in synchronous mode");
|
|
logger.debug("Interceptors are executed in synchronous mode");
|
|
|
Array.prototype.unshift.apply(requestInterceptorChain, defaultRequestInterceptors);
|
|
Array.prototype.unshift.apply(requestInterceptorChain, defaultRequestInterceptors);
|
|
|
- requestInterceptorChain = requestInterceptorChain.concat([ interceptConfig, undefined ]);
|
|
|
|
|
|
|
+ requestInterceptorChain = requestInterceptorChain.concat([interceptConfig, undefined]);
|
|
|
while (requestInterceptorChain.length) {
|
|
while (requestInterceptorChain.length) {
|
|
|
let onFulfilled = requestInterceptorChain.shift();
|
|
let onFulfilled = requestInterceptorChain.shift();
|
|
|
let onRejected = requestInterceptorChain.shift();
|
|
let onRejected = requestInterceptorChain.shift();
|
|
@@ -763,7 +823,7 @@ function MagicHttp(env, logger) {
|
|
|
reject(err);
|
|
reject(err);
|
|
|
}, config["timeout"]);
|
|
}, config["timeout"]);
|
|
|
});
|
|
});
|
|
|
- return Promise.race([ dispatchRequest(config), timer ]);
|
|
|
|
|
|
|
+ return Promise.race([dispatchRequest(config), timer]);
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
logger.error(`Request Timeout exception: ${err}.`);
|
|
logger.error(`Request Timeout exception: ${err}.`);
|
|
|
}
|
|
}
|
|
@@ -849,7 +909,7 @@ function MagicData(env, logger) {
|
|
|
if (typeof val === "string" && val !== "null") {
|
|
if (typeof val === "string" && val !== "null") {
|
|
|
try {
|
|
try {
|
|
|
val = JSON.parse(val);
|
|
val = JSON.parse(val);
|
|
|
- } catch {}
|
|
|
|
|
|
|
+ } catch { }
|
|
|
}
|
|
}
|
|
|
if (read_no_session === false && !!val && val["magic_session"] === true) {
|
|
if (read_no_session === false && !!val && val["magic_session"] === true) {
|
|
|
val = null;
|
|
val = null;
|
|
@@ -869,7 +929,7 @@ function MagicData(env, logger) {
|
|
|
if (type !== "object" || data instanceof Array || type === "bool" || data === null) {
|
|
if (type !== "object" || data instanceof Array || type === "bool" || data === null) {
|
|
|
data = {};
|
|
data = {};
|
|
|
}
|
|
}
|
|
|
- } catch {}
|
|
|
|
|
|
|
+ } catch { }
|
|
|
return data;
|
|
return data;
|
|
|
} else if (obj instanceof Array || obj === null || typeof obj === "undefined" || obj !== obj || typeof obj === "boolean") {
|
|
} else if (obj instanceof Array || obj === null || typeof obj === "undefined" || obj !== obj || typeof obj === "boolean") {
|
|
|
return {};
|
|
return {};
|
|
@@ -899,7 +959,7 @@ function MagicData(env, logger) {
|
|
|
}
|
|
}
|
|
|
val = _valConvertor(val, default_, session, read_no_session);
|
|
val = _valConvertor(val, default_, session, read_no_session);
|
|
|
}
|
|
}
|
|
|
- logger.debug(`READ DATA [${key}]${!!session ? `[${session}]` : ""} <${typeof val}>`+'\n'+`${JSON.stringify(val)}`);
|
|
|
|
|
|
|
+ logger.debug(`READ DATA [${key}]${!!session ? `[${session}]` : ""} <${typeof val}>` + '\n' + `${JSON.stringify(val)}`);
|
|
|
return val;
|
|
return val;
|
|
|
};
|
|
};
|
|
|
const writeForNode = (key, val, session = "", externalData = null) => {
|
|
const writeForNode = (key, val, session = "", externalData = null) => {
|
|
@@ -945,7 +1005,7 @@ function MagicData(env, logger) {
|
|
|
if (!!data && typeof data === "object") {
|
|
if (!!data && typeof data === "object") {
|
|
|
data = JSON.stringify(data, null, 4);
|
|
data = JSON.stringify(data, null, 4);
|
|
|
}
|
|
}
|
|
|
- logger.debug(`WRITE DATA [${key}]${session ? `[${session}]` : ""} <${typeof val}>`+'\n'+`${JSON.stringify(val)}`);
|
|
|
|
|
|
|
+ logger.debug(`WRITE DATA [${key}]${session ? `[${session}]` : ""} <${typeof val}>` + '\n' + `${JSON.stringify(val)}`);
|
|
|
if (!externalData) {
|
|
if (!externalData) {
|
|
|
if (env.isSurgeLike) {
|
|
if (env.isSurgeLike) {
|
|
|
return $persistentStore.write(data, key);
|
|
return $persistentStore.write(data, key);
|
|
@@ -1033,7 +1093,7 @@ function MagicData(env, logger) {
|
|
|
} else {
|
|
} else {
|
|
|
_sessions = Object.keys(data).filter(key => key !== "magic_session");
|
|
_sessions = Object.keys(data).filter(key => key !== "magic_session");
|
|
|
}
|
|
}
|
|
|
- logger.debug(`READ ALL SESSIONS [${key}] <${typeof _sessions}>`+'\n'+`${JSON.stringify(_sessions, null, 4)}`);
|
|
|
|
|
|
|
+ logger.debug(`READ ALL SESSIONS [${key}] <${typeof _sessions}>` + '\n' + `${JSON.stringify(_sessions, null, 4)}`);
|
|
|
return _sessions;
|
|
return _sessions;
|
|
|
};
|
|
};
|
|
|
const allSessions = (key, externalData = null) => {
|
|
const allSessions = (key, externalData = null) => {
|
|
@@ -1046,7 +1106,7 @@ function MagicData(env, logger) {
|
|
|
};
|
|
};
|
|
|
delete _sessions["magic_session"];
|
|
delete _sessions["magic_session"];
|
|
|
}
|
|
}
|
|
|
- logger.debug(`READ ALL SESSIONS [${key}] <${typeof _sessions}>`+'\n'+`${JSON.stringify(_sessions, null, 4)}`);
|
|
|
|
|
|
|
+ logger.debug(`READ ALL SESSIONS [${key}] <${typeof _sessions}>` + '\n' + `${JSON.stringify(_sessions, null, 4)}`);
|
|
|
return _sessions;
|
|
return _sessions;
|
|
|
};
|
|
};
|
|
|
return {
|
|
return {
|
|
@@ -1089,20 +1149,20 @@ function MagicNotification(scriptName, env, logger, http) {
|
|
|
|
|
|
|
|
function msg(subtitle, message, openUrl, mediaUrl) {
|
|
function msg(subtitle, message, openUrl, mediaUrl) {
|
|
|
let opts = {};
|
|
let opts = {};
|
|
|
- if(openUrl){
|
|
|
|
|
|
|
+ if (openUrl) {
|
|
|
opts["open-url"] = openUrl;
|
|
opts["open-url"] = openUrl;
|
|
|
}
|
|
}
|
|
|
- if(mediaUrl){
|
|
|
|
|
|
|
+ if (mediaUrl) {
|
|
|
opts["media-url"] = mediaUrl;
|
|
opts["media-url"] = mediaUrl;
|
|
|
}
|
|
}
|
|
|
- if(!message || message.length == 0){
|
|
|
|
|
|
|
+ if (!message || message.length == 0) {
|
|
|
if (Array.isArray(notifyInfo)) {
|
|
if (Array.isArray(notifyInfo)) {
|
|
|
message = notifyInfo.join("\n");
|
|
message = notifyInfo.join("\n");
|
|
|
} else {
|
|
} else {
|
|
|
message = notifyInfo;
|
|
message = notifyInfo;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if(message && message.length > 0){
|
|
|
|
|
|
|
+ if (message && message.length > 0) {
|
|
|
post(scriptName, "", message, opts);
|
|
post(scriptName, "", message, opts);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1111,16 +1171,16 @@ function MagicNotification(scriptName, env, logger, http) {
|
|
|
try {
|
|
try {
|
|
|
let newOpts = {};
|
|
let newOpts = {};
|
|
|
if (typeof _opts === "string") {
|
|
if (typeof _opts === "string") {
|
|
|
- if(_opts.length > 0){
|
|
|
|
|
- if (env.isLoon){
|
|
|
|
|
|
|
+ if (_opts.length > 0) {
|
|
|
|
|
+ if (env.isLoon) {
|
|
|
newOpts = {
|
|
newOpts = {
|
|
|
openUrl: _opts
|
|
openUrl: _opts
|
|
|
};
|
|
};
|
|
|
- }else if (env.isQuanX){
|
|
|
|
|
|
|
+ } else if (env.isQuanX) {
|
|
|
newOpts = {
|
|
newOpts = {
|
|
|
"open-url": _opts
|
|
"open-url": _opts
|
|
|
};
|
|
};
|
|
|
- }else if (env.isSurge){
|
|
|
|
|
|
|
+ } else if (env.isSurge) {
|
|
|
newOpts = {
|
|
newOpts = {
|
|
|
url: _opts
|
|
url: _opts
|
|
|
};
|
|
};
|
|
@@ -1150,7 +1210,7 @@ function MagicNotification(scriptName, env, logger, http) {
|
|
|
title = scriptName;
|
|
title = scriptName;
|
|
|
subTitle = "", body = arguments[0];
|
|
subTitle = "", body = arguments[0];
|
|
|
}
|
|
}
|
|
|
- logger.notify('\n'+`title:${title}`+'\n'+`subTitle:${subTitle}`+'\n'+`body:${body}`+'\n'+`options:${typeof opts === "object" ? JSON.stringify(opts) : opts}`);
|
|
|
|
|
|
|
+ logger.notify('\n' + `title:${title}` + '\n' + `subTitle:${subTitle}` + '\n' + `body:${body}` + '\n' + `options:${typeof opts === "object" ? JSON.stringify(opts) : opts}`);
|
|
|
if (env.isSurge) {
|
|
if (env.isSurge) {
|
|
|
$notification.post(title, subTitle, body, opts);
|
|
$notification.post(title, subTitle, body, opts);
|
|
|
} else if (env.isLoon) {
|
|
} else if (env.isLoon) {
|
|
@@ -1183,7 +1243,7 @@ function MagicNotification(scriptName, env, logger, http) {
|
|
|
},
|
|
},
|
|
|
body: {
|
|
body: {
|
|
|
title: title,
|
|
title: title,
|
|
|
- body: subTitle ? `${subTitle}`+'\n'+`${body}` : body,
|
|
|
|
|
|
|
+ body: subTitle ? `${subTitle}` + '\n' + `${body}` : body,
|
|
|
device_key: _barkKey
|
|
device_key: _barkKey
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -1302,7 +1362,7 @@ function MagicQingLong(env, data, logger) {
|
|
|
function readQingLongConfig(config) {
|
|
function readQingLongConfig(config) {
|
|
|
qlUrl = qlUrl || data.read("magic_qlurl");
|
|
qlUrl = qlUrl || data.read("magic_qlurl");
|
|
|
qlToken = qlToken || data.read("magic_qltoken");
|
|
qlToken = qlToken || data.read("magic_qltoken");
|
|
|
- logger.debug(`QingLong url: ${qlUrl}`+'\n'+`QingLong token: ${qlToken}`);
|
|
|
|
|
|
|
+ logger.debug(`QingLong url: ${qlUrl}` + '\n' + `QingLong token: ${qlToken}`);
|
|
|
return config;
|
|
return config;
|
|
|
}
|
|
}
|
|
|
function setBaseUrlAndTimeout(config) {
|
|
function setBaseUrlAndTimeout(config) {
|
|
@@ -1399,7 +1459,7 @@ function MagicQingLong(env, data, logger) {
|
|
|
throw new Error("Get QingLong Panel token failed.");
|
|
throw new Error("Get QingLong Panel token failed.");
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error logging in to QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error logging in to QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
} else if (qlUrl && qlName && qlPwd) {
|
|
} else if (qlUrl && qlName && qlPwd) {
|
|
|
await http.post({
|
|
await http.post({
|
|
@@ -1416,7 +1476,7 @@ function MagicQingLong(env, data, logger) {
|
|
|
qlToken = resp.body.data.token;
|
|
qlToken = resp.body.data.token;
|
|
|
data.write("magic_qltoken", qlToken);
|
|
data.write("magic_qltoken", qlToken);
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error logging in to QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error logging in to QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
return qlToken;
|
|
return qlToken;
|
|
@@ -1424,10 +1484,10 @@ function MagicQingLong(env, data, logger) {
|
|
|
async function setEnv(name, value, id = null) {
|
|
async function setEnv(name, value, id = null) {
|
|
|
qlUrl = qlUrl || data.read("magic_qlurl");
|
|
qlUrl = qlUrl || data.read("magic_qlurl");
|
|
|
if (id === null) {
|
|
if (id === null) {
|
|
|
- let envIds = await setEnvs([ {
|
|
|
|
|
|
|
+ let envIds = await setEnvs([{
|
|
|
name: name,
|
|
name: name,
|
|
|
value: value
|
|
value: value
|
|
|
- } ]);
|
|
|
|
|
|
|
+ }]);
|
|
|
if (!!envIds && envIds.length === 1) {
|
|
if (!!envIds && envIds.length === 1) {
|
|
|
return envIds[0];
|
|
return envIds[0];
|
|
|
}
|
|
}
|
|
@@ -1444,13 +1504,13 @@ function MagicQingLong(env, data, logger) {
|
|
|
}
|
|
}
|
|
|
}).then(resp => {
|
|
}).then(resp => {
|
|
|
if (resp.body.code === 200) {
|
|
if (resp.body.code === 200) {
|
|
|
- logger.debug(`QINGLONG UPDATE ENV ${name} <${typeof value}> (${id})`+'\n'+`${JSON.stringify(value)}`);
|
|
|
|
|
|
|
+ logger.debug(`QINGLONG UPDATE ENV ${name} <${typeof value}> (${id})` + '\n' + `${JSON.stringify(value)}`);
|
|
|
return true;
|
|
return true;
|
|
|
} else {
|
|
} else {
|
|
|
- logger.error(`Error adding environment variable from QingLong Panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ logger.error(`Error adding environment variable from QingLong Panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error adding environment variable from QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error adding environment variable from QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
return false;
|
|
return false;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -1466,14 +1526,14 @@ function MagicQingLong(env, data, logger) {
|
|
|
}).then(resp => {
|
|
}).then(resp => {
|
|
|
if (resp.body.code === 200) {
|
|
if (resp.body.code === 200) {
|
|
|
resp.body.data.forEach(element => {
|
|
resp.body.data.forEach(element => {
|
|
|
- logger.debug(`QINGLONG ADD ENV ${element.name} <${typeof element.value}> (${element.id})`+'\n'+`${JSON.stringify(element)}`);
|
|
|
|
|
|
|
+ logger.debug(`QINGLONG ADD ENV ${element.name} <${typeof element.value}> (${element.id})` + '\n' + `${JSON.stringify(element)}`);
|
|
|
envIds.push(element.id);
|
|
envIds.push(element.id);
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
- logger.error(`Error adding environments variable from QingLong Panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ logger.error(`Error adding environments variable from QingLong Panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error adding environments variable from QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error adding environments variable from QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
return envIds;
|
|
return envIds;
|
|
|
}
|
|
}
|
|
@@ -1493,11 +1553,11 @@ function MagicQingLong(env, data, logger) {
|
|
|
logger.debug(`QINGLONG DELETE ENV IDS: ${ids}`);
|
|
logger.debug(`QINGLONG DELETE ENV IDS: ${ids}`);
|
|
|
return true;
|
|
return true;
|
|
|
} else {
|
|
} else {
|
|
|
- logger.error(`Error deleting environments variable from QingLong Panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ logger.error(`Error deleting environments variable from QingLong Panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error deleting environments variable from QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error deleting environments variable from QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
async function getEnvs(name = null, searchValue = "", retired = 0) {
|
|
async function getEnvs(name = null, searchValue = "", retired = 0) {
|
|
@@ -1524,10 +1584,10 @@ function MagicQingLong(env, data, logger) {
|
|
|
}
|
|
}
|
|
|
envs = allEnvs;
|
|
envs = allEnvs;
|
|
|
} else {
|
|
} else {
|
|
|
- throw new Error(`Error reading environment variable from QingLong Panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ throw new Error(`Error reading environment variable from QingLong Panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- throw new Error(`Error reading environments variable from QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ throw new Error(`Error reading environments variable from QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
return envs;
|
|
return envs;
|
|
|
}
|
|
}
|
|
@@ -1559,10 +1619,10 @@ function MagicQingLong(env, data, logger) {
|
|
|
logger.debug(`QINGLONG DISABLED ENV IDS: ${ids}`);
|
|
logger.debug(`QINGLONG DISABLED ENV IDS: ${ids}`);
|
|
|
result = true;
|
|
result = true;
|
|
|
} else {
|
|
} else {
|
|
|
- logger.error(`Error disabling environments variable from QingLong Panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ logger.error(`Error disabling environments variable from QingLong Panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error disabling environments variable from QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error disabling environments variable from QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -1583,10 +1643,10 @@ function MagicQingLong(env, data, logger) {
|
|
|
logger.debug(`QINGLONG ENABLED ENV IDS: ${ids}`);
|
|
logger.debug(`QINGLONG ENABLED ENV IDS: ${ids}`);
|
|
|
result = true;
|
|
result = true;
|
|
|
} else {
|
|
} else {
|
|
|
- logger.error(`Error enabling environments variable from Qilong panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ logger.error(`Error enabling environments variable from Qilong panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error enabling environments variable from Qilong panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error enabling environments variable from Qilong panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -1606,10 +1666,10 @@ function MagicQingLong(env, data, logger) {
|
|
|
if (resp.body.code === 200) {
|
|
if (resp.body.code === 200) {
|
|
|
result = true;
|
|
result = true;
|
|
|
} else {
|
|
} else {
|
|
|
- logger.error(`Error reading data from QingLong Panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ logger.error(`Error reading data from QingLong Panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error reading data from QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error reading data from QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -1624,10 +1684,10 @@ function MagicQingLong(env, data, logger) {
|
|
|
if (resp.body.code === 200) {
|
|
if (resp.body.code === 200) {
|
|
|
content = resp.body.data;
|
|
content = resp.body.data;
|
|
|
} else {
|
|
} else {
|
|
|
- throw new Error(`Error reading data from QingLong Panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ throw new Error(`Error reading data from QingLong Panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- throw new Error(`Error reading data from QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ throw new Error(`Error reading data from QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
return content;
|
|
return content;
|
|
|
}
|
|
}
|
|
@@ -1647,10 +1707,10 @@ function MagicQingLong(env, data, logger) {
|
|
|
if (resp.body.code === 200) {
|
|
if (resp.body.code === 200) {
|
|
|
result = true;
|
|
result = true;
|
|
|
} else {
|
|
} else {
|
|
|
- logger.error(`Error reading data from QingLong Panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ logger.error(`Error reading data from QingLong Panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error reading data from QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error reading data from QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -1669,10 +1729,10 @@ function MagicQingLong(env, data, logger) {
|
|
|
if (resp.body.code === 200) {
|
|
if (resp.body.code === 200) {
|
|
|
result = true;
|
|
result = true;
|
|
|
} else {
|
|
} else {
|
|
|
- logger.error(`Error reading data from QingLong Panel.`+'\n'+`${JSON.stringify(resp)}`);
|
|
|
|
|
|
|
+ logger.error(`Error reading data from QingLong Panel.` + '\n' + `${JSON.stringify(resp)}`);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- logger.error(`Error reading data from QingLong Panel.`+'\n'+`${err.message || err}`);
|
|
|
|
|
|
|
+ logger.error(`Error reading data from QingLong Panel.` + '\n' + `${err.message || err}`);
|
|
|
});
|
|
});
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|