diff --git a/fileUpdate.js b/fileUpdate.js index 8753a34a7..c2ed857b7 100644 --- a/fileUpdate.js +++ b/fileUpdate.js @@ -3,7 +3,7 @@ const path = require('path'); const { cliux, messageHandler } = require('@contentstack/cli-utilities'); const isEmpty = (value) => value === null || value === undefined || (typeof value === 'object' && Object.keys(value).length === 0) || - (typeof value === 'string' && value.trim().length === 0);; + (typeof value === 'string' && value.trim().length === 0); const config = { plan: { dropdown: { optionLimit: 100 } @@ -15,8 +15,8 @@ const config = { awsAccessKeyId: '', awsSecretAccessKey: '', awsSessionToken: '', - bucketName: 'migartion-test', - buketKey: 'project/package 45.zip' + bucketName: '', + bucketKey: '' }, localPath: null }; diff --git a/upload-api/src/config/index.ts b/upload-api/src/config/index.ts index a3e627499..ee1d411a1 100644 --- a/upload-api/src/config/index.ts +++ b/upload-api/src/config/index.ts @@ -9,8 +9,8 @@ export default { awsAccessKeyId: '', awsSecretAccessKey: '', awsSessionToken: '', - bucketName: 'migartion-test', - buketKey: 'project/package 45.zip' + bucketName: '', + bucketKey: '' }, // localPath: '/Users/sayali.joshi/Downloads/contentfulDummyEmbedData.json' //package 45.zip' localPath: '/Users/umesh.more/Documents/ui-migration/migration-v2-node-server/upload-api/extracted_files/package 45.zip' diff --git a/upload-api/src/models/types.ts b/upload-api/src/models/types.ts index c86ca5ca2..2492a9b94 100644 --- a/upload-api/src/models/types.ts +++ b/upload-api/src/models/types.ts @@ -12,7 +12,7 @@ export interface Config { awsSecretAccessKey: string; awsSessionToken: string; bucketName: string; - buketKey: string; + bucketKey: string; }; localPath: string; } diff --git a/upload-api/src/routes/index.ts b/upload-api/src/routes/index.ts index 2d6c91b80..8ef1cb7bb 100644 --- a/upload-api/src/routes/index.ts +++ b/upload-api/src/routes/index.ts @@ -136,7 +136,7 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r throw new Error('No data collected from the stream.'); } - const data = await handleFileProcessing(fileExt, xmlData, cmsType,name); + const data = await handleFileProcessing(fileExt, xmlData, cmsType, name); res.status(data?.status || 200).json(data); if (data?.status === 200) { const filePath = path.join(__dirname, '..', '..', 'extracted_files', `${name}.json`); @@ -144,7 +144,7 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r } }); } - else{ + else { // Create a writable stream to save the downloaded zip file let zipBuffer = Buffer.alloc(0); @@ -162,67 +162,67 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r if (!zipBuffer) { throw new Error('No data collected from the stream.'); } - const data = await handleFileProcessing(fileExt, zipBuffer, cmsType,name); + const data = await handleFileProcessing(fileExt, zipBuffer, cmsType, name); res.status(data?.status || 200).json(data); if (data?.status === 200) { const filePath = path.join(__dirname, '..', '..', 'extracted_files', name); createMapper(filePath, projectId, app_token, affix, config); } }); - } - } - }else { - const params = { - Bucket: config?.awsData?.bucketName, - Key: config?.awsData?.buketKey - }; - const getObjectCommand = new GetObjectCommand(params); - // Get the object from S3 - const s3File = await client.send(getObjectCommand); - //file Name From key - const fileName = params?.Key?.split?.('/')?.pop?.() ?? ''; - //file ext from fileName - const fileExt = fileName?.split?.('.')?.pop?.() ?? 'test'; - - if (!s3File?.Body) { - throw new Error('Empty response body from S3'); - } + } + } + } else { + const params = { + Bucket: config?.awsData?.bucketName, + Key: config?.awsData?.bucketKey + }; + const getObjectCommand = new GetObjectCommand(params); + // Get the object from S3 + const s3File = await client.send(getObjectCommand); + //file Name From key + const fileName = params?.Key?.split?.('/')?.pop?.() ?? ''; + //file ext from fileName + const fileExt = fileName?.split?.('.')?.pop?.() ?? 'test'; + + if (!s3File?.Body) { + throw new Error('Empty response body from S3'); + } - const bodyStream: Readable = s3File?.Body as Readable; + const bodyStream: Readable = s3File?.Body as Readable; - // Create a writable stream to save the downloaded zip file - const zipFileStream = createWriteStream(`${fileName}`); + // Create a writable stream to save the downloaded zip file + const zipFileStream = createWriteStream(`${fileName}`); - // // Pipe the S3 object's body to the writable stream - bodyStream.pipe(zipFileStream); + // // Pipe the S3 object's body to the writable stream + bodyStream.pipe(zipFileStream); - // Create a writable stream to save the downloaded zip file - let zipBuffer: Buffer | null = null; + // Create a writable stream to save the downloaded zip file + let zipBuffer: Buffer | null = null; - // Collect the data from the stream into a buffer - bodyStream.on('data', (chunk) => { - if (zipBuffer === null) { - zipBuffer = chunk; - } else { - zipBuffer = Buffer.concat([zipBuffer, chunk]); - } - }); + // Collect the data from the stream into a buffer + bodyStream.on('data', (chunk) => { + if (zipBuffer === null) { + zipBuffer = chunk; + } else { + zipBuffer = Buffer.concat([zipBuffer, chunk]); + } + }); - //buffer fully stremd - bodyStream.on('end', async () => { - if (!zipBuffer) { - throw new Error('No data collected from the stream.'); - } + //buffer fully stremd + bodyStream.on('end', async () => { + if (!zipBuffer) { + throw new Error('No data collected from the stream.'); + } - const data = await handleFileProcessing(fileExt, zipBuffer, cmsType,fileName); - res.json(data); - res.send('file valited sucessfully.'); - const filePath = path.join(__dirname, '..', '..', 'extracted_files', fileName); - console.log("🚀 ~ bodyStream.on ~ filePath:", filePath) - createMapper(filePath, projectId, app_token, affix, config); - }); + const data = await handleFileProcessing(fileExt, zipBuffer, cmsType, fileName); + res.json(data); + res.send('file valited sucessfully.'); + const filePath = path.join(__dirname, '..', '..', 'extracted_files', fileName); + console.log("🚀 ~ bodyStream.on ~ filePath:", filePath) + createMapper(filePath, projectId, app_token, affix, config); + }); + } } -} catch (err: any) { console.error('🚀 ~ router.get ~ err:', err); }