t-comm
Version:
专业、稳定、纯粹的工具库
189 lines (186 loc) • 5.8 kB
JavaScript
import { b as __awaiter, c as __generator } from '../tslib.es6-096fffdd.js';
import { flatten } from '../list/flat.mjs';
import { timeStampFormat } from '../time/time.mjs';
import { batchSendWxRobotMarkdown } from '../wecom-robot/batch-send.mjs';
import { getCOSFilePath } from './helper/helper.mjs';
import '../wecom-robot/base.mjs';
import '../wecom-robot/helper.mjs';
import 'axios';
import '../wecom-robot/send-img.mjs';
import '../node-img/img.mjs';
import '../string/string.mjs';
import '../node/fs-util.mjs';
import 'fs';
import 'path';
import '../fs/fs.mjs';
import '../tencent-cloud/cos/link.mjs';
import './helper/value-type.mjs';
function isEqual(a, b) {
var wrapA = a;
var wrapB = b;
if (typeof a !== 'string') wrapA = JSON.stringify(a);
if (typeof a !== 'string') wrapB = JSON.stringify(b);
return wrapA === wrapB;
}
function getAllCOSFiles(_a) {
var flatNow = _a.flatNow,
appName = _a.appName,
secretInfo = _a.secretInfo,
cosInfo = _a.cosInfo;
var _b = secretInfo || {},
groupName = _b.groupName,
envName = _b.envName;
var notifyList = [">\u3010\u5F53\u524D\u4E03\u5F69\u77F3\u914D\u7F6E\u3011".concat(appName, "\xB7").concat(groupName, "\xB7").concat(envName)];
var keys = Object.keys(flatNow);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var params = {
appName: appName,
groupName: groupName,
envName: envName,
key: key,
valueType: flatNow[key].valueType,
cosInfo: cosInfo
};
notifyList.push("".concat(i + 1, ". [").concat(key, "](").concat(getCOSFilePath(params), ")"));
}
return notifyList;
}
function getOnlyChangedCOSFiles(_a) {
var flatNow = _a.flatNow,
flatOrigin = _a.flatOrigin,
appName = _a.appName,
secretInfo = _a.secretInfo,
cosInfo = _a.cosInfo;
var _b = secretInfo || {},
groupName = _b.groupName,
envName = _b.envName;
var notifyList = [];
var addList = [];
var updateList = [];
var deleteList = [];
Object.keys(flatNow).forEach(function (key) {
var params = {
appName: appName,
groupName: groupName,
envName: envName,
key: key,
valueType: flatNow[key].valueType,
cosInfo: cosInfo
};
if (!flatOrigin[key]) {
addList.push("[".concat(key, "](").concat(getCOSFilePath(params), ")"));
} else if (!isEqual(flatOrigin[key].value, flatNow[key].value)) {
updateList.push("[".concat(key, "](").concat(getCOSFilePath(params), ")"));
}
});
Object.keys(flatOrigin).forEach(function (key) {
if (!flatNow[key]) {
var params = {
appName: appName,
groupName: groupName,
envName: envName,
key: key,
valueType: flatOrigin[key].valueType,
cosInfo: cosInfo
};
deleteList.push("[".concat(key, "](").concat(getCOSFilePath(params), ")"));
}
});
if (addList.length) {
notifyList.push("\u65B0\u589E\u4E86\uFF1A".concat(addList.join(',')));
}
if (updateList.length) {
notifyList.push("\u66F4\u65B0\u4E86\uFF1A".concat(updateList.join(',')));
}
if (deleteList.length) {
notifyList.push("\u5220\u9664\u4E86\uFF1A".concat(deleteList.join(',')));
}
if (!notifyList.length) {
return [];
}
notifyList = notifyList.map(function (value, idx) {
return "".concat(idx + 1, ". ").concat(value);
});
notifyList.unshift(">\u3010\u4E03\u5F69\u77F3\u914D\u7F6E\u66F4\u65B0\u3011".concat(appName, "\xB7").concat(groupName, "\xB7").concat(envName));
notifyList.push("".concat(timeStampFormat(Date.now(), 'yyyy-MM-dd: hh:mm:ss')));
return notifyList;
}
function genRobotMsg(_a) {
var newConfig = _a.newConfig,
originConfig = _a.originConfig,
secretInfo = _a.secretInfo,
appName = _a.appName,
cosInfo = _a.cosInfo,
_b = _a.isGenAll,
isGenAll = _b === void 0 ? false : _b;
var flatNow = flatten(newConfig, 'key');
var flatOrigin = flatten(originConfig, 'key');
var notifyList = [];
if (isGenAll) {
notifyList = getAllCOSFiles({
flatNow: flatNow,
appName: appName,
secretInfo: secretInfo,
cosInfo: cosInfo
});
} else {
notifyList = getOnlyChangedCOSFiles({
flatNow: flatNow,
flatOrigin: flatOrigin,
appName: appName,
secretInfo: secretInfo,
cosInfo: cosInfo
});
}
return notifyList.join('\n');
}
function sendRainbowInfoToRobot(_a) {
var newConfig = _a.newConfig,
originConfig = _a.originConfig,
secretInfo = _a.secretInfo,
cosInfo = _a.cosInfo,
appName = _a.appName,
_b = _a.isGenAll,
isGenAll = _b === void 0 ? false : _b,
chatId = _a.chatId,
webhookUrl = _a.webhookUrl;
return __awaiter(this, void 0, void 0, function () {
var chatContent, err_1;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
chatContent = genRobotMsg({
newConfig: newConfig,
originConfig: originConfig,
secretInfo: secretInfo,
appName: appName,
cosInfo: cosInfo,
isGenAll: isGenAll
});
if (!chatContent) {
console.log('[sendRainbowInfoToRobot] Error: chatContent 为空');
return [2 /*return*/];
}
_c.label = 1;
case 1:
_c.trys.push([1, 3,, 4]);
return [4 /*yield*/, batchSendWxRobotMarkdown({
chatId: chatId,
content: chatContent,
webhookUrl: webhookUrl
})];
case 2:
_c.sent();
return [3 /*break*/, 4];
case 3:
err_1 = _c.sent();
console.log('[sendRainbowInfoToRobot] err: \n', err_1);
return [3 /*break*/, 4];
case 4:
return [2 /*return*/];
}
});
});
}
export { sendRainbowInfoToRobot };