Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions fileUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -15,8 +15,8 @@ const config = {
awsAccessKeyId: '',
awsSecretAccessKey: '',
awsSessionToken: '',
bucketName: 'migartion-test',
buketKey: 'project/package 45.zip'
bucketName: '',
bucketKey: ''
},
localPath: null
};
Expand Down
4 changes: 2 additions & 2 deletions upload-api/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion upload-api/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Config {
awsSecretAccessKey: string;
awsSessionToken: string;
bucketName: string;
buketKey: string;
bucketKey: string;
};
localPath: string;
}
98 changes: 49 additions & 49 deletions upload-api/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ 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`);
createMapper(filePath, projectId, app_token, affix, config);
}
});
}
else{
else {
// Create a writable stream to save the downloaded zip file
let zipBuffer = Buffer.alloc(0);

Expand All @@ -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);
}
Expand Down
Loading