UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

197 lines (194 loc) 6.34 kB
import _regeneratorRuntime from '@babel/runtime/regenerator'; import { _ as __awaiter } from '../tslib.es6-848120af.js'; import { flatten } from '../list/flat.mjs'; import '@babel/runtime/helpers/toConsumableArray'; 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 '../nodejs/crypto.mjs'; import '../nodejs/fs.mjs'; import '../nodejs/request.mjs'; import '../nodejs/path.mjs'; import '../string/string.mjs'; import '../fs/fs-util.mjs'; import '../fs/fs.mjs'; import '../nodejs/os.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(_ref) { var flatNow = _ref.flatNow, appName = _ref.appName, secretInfo = _ref.secretInfo, cosInfo = _ref.cosInfo; var _ref2 = secretInfo || {}, groupName = _ref2.groupName, envName = _ref2.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(_ref3) { var flatNow = _ref3.flatNow, flatOrigin = _ref3.flatOrigin, appName = _ref3.appName, secretInfo = _ref3.secretInfo, cosInfo = _ref3.cosInfo; var _ref4 = secretInfo || {}, groupName = _ref4.groupName, envName = _ref4.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(_ref5) { var newConfig = _ref5.newConfig, originConfig = _ref5.originConfig, secretInfo = _ref5.secretInfo, appName = _ref5.appName, cosInfo = _ref5.cosInfo, _ref5$isGenAll = _ref5.isGenAll, isGenAll = _ref5$isGenAll === void 0 ? false : _ref5$isGenAll; 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(_ref6) { var newConfig = _ref6.newConfig, originConfig = _ref6.originConfig, secretInfo = _ref6.secretInfo, cosInfo = _ref6.cosInfo, appName = _ref6.appName, _ref6$isGenAll = _ref6.isGenAll, isGenAll = _ref6$isGenAll === void 0 ? false : _ref6$isGenAll, chatId = _ref6.chatId, webhookUrl = _ref6.webhookUrl; return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var chatContent, _t; return _regeneratorRuntime.wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: chatContent = genRobotMsg({ newConfig: newConfig, originConfig: originConfig, secretInfo: secretInfo, appName: appName, cosInfo: cosInfo, isGenAll: isGenAll }); if (chatContent) { _context.next = 1; break; } console.log('[sendRainbowInfoToRobot] Error: chatContent 为空'); return _context.abrupt("return"); case 1: _context.prev = 1; _context.next = 2; return batchSendWxRobotMarkdown({ chatId: chatId, content: chatContent, webhookUrl: webhookUrl }); case 2: _context.next = 4; break; case 3: _context.prev = 3; _t = _context["catch"](1); console.log('[sendRainbowInfoToRobot] err: \n', _t); case 4: case "end": return _context.stop(); } }, _callee, null, [[1, 3]]); })); } export { sendRainbowInfoToRobot };