UNPKG

t-comm

Version:

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

193 lines (188 loc) 6.07 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib_es6 = require('../tslib.es6-01322ba9.js'); var time_time = require('../time/time.js'); var wecomRobot_batchSend = require('../wecom-robot/batch-send.js'); var rainbowToCos_helper_helper = require('./helper/helper.js'); var list_flat = require('../list/flat.js'); require('../wecom-robot/base.js'); require('../wecom-robot/helper.js'); require('axios'); require('../wecom-robot/send-img.js'); require('../node-img/img.js'); require('../node/fs-util.js'); require('fs'); require('path'); require('../fs/fs.js'); require('../tencent-cloud/cos/link.js'); require('./helper/value-type.js'); require('../string/string.js'); 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(rainbowToCos_helper_helper.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(rainbowToCos_helper_helper.getCOSFilePath(params), ")")); } else if (!isEqual(flatOrigin[key].value, flatNow[key].value)) { updateList.push("[".concat(key, "](").concat(rainbowToCos_helper_helper.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(rainbowToCos_helper_helper.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(time_time.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 = list_flat.flatten(newConfig, 'key'); var flatOrigin = list_flat.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 tslib_es6.__awaiter(this, void 0, void 0, function () { var chatContent, err_1; return tslib_es6.__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*/, wecomRobot_batchSend.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*/]; } }); }); } exports.sendRainbowInfoToRobot = sendRainbowInfoToRobot;