优化体验,新增多项功能,美化界面
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* 本地开发环境:使用 AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
|
||||
* 正式环境:通过 IAM 角色访问 S3(无需配置密钥)
|
||||
*/
|
||||
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
|
||||
const { S3Client, PutObjectCommand, GetObjectCommand } = require('@aws-sdk/client-s3');
|
||||
const logger = require('../config/logger');
|
||||
|
||||
const AWS_REGION = process.env.AWS_REGION || 'eu-central-1';
|
||||
@@ -79,7 +79,36 @@ async function uploadMeasurementToS3(buffer, params) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 S3 读取频响 CSV 文件
|
||||
* @param {object} params - 路径参数(同 buildMeasurementKey)
|
||||
* @returns {Promise<{ key: string, content: string }>}
|
||||
*/
|
||||
async function getMeasurementFromS3(params) {
|
||||
const key = buildMeasurementKey(params);
|
||||
const client = getS3Client();
|
||||
|
||||
try {
|
||||
const response = await client.send(
|
||||
new GetObjectCommand({
|
||||
Bucket: S3_BUCKET,
|
||||
Key: key,
|
||||
})
|
||||
);
|
||||
const content = await response.Body.transformToString('utf-8');
|
||||
logger.info(`Measurement read from s3://${S3_BUCKET}/${key}`);
|
||||
return { key, content };
|
||||
} catch (e) {
|
||||
if (e.name === 'NoSuchKey' || e.$metadata?.httpStatusCode === 404) {
|
||||
throw new Error('S3 上未找到该型号的频响文件');
|
||||
}
|
||||
logger.error(`S3 measurement read failed: ${e.message}`);
|
||||
throw new Error(`S3 读取失败:${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
uploadMeasurementToS3,
|
||||
getMeasurementFromS3,
|
||||
buildMeasurementKey,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user