Skip to content

Commit

Permalink
[feat] 로직변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jainefer committed Nov 14, 2024
1 parent bf282e2 commit f8bef0f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/services/storage.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,36 @@ export const uploadStreamToStorage = (stream, fileName) => {
});
});
};
export const readFileFromObjectStorage = async (bucketName, objectKey) => {

const params = {
Bucket: bucketName,
Key: objectKey
};

try {
const data = await s3.getObject(params).promise();
return JSON.parse(data.Body.toString('utf-8'));
} catch (error) {
console.error('Error in reading file from storage:', error);
throw error;
}
};
export const getScriptFileName = async (bucketName, videoId) => {
const params = {
Bucket: bucketName,
Prefix: `${process.env.OBJECT_STORAGE_BUCKET_NAME}:${videoId}.mp3`
};

try {
const data = await s3.listObjectsV2(params).promise();
const scriptFile = data.Contents.find(file => file.Key.endsWith('.json'));
return scriptFile ? scriptFile.Key : null;
} catch (error) {
console.error('Error in getting script file name:', error);
throw error;
}
};
// S3에서 파일 존재 여부 확인
export const checkFileExistsInStorage = async (bucketName, fileNamePrefix) => {
const params = {
Expand Down

0 comments on commit f8bef0f

Please sign in to comment.