feat: presigned urls for inventories

This commit is contained in:
Sathishkumar Krishnan
2022-03-01 00:04:08 +05:30
parent 4dec9b6998
commit 8518122359
3 changed files with 16 additions and 0 deletions

View File

@@ -32,5 +32,13 @@ module.exports = {
return false; return false;
} }
}, },
generatePresignedUrl: (url) => {
const key = url.split(".com/")[1];
return S3.getSignedUrl("getObject", {
Bucket: AWS_S3_BUCKET,
Key: key,
Expires: 600,
});
}
}, },
}; };

View File

@@ -30,6 +30,7 @@ module.exports = {
res.status(404).send({ success: false, error: "Inventory not found" }); res.status(404).send({ success: false, error: "Inventory not found" });
return; return;
} }
if (inventoryData.image_url) inventoryData.image_url = S3.generatePresignedUrl(inventoryData.image_url);
res.send({ success: true, data: inventoryData }); res.send({ success: true, data: inventoryData });
} catch (error) { } catch (error) {
next(error); next(error);
@@ -52,6 +53,7 @@ module.exports = {
for (const inventory of inventoryData) { for (const inventory of inventoryData) {
inventory["widgetFamilies"] = await WidgetFamily.find({ inventory: inventory._id }); inventory["widgetFamilies"] = await WidgetFamily.find({ inventory: inventory._id });
if (inventory.image_url) inventory.image_url = S3.generatePresignedUrl(inventory.image_url);
} }
res.send({ success: true, data: inventoryData }); res.send({ success: true, data: inventoryData });

View File

@@ -13,6 +13,12 @@ const schema = new mongoose.Schema(
required: true, required: true,
trim: true, trim: true,
}, },
images: [
{
type: String,
trim: true,
},
],
description: { description: {
type: String, type: String,
required: true, required: true,