Skip to main content

Endpoints for filtering gallery

VIDEO RESULT after completing all actions on the "SingleCollection" page.

image.png


To start creating this page, let's begin by creating the endpoint.

1. /getRequestText

Getting unique text based on which the image was generated:

image.png

Using nodes:

  • http in (GET);
  • function: 
    msg.payload = ([
        {
            $match: {
                "deleted": false,
                "collection": objectid(msg.payload.collection)
            }
        },
        { 
            $group: { _id: "$text" } 
        },
        { 
            $project: { _id: 0, text: "$_id" } 
            }
    ])
    
    return msg
    In the function node, add the "objectid" library.

    image.png



  • mongodb in.
    Select the nodes "collection-gallery" and "operation-aggregate."

    image.png

  • http response

2. /getGalleryByText

image.png

Using node:

  • http in(GET);
  • function.  
    msg.payload = {
        text: msg.payload.text,
        deleted: false
    }
    return msg;
  • mongodb in.

    image.png

  • 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.

image.png

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

    image.png
  • http response