feat: presigned urls for inventories
This commit is contained in:
@@ -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,
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user