Endpoints for filtering gallery
VIDEO RESULT after completing all actions on the "SingleCollection" page.
To start creating this page, let's begin by creating the endpoint.
1. /getRequestText
Getting unique text based on which the image was generated:
Using nodes:
- http in (GET);
- function:
In the function node, add the "objectid" library.msg.payload = ([ { $match: { "deleted": false, "collection": objectid(msg.payload.collection) } }, { $group: { _id: "$text" } }, { $project: { _id: 0, text: "$_id" } } ]) return msg
- mongodb in.
Select the nodes "collection-gallery" and "operation-aggregate."
- http response
2. /getGalleryByText
Using node:
- http in(GET);
- function.
msg.payload = { text: msg.payload.text, deleted: false } return msg;
- mongodb in.
- function:
We filter the data in a way that only returns the images with valid links, ensuring that only those images whose links are still active are returned.
const result = []; for (const image of msg.payload) { const timeDiff = new Date(image.expireTime).getTime() - new Date().getTime(); if (timeDiff > 0) { result.push(image); } } msg.payload = result; return msg;
- http response
3. /deleteAllImageByText
Deleting all images based on the specified text.
Using nodes:
- http in(PUT)
- function.
Specify that need to update the "deleted" property to true for objects with the specified text.
msg.query = { text: msg.payload.text } msg.payload = { $set: { deleted: true } } return msg;
- mongodb out
- http response
No Comments