From eeed28c1dec8899d45623b4cc9da8be436f2fa14 Mon Sep 17 00:00:00 2001 From: gitadmin Date: Thu, 25 Sep 2025 06:35:27 +0000 Subject: [PATCH] Update 'src/index.js' --- src/index.js | 86 ++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/index.js b/src/index.js index 1f0a6baf..24e5272d 100644 --- a/src/index.js +++ b/src/index.js @@ -981,7 +981,7 @@ const mime = require("mime-types"); // } // }); -fastify.register(upload.contentParser); +// fastify.register(upload.contentParser); // fastify.post('/api/uploads_team_profile/:customerId', { // preHandler: upload.single('file') @@ -1383,59 +1383,59 @@ fastify.post('/api/uploads/:supplierId', async (request, reply) => { -fastify.post('/api/uploads-user/:customerId', async (request, reply) => { - try { - const customerId = request.params.customerId; - const data = await request.file(); +// fastify.post('/api/uploads-user/:customerId', async (request, reply) => { +// try { +// const customerId = request.params.customerId; +// const data = await request.file(); - // Generate a unique file name +// // Generate a unique file name - const fileName = `${data.filename}`; +// const fileName = `${data.filename}`; - // Define the destination bucket and file path - const bucketName = 'arminta_profile_pictures'; - const filePath = `arminta_user_profiles/${fileName}`; +// // Define the destination bucket and file path +// const bucketName = 'arminta_profile_pictures'; +// const filePath = `arminta_user_profiles/${fileName}`; - // Create a write stream to the destination file in the bucket - const writeStream = storage.bucket(bucketName).file(filePath).createWriteStream(); +// // Create a write stream to the destination file in the bucket +// const writeStream = storage.bucket(bucketName).file(filePath).createWriteStream(); - // Pipe the file data to the write stream - data.file.pipe(writeStream); +// // Pipe the file data to the write stream +// data.file.pipe(writeStream); - writeStream.on('finish', async () => { - try { - // Make the uploaded file publicly accessible - await storage.bucket(bucketName).file(filePath).makePublic(); +// writeStream.on('finish', async () => { +// try { +// // Make the uploaded file publicly accessible +// await storage.bucket(bucketName).file(filePath).makePublic(); - const publicUrl = `https://storage.googleapis.com/${bucketName}/${filePath}`; +// const publicUrl = `https://storage.googleapis.com/${bucketName}/${filePath}`; - ProfilePicture.findOneAndUpdate( - { customerId }, - { picture: publicUrl }, - { new: true, upsert: true }, - (error, picture) => { - if (error) { - reply.code(500).send({ error: 'Failed to update database' }); - } else { - // Return the public URL - reply.send({ picture: publicUrl }); - } - } - ); - } catch (error) { - reply.code(500).send({ error: 'Failed to make file public' }); - } - }); +// ProfilePicture.findOneAndUpdate( +// { customerId }, +// { picture: publicUrl }, +// { new: true, upsert: true }, +// (error, picture) => { +// if (error) { +// reply.code(500).send({ error: 'Failed to update database' }); +// } else { +// // Return the public URL +// reply.send({ picture: publicUrl }); +// } +// } +// ); +// } catch (error) { +// reply.code(500).send({ error: 'Failed to make file public' }); +// } +// }); - writeStream.on('error', (err) => { - reply.code(500).send({ error: 'Failed to move file' }); - }); - } catch (err) { - reply.code(500).send({ error: 'An error occurred' }); - } -}); +// writeStream.on('error', (err) => { +// reply.code(500).send({ error: 'Failed to move file' }); +// }); +// } catch (err) { +// reply.code(500).send({ error: 'An error occurred' }); +// } +// }); // fastify.post("/api/uploads-electricty-work/:customerId/:installationId", async (request, reply) => {