Skip to content

Commit

Permalink
new image point for logos
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinovpankaj committed Feb 16, 2024
1 parent ec01850 commit ba8564a
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions routes/images-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var upload = multer({ dest: 'uploads/' });
const bodyParser = require('body-parser');
var image = require('../model/image');
var tenantService = require('../service/tenantService');
const { newPipeline } = require('@azure/storage-blob');

require("dotenv").config();

Expand Down Expand Up @@ -88,4 +89,66 @@ router.route('/upload')
res.status(500).json(errResponse);
}
});

router.route('/uploadlogos')
.post(upload.single("picture"), async function (req, res) {
var errResponse;
try {
var editedat = (new Date(Date.now())).toISOString();
const { containerName, uploader, entityName,id,
lasteditedby,
type, parentType} = req.body;
//var companyIdentifier = req.user.company;
//companyIdentifier = companyIdentifier.replaceAll(".","-");
//var fileSizeInBytes = req.headers['content-length'] ;
const filetoUpload = req.file;

//replace all except alphanumeric

var newcontainerName= containerName.replace(/[^a-zA-Z0-9 ]/g, '');
newcontainerName = newcontainerName.toLowerCase();
// var newentityName= entityName.replace(/[^a-zA-Z0-9 ]/g, '');
// newentityName = newentityName.toLowerCase();
//container would be now the companyidentifier

const uploadOptions = {
metadata: {
'uploader': uploader,
},
tags: {
'project': newcontainerName,

}
};

if (newcontainerName.length < 3) {
newcontainerName = `${newcontainerName}-${uploader}`;
}
if (!(newcontainerName && filetoUpload)) {
errResponse = new ErrorResponse(400, "containerName, blobName, filePath is required", "");
res.status(400).json(errResponse);
return;
}
var result = await uploadBlob.uploadFile(newcontainerName, `${filetoUpload.originalname}`, filetoUpload.path, uploadOptions);
var response = JSON.parse(result);
if (response.error) {
errResponse = new ErrorResponse(500, 'Internal server error', result.error);
console.log(response);
res.status(500).json(errResponse);
return;
}
if (response.message) {
res.status(201).json(response);

}
else
res.status(409).json(response);
return;

} catch (err) {
console.log(err);
errResponse = new ErrorResponse(500, "Internal server error", err);
res.status(500).json(errResponse);
}
});
module.exports = router;

0 comments on commit ba8564a

Please sign in to comment.