UNPKG

t-comm

Version:

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

71 lines (68 loc) 2.03 kB
import { hyphenate } from '../../string/string.mjs'; import { getJsonLogDir, readJsonLog } from '../../node/fs-util.mjs'; import { getCosUrlLink } from '../../tencent-cloud/cos/link.mjs'; import { RAINBOW_VALUE_TYPE_MAP } from './value-type.mjs'; import 'fs'; import 'path'; import '../../fs/fs.mjs'; import '../../time/time.mjs'; /* eslint-disable @typescript-eslint/no-require-imports */ function getSaveFileName(_a) { var _b; var appName = _a.appName, groupName = _a.groupName, envName = _a.envName, key = _a.key, valueType = _a.valueType; var ext = ((_b = RAINBOW_VALUE_TYPE_MAP[valueType]) === null || _b === void 0 ? void 0 : _b.ext) || 'txt'; return "".concat(hyphenate(appName), "__").concat(hyphenate(groupName), "__").concat(hyphenate(envName), "__").concat(key, ".").concat(ext); } function getSavePath(_a) { var appName = _a.appName, groupName = _a.groupName, envName = _a.envName, key = _a.key, valueType = _a.valueType; var path = require('path'); return path.resolve(getJsonLogDir(), getSaveFileName({ appName: appName, groupName: groupName, envName: envName, key: key, valueType: valueType })); } function getCOSFilePath(_a) { var appName = _a.appName, groupName = _a.groupName, envName = _a.envName, key = _a.key, valueType = _a.valueType, cosInfo = _a.cosInfo; var saveFileName = getSaveFileName({ appName: appName, groupName: groupName, envName: envName, key: key, valueType: valueType }); var bucket = cosInfo.bucket, region = cosInfo.region, dir = cosInfo.dir; return getCosUrlLink({ bucket: bucket, region: region, dir: dir, fileName: saveFileName }); } var readCOSConfig = function readCOSConfig(saveFileName) { var content = []; try { content = JSON.parse(readJsonLog(saveFileName, '[]')); } catch (err) { console.log('[readCOSConfig] err: \n', err); } return content; }; export { getCOSFilePath, getSaveFileName, getSavePath, readCOSConfig };