Skip to content

Commit ef89655

Browse files
Merge pull request #584 from contentstack/feature/mac-setup-v2
code review changes
2 parents d66c66a + 6d80a84 commit ef89655

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
lines changed

fileUpdate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require('path');
33
const { cliux, messageHandler } = require('@contentstack/cli-utilities');
44
const isEmpty = (value) => value === null || value === undefined ||
55
(typeof value === 'object' && Object.keys(value).length === 0) ||
6-
(typeof value === 'string' && value.trim().length === 0);;
6+
(typeof value === 'string' && value.trim().length === 0);
77
const config = {
88
plan: {
99
dropdown: { optionLimit: 100 }
@@ -15,8 +15,8 @@ const config = {
1515
awsAccessKeyId: '',
1616
awsSecretAccessKey: '',
1717
awsSessionToken: '',
18-
bucketName: 'migartion-test',
19-
buketKey: 'project/package 45.zip'
18+
bucketName: '',
19+
bucketKey: ''
2020
},
2121
localPath: null
2222
};

upload-api/src/config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default {
99
awsAccessKeyId: '',
1010
awsSecretAccessKey: '',
1111
awsSessionToken: '',
12-
bucketName: 'migartion-test',
13-
buketKey: 'project/package 45.zip'
12+
bucketName: '',
13+
bucketKey: ''
1414
},
1515
// localPath: '/Users/sayali.joshi/Downloads/contentfulDummyEmbedData.json' //package 45.zip'
1616
localPath: '/Users/umesh.more/Documents/ui-migration/migration-v2-node-server/upload-api/extracted_files/package 45.zip'

upload-api/src/models/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface Config {
1212
awsSecretAccessKey: string;
1313
awsSessionToken: string;
1414
bucketName: string;
15-
buketKey: string;
15+
bucketKey: string;
1616
};
1717
localPath: string;
1818
}

upload-api/src/routes/index.ts

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
136136
throw new Error('No data collected from the stream.');
137137
}
138138

139-
const data = await handleFileProcessing(fileExt, xmlData, cmsType,name);
139+
const data = await handleFileProcessing(fileExt, xmlData, cmsType, name);
140140
res.status(data?.status || 200).json(data);
141141
if (data?.status === 200) {
142142
const filePath = path.join(__dirname, '..', '..', 'extracted_files', `${name}.json`);
143143
createMapper(filePath, projectId, app_token, affix, config);
144144
}
145145
});
146146
}
147-
else{
147+
else {
148148
// Create a writable stream to save the downloaded zip file
149149
let zipBuffer = Buffer.alloc(0);
150150

@@ -162,67 +162,67 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
162162
if (!zipBuffer) {
163163
throw new Error('No data collected from the stream.');
164164
}
165-
const data = await handleFileProcessing(fileExt, zipBuffer, cmsType,name);
165+
const data = await handleFileProcessing(fileExt, zipBuffer, cmsType, name);
166166
res.status(data?.status || 200).json(data);
167167
if (data?.status === 200) {
168168
const filePath = path.join(__dirname, '..', '..', 'extracted_files', name);
169169
createMapper(filePath, projectId, app_token, affix, config);
170170
}
171171
});
172-
}
173-
}
174-
}else {
175-
const params = {
176-
Bucket: config?.awsData?.bucketName,
177-
Key: config?.awsData?.buketKey
178-
};
179-
const getObjectCommand = new GetObjectCommand(params);
180-
// Get the object from S3
181-
const s3File = await client.send(getObjectCommand);
182-
//file Name From key
183-
const fileName = params?.Key?.split?.('/')?.pop?.() ?? '';
184-
//file ext from fileName
185-
const fileExt = fileName?.split?.('.')?.pop?.() ?? 'test';
186-
187-
if (!s3File?.Body) {
188-
throw new Error('Empty response body from S3');
189-
}
172+
}
173+
}
174+
} else {
175+
const params = {
176+
Bucket: config?.awsData?.bucketName,
177+
Key: config?.awsData?.bucketKey
178+
};
179+
const getObjectCommand = new GetObjectCommand(params);
180+
// Get the object from S3
181+
const s3File = await client.send(getObjectCommand);
182+
//file Name From key
183+
const fileName = params?.Key?.split?.('/')?.pop?.() ?? '';
184+
//file ext from fileName
185+
const fileExt = fileName?.split?.('.')?.pop?.() ?? 'test';
186+
187+
if (!s3File?.Body) {
188+
throw new Error('Empty response body from S3');
189+
}
190190

191-
const bodyStream: Readable = s3File?.Body as Readable;
191+
const bodyStream: Readable = s3File?.Body as Readable;
192192

193-
// Create a writable stream to save the downloaded zip file
194-
const zipFileStream = createWriteStream(`${fileName}`);
193+
// Create a writable stream to save the downloaded zip file
194+
const zipFileStream = createWriteStream(`${fileName}`);
195195

196-
// // Pipe the S3 object's body to the writable stream
197-
bodyStream.pipe(zipFileStream);
196+
// // Pipe the S3 object's body to the writable stream
197+
bodyStream.pipe(zipFileStream);
198198

199-
// Create a writable stream to save the downloaded zip file
200-
let zipBuffer: Buffer | null = null;
199+
// Create a writable stream to save the downloaded zip file
200+
let zipBuffer: Buffer | null = null;
201201

202-
// Collect the data from the stream into a buffer
203-
bodyStream.on('data', (chunk) => {
204-
if (zipBuffer === null) {
205-
zipBuffer = chunk;
206-
} else {
207-
zipBuffer = Buffer.concat([zipBuffer, chunk]);
208-
}
209-
});
202+
// Collect the data from the stream into a buffer
203+
bodyStream.on('data', (chunk) => {
204+
if (zipBuffer === null) {
205+
zipBuffer = chunk;
206+
} else {
207+
zipBuffer = Buffer.concat([zipBuffer, chunk]);
208+
}
209+
});
210210

211-
//buffer fully stremd
212-
bodyStream.on('end', async () => {
213-
if (!zipBuffer) {
214-
throw new Error('No data collected from the stream.');
215-
}
211+
//buffer fully stremd
212+
bodyStream.on('end', async () => {
213+
if (!zipBuffer) {
214+
throw new Error('No data collected from the stream.');
215+
}
216216

217-
const data = await handleFileProcessing(fileExt, zipBuffer, cmsType,fileName);
218-
res.json(data);
219-
res.send('file valited sucessfully.');
220-
const filePath = path.join(__dirname, '..', '..', 'extracted_files', fileName);
221-
console.log("🚀 ~ bodyStream.on ~ filePath:", filePath)
222-
createMapper(filePath, projectId, app_token, affix, config);
223-
});
217+
const data = await handleFileProcessing(fileExt, zipBuffer, cmsType, fileName);
218+
res.json(data);
219+
res.send('file valited sucessfully.');
220+
const filePath = path.join(__dirname, '..', '..', 'extracted_files', fileName);
221+
console.log("🚀 ~ bodyStream.on ~ filePath:", filePath)
222+
createMapper(filePath, projectId, app_token, affix, config);
223+
});
224+
}
224225
}
225-
}
226226
catch (err: any) {
227227
console.error('🚀 ~ router.get ~ err:', err);
228228
}

0 commit comments

Comments
 (0)