UNPKG

t-comm

Version:

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

96 lines (93 loc) 2.66 kB
import { b as __awaiter, c as __generator, _ as __assign } from '../tslib.es6-096fffdd.js'; import { writeFileSync } from '../fs/fs.mjs'; import { uploadCOSFile } from '../tencent-cloud/cos/cos.mjs'; import 'fs'; import { getSavePath, getSaveFileName } from './helper/helper.mjs'; import '../tencent-cloud/cos/helper.mjs'; import '../bite/format-bite.mjs'; import '../string/string.mjs'; import '../node/fs-util.mjs'; import 'path'; import '../time/time.mjs'; import '../tencent-cloud/cos/link.mjs'; import './helper/value-type.mjs'; function pushCOSFiles(list) { var files = list.map(function (item) { return { key: item.cosKey, path: item.savePath }; }); return files; } function getCOSKeyAndSavePath(_a) { var configList = _a.configList, secretInfo = _a.secretInfo, appName = _a.appName, cosDir = _a.cosDir; var _b = secretInfo || {}, groupName = _b.groupName, envName = _b.envName; return configList.map(function (config) { var key = config.key, valueType = config.valueType; var savePath = getSavePath({ appName: appName, groupName: groupName, envName: envName, key: key, valueType: valueType }); var saveFileName = getSaveFileName({ appName: appName, groupName: groupName, envName: envName, key: key, valueType: valueType }); return __assign(__assign({}, config), { cosKey: "".concat(cosDir, "/").concat(saveFileName), savePath: savePath }); }); } function removeTmpFiles(cosKeyList) { var fs = require('fs'); cosKeyList.forEach(function (item) { fs.unlinkSync(item.savePath); }); } function syncRainbowToCOS(_a) { var configList = _a.configList, secretInfo = _a.secretInfo, appName = _a.appName, cosInfo = _a.cosInfo; return __awaiter(this, void 0, void 0, function () { var cosKeyList, files; return __generator(this, function (_b) { switch (_b.label) { case 0: cosKeyList = getCOSKeyAndSavePath({ configList: configList, secretInfo: secretInfo, appName: appName, cosDir: cosInfo.dir }); cosKeyList.forEach(function (item) { writeFileSync(item.savePath, item.value); }); files = pushCOSFiles(cosKeyList); return [4 /*yield*/, uploadCOSFile(__assign({ files: files }, cosInfo))]; case 1: _b.sent(); return [4 /*yield*/, removeTmpFiles(cosKeyList)]; case 2: _b.sent(); return [2 /*return*/]; } }); }); } export { syncRainbowToCOS };