deployhub
Version:
一站式前端多平台部署工具,支持FTP、OSS、TOS、COS等多种部署方式。
27 lines (25 loc) • 976 B
JavaScript
const COS = require('cos-nodejs-sdk-v5');
/**
* 使用 COS 上传文件
* @param {Object} config - COS 配置
* @param {string} localFilePath - 本地文件路径
* @param {string} remoteFilePath - 远程文件路径
* @param {number} currentFileIndex - 当前文件索引
* @param {number} totalFiles - 总文件数
* @returns {Promise<void>}
*/
async function uploadViaCOS(config, localFilePath, remoteFilePath, currentFileIndex, totalFiles) {
const client = new COS(config);
try {
process.stdout.write(`\r[COS] ${currentFileIndex + 1}/${totalFiles} [${localFilePath}]`);
await client.putObject({
Bucket: config.Bucket,
Region: config.Region,
Key: remoteFilePath,
Body: require('fs').createReadStream(localFilePath)
});
} catch (error) {
console.error(`\n[COS] 文件上传失败: ${localFilePath}`, error);
}
}
module.exports = uploadViaCOS;