UNPKG

@raihan0824/mcp-veo2

Version:

MCP server for generating videos with Google Veo2

80 lines 2.73 kB
import AWS from 'aws-sdk'; import config from '../config.js'; import { log } from '../utils/logger.js'; import fs from 'fs/promises'; import path from 'path'; class S3Service { s3; bucket; constructor() { if (!config.USE_S3) { throw new Error('S3 service initialized but USE_S3 is not enabled'); } // Configure AWS SDK AWS.config.update({ accessKeyId: config.S3_ACCESS_KEY, secretAccessKey: config.S3_SECRET_KEY, region: config.S3_REGION, }); this.s3 = new AWS.S3({ endpoint: config.S3_ENDPOINT, s3ForcePathStyle: true, // Needed for custom S3-compatible services }); this.bucket = config.S3_BUCKET; log.info(`S3 service initialized with endpoint: ${config.S3_ENDPOINT}, bucket: ${this.bucket}`); } /** * Upload a file to S3 */ async uploadFile(localFilePath, s3Key) { try { const fileContent = await fs.readFile(localFilePath); const fileExtension = path.extname(localFilePath); // Determine content type based on file extension let contentType = 'application/octet-stream'; if (fileExtension === '.mp4') { contentType = 'video/mp4'; } else if (fileExtension === '.json') { contentType = 'application/json'; } const uploadParams = { Bucket: this.bucket, Key: s3Key, Body: fileContent, ContentType: contentType, ACL: 'public-read', // Make the file publicly accessible }; log.info(`Uploading file to S3: ${s3Key}`); const result = await this.s3.upload(uploadParams).promise(); log.info(`File uploaded successfully to S3: ${result.Location}`); return result.Location; } catch (error) { log.error(`Error uploading file to S3:`, error); throw new Error(`Failed to upload file to S3: ${error}`); } } /** * Generate a public URL for an S3 object */ getPublicUrl(s3Key) { return `${config.S3_ENDPOINT}/${this.bucket}/${s3Key}`; } /** * Check if S3 connection is working */ async testConnection() { try { await this.s3.headBucket({ Bucket: this.bucket }).promise(); log.info('S3 connection test successful'); return true; } catch (error) { log.error('S3 connection test failed:', error); return false; } } } export default S3Service; //# sourceMappingURL=s3Service.js.map