Explicitly Close Dropdown Menu in Vue.js

I have a drop down menu in a Vue application which I need to explicitly close after applying some logic.

Essentially the flow is:

  1. Page loads, user clicks on a name from the drop down – name value gets written to database
  2. User reloads page, clicks on a different name, gets a pop-up asking if they want to save the new name

At this point, if the user confirms their choice, the new name gets written to the database, but the drop down stays open.
I need to add some logic to call after the user confirms their choice in step 2 to ensure that the drop down doesn’t stay open.

<div class="part">
        <span class="for-label"> Employee: </span>
        <el-select v-model="dataValue.assignedUser" filterable :disabled="notClick" @change="handle">
          <el-option
            v-for="(user, userIndex) in assignedOption"
            :key="userIndex"
            :label="user.userName"
            :value="user.userEmail"
          />
        </el-select>
      </div>

If relevant this bug only started occurring after adding the “filterable” attribute to the el-select.

React Native – Flatlist error when removing an item

I am using flatlist to display a list of items from async storage. I am currently getting the list of items from async storage and then displaying it using flatlist so removing an item item from the flatlist also removes it from the async storage.

The list of items (ItemsArray) consists of id and product retrieved from async storage.

When i try to remove a single item from the list i get an error as shown here:
Error 1
Error 2

Error 1 happens because the items are being compared so it can sort the list in ascending order and when the item is removed, there is no item to be compared with so it returns null.

Error 2 happens when i remove the last item from the list and i believe the error is related to the key extractor.

Async Storage: https://react-native-async-storage.github.io/async-storage/docs/api#removeitem

Code:

const [ItemArray, setItemsArray] = useState([]);
const removeItem = async (ID) => {
  await AsyncStorage.removeItem(ID);
};
const getItem = async (x) => {
  const item = await AsyncStorage.getItem(x);
  return item
};

const getAllItems = async () => {
  let temp = [];
  temp = await AsyncStorage.getAllKeys();
  const tempItems = [];
  for (let i = 0; i < temp.length; i++) {
    tempItems.push(await getItem(temp[i]));
  }
  setItemsArray(tempItems);
};
//...
return (
  <View>
    <FlatList
      data={itemsArray.sort((a, b) => (a.id > b.id ? 1 : -1))}
      renderItem={renderItem}
      keyExtractor={(product) => product.id}
    />
  </View>
);

Flattening 2D grid of 2D arrays into a single 2D array, in JavaScript (functionally)

I have a 2D array (grid) of 2D arrays (chunks) for a game I’m developing:

const c1 = [[1, 2],
            [3, 4]]

const c2 = [[5, 6],
            [7, 8]]

const c3 = [[9, 0],
            [1, 2]]

const c4 = [[3, 4],
            [5, 6]]

const grid_of_chunks = [[c1, c2],
                        [c3, c4]];

and I want to reduce/flatten the grid_of_chunks to:

[[1, 2, 5, 6],
 [3, 4, 7, 8],
 [9, 0, 3, 4],
 [1, 2, 5, 6]]

I’ve been able to implement a functional solution for this (in 2 lines of Clojure), but I’m struggling to wrap my head around translating it to functional JavaScript, and bridging the gap between the two language’s map semantics (JS map only accepts one array, whereas Clojure’s map accepts many collections…).

This is as far as I got:

function join_grid_of_chunks(gofc) {
    const joined_horiz = gofc.map(
        gofc_row => [].map.apply(gofc_row, [cs => [].concat.apply(cs)])
    );
    return [].concat.apply(joined_horiz);
}

How to build a meme javascript? [closed]

I can`t find a way to take the informations i need ,from a wordpress website, and copy them into my website.

For example:

I need to copy a list of 40 products from Apple website to my personal website

These 40 products must be copied with the price and picture of each product separately

register the id of a dropdown array in PHP Laravel 8 livewire with components?

Using Laravel 8 + Livewire: can’t record id of many drop down list in component
[my form blade][1]

<form class="form-horizontal" wire:submit.prevent="storePrecio">
        @csrf
        @foreach ($product->attributeValues->unique('product_attribute_id') as $av)
        <div class="form-group">
          <label class="col-md-4 control-label">{{ $av->productAttribute->name }} :</label>
            <div class="col-md-4">
              <select class="form-control" style="width: 200px;" wire:model="combination">
              @foreach ($av->productAttribute->attributeValues->where('product_id', $product->id) as $pav)
               <option value="{{ $pav->id }}">{{ $pav->value }}</option>
              @endforeach
              </select>
           </div>
      </div>

@endforeach

[1]: https://i.stack.imgur.com/5C0wO.jpg

Move a dynamic number of array elements from one collection’s array to another collection’s array in MongoDB

I’m working on a Discord Bot but this question is about the service-end I’ve created for the bot. The scenario I’m working on is as follows, whenever a user deletes their account all of the images uploaded by said user will be removed from the GUILDS collection and placed in the DELETED_CONTENT collection. Specifically, a user’s image data will be removed from a GUILD’s image_pool array and placed in a respective DELETED_CONTENT image_pool array.

The number of images varies by user and the number of GUILDS that a user is associated also varies. image_pool data is dynamic so overwriting that would be nuanced to maintain state, whereas the rest of a GUILD’s data is static.
What I’m looking to achieve below assuming ‘jeskoston’ deletes account. I’ve added a comment to their username for clarity.

Current GUILDS (collection)

{
    "_id" : ObjectId("61b3db8b965d8d06da643edd"),
    "preferred_locale" : "en-US",
    "nsfw" : false,
    "installed_by_id" : "795864504197578834",
    "installed_by_username" : "philjackson",
    "image_pool" : [ 
        {
            "_id" : ObjectId("61eb74edaa9c4c0f53cbff67"),
            "date_uploaded" : "2022-01-21T19:07:25-08:00",
            "uploaded_by_discord_username" : "jeskoston <-- WILL DELETE ACCOUNT", 
            "uploaded_by_id" : "619dadc90565852231712345",
            "image_title" : "Jordan",
            "image_url" : "/uploads/925819329911062589/1642820844573IMG-4148.JPG",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null
        }, 
        {
            "_id" : ObjectId("61eb74edaa9c4c0f53cbfe88"),
            "date_uploaded" : "2022-01-21T19:07:25-08:00",
            "uploaded_by_discord_username" : "andydiscord",
            "uploaded_by_id" : "619dadc90565852231771649",
            "image_title" : "Pippen",
            "image_url" : "/uploads/825519329911062589/5442820844573IMG-1111.png",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null
        }
    ],
    "install_date" : "2021-12-10T22:58:19.504Z",
    "discord" : {
        "id" : "945819329911062589",
        "owner_id" : "795864504197577734",
        "system_channel_id" : "888819329911062592",
        "name" : "bulls"
    }
},
{
    "_id" : ObjectId("61eb9a0cbcbea4139ea17123"),
    "preferred_locale" : "en-US",
    "nsfw" : false,
    "installed_by_id" : "795864504197578834",
    "installed_by_username" : "georgekarl",
    "image_pool" : [
      {
            "_id" : ObjectId("61eb74edaa9c4c0f53cbfe90"),
            "date_uploaded" : "2022-01-21T19:09:30-08:00",
            "uploaded_by_discord_username" : "jeskoston <-- WILL DELETE ACCOUNT",
            "uploaded_by_id" : "619dadc90565852231712345",
            "image_title" : "Malone",
            "image_url" : "/uploads/995519329911062100/7842820844573IMG-4000.jpg",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null
        }
     ],
    "install_date" : "2022-01-22T05:45:48.011Z",
    "discord" : {
        "id" : "549483811550042074",
        "owner_id" : "792864524197578834",
        "system_channel_id" : "849421811440042077",
        "name" : "jazz"
    }
}

Current DELETED_CONTENT (collection):

{
    "_id" : ObjectId("88b3db8b965d8d06da643p09"),
    "preferred_locale" : "en-US",
    "nsfw" : false,
    "installed_by_id" : "795864504197578834",
    "installed_by_username" : "philjackson",
    "guild_uninstalled": false,
    "image_pool" : [ 
        {
            "_id" : ObjectId("61eb74edaa9c4c0f53cbfk3p"),
            "date_uploaded" : "2022-01-21T19:07:25-08:00",
            "date_deleted" : "2022-01-25T01:07:45-08:00",
            "uploaded_by_discord_username" : "andrewdiscord",
            "uploaded_by_id" : "619dadc90565852231771659",
            "image_title" : "Rodman",
            "image_url" : "/uploads/925819329911062589/1232820844573IMG-4148.JPG",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null,
            "date_deleted" : "2022-01-22T19:09:25-08:00",
        },
    ],
    "install_date" : "2021-12-10T22:58:19.504Z",
    "discord" : {
        "id" : "945819329911062589",
        "owner_id" : "795864504197577734",
        "system_channel_id" : "888819329911062592",
        "name" : "bulls"
    }
},
{
    "_id" : ObjectId("61eb9a0cbcbea4139ea17789"),
    "preferred_locale" : "en-US",
    "nsfw" : false,
    "installed_by_id" : "795864504197578834",
    "installed_by_username" : "georgekarl",
    "guild_uninstalled": false,
    "image_pool":[{
            "_id" : ObjectId("888b74edaa9c4c0f53cbff45"),
            "date_uploaded" : "2022-02-23T12:07:11-08:00",
            "date_deleted" : "2022-02-24T11:02:01-08:00",
            "uploaded_by_discord_username" : "jakediscord",
            "uploaded_by_id" : "619dadc9056585223175461f",
            "image_title" : "Stockton",
            "image_url" : "/uploads/925819329911062589/1232820844573IMG-4148.JPG",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null,
            "date_deleted" : "2022-03-22T04:09:00-08:00",
        }
],
    "install_date" : "2022-01-22T05:45:48.011Z",
    "discord" : {
        "id" : "549483811550042074",
        "owner_id" : "792864524197578834",
        "system_channel_id" : "849421811440042077",
        "name" : "jazz"
    }
}

Desired GUILDS (collection) after user jeskoston deletes their account:

{
    "_id" : ObjectId("61b3db8b965d8d06da643edd"),
    "preferred_locale" : "en-US",
    "nsfw" : false,
    "installed_by_id" : "795864504197578834",
    "installed_by_username" : "philjackson",
    "image_pool" : [  
        {
            "_id" : ObjectId("61eb74edaa9c4c0f53cbfe88"),
            "date_uploaded" : "2022-01-21T19:07:25-08:00",
            "uploaded_by_discord_username" : "andydiscord",
            "uploaded_by_id" : "619dadc90565852231771649",
            "image_title" : "Pippen",
            "image_url" : "/uploads/825519329911062589/5442820844573IMG-1111.png",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null
        }
    ],
    "install_date" : "2021-12-10T22:58:19.504Z",
    "discord" : {
        "id" : "945819329911062589",
        "owner_id" : "795864504197577734",
        "system_channel_id" : "888819329911062592",
        "name" : "bulls"
    }
},
{
    "_id" : ObjectId("61eb9a0cbcbea4139ea17123"),
    "preferred_locale" : "en-US",
    "nsfw" : false,
    "installed_by_id" : "795864504197578834",
    "installed_by_username" : "georgekarl",
    "image_pool" : [],
    "install_date" : "2022-01-22T05:45:48.011Z",
    "discord" : {
        "id" : "549483811550042074",
        "owner_id" : "792864524197578834",
        "system_channel_id" : "849421811440042077",
        "name" : "jazz"
    }
}

Desired DELETED_CONTENT (collection) after user jeskoston deletes their account:

{
    "_id" : ObjectId("88b3db8b965d8d06da643p09"),
    "preferred_locale" : "en-US",
    "nsfw" : false,
    "installed_by_id" : "795864504197578834",
    "installed_by_username" : "philjackson",
    "guild_uninstalled": false,
    "image_pool" : [ 
        {
            "_id" : ObjectId("61eb74edaa9c4c0f53cbff67"),
            "date_uploaded" : "2022-01-21T19:07:25-08:00",
            "date_deleted" : "2022-01-22T19:09:25-08:00",
            "uploaded_by_discord_username" : "andrewdiscord",
            "uploaded_by_id" : "619dadc90565852231771659",
            "image_title" : "Rodman",
            "image_url" : "/uploads/925819329911062589/1232820844573IMG-4148.JPG",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null,

        },
        {
            "_id" : ObjectId("61eb74edaa9c4c0f53cbff67"),
            "date_uploaded" : "2022-01-21T19:07:25-08:00",
            "date_deleted" : "2022-01-26T07:09:51-08:00",
            "uploaded_by_discord_username" : "jeskoston <-- ACCT DELETED", 
            "uploaded_by_id" : "619dadc90565852231712345",
            "image_title" : "Jordan",
            "image_url" : "/uploads/925819329911062589/1642820844573IMG-4148.JPG",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null
        }
    ],
    "install_date" : "2021-12-10T22:58:19.504Z",
    "discord" : {
        "id" : "945819329911062589",
        "owner_id" : "795864504197577734",
        "system_channel_id" : "888819329911062592",
        "name" : "bulls"
    }
},
{
    "_id" : ObjectId("61eb9a0cbcbea4139ea17789"),
    "preferred_locale" : "en-US",
    "nsfw" : false,
    "installed_by_id" : "795864504197578834",
    "installed_by_username" : "georgekarl",
    "guild_uninstalled": false,
    "image_pool":[{
            "_id" : ObjectId("888b74edaa9c4c0f53cbff45"),
            "date_uploaded" : "2022-02-21T15:07:11-08:00",
            "date_deleted" : "2022-03-02T04:09:00-08:00",
            "uploaded_by_discord_username" : "jakediscord",
            "uploaded_by_id" : "619dadc9056585223175461f",
            "image_title" : "Stockton",
            "image_url" : "/uploads/925819329911062589/1232820844573IMG-4148.JPG",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null,
            
        },
        {
            "_id" : ObjectId("61eb74edaa9c4c0f53cbfe90"),
            "date_uploaded" : "2022-01-21T19:09:30-08:00",
            "date_deleted" : "2022-23-22T04:09:00-08:00",
            "uploaded_by_discord_username" : "jeskoston <-- ACCT DELETED", 
            "uploaded_by_id" : "619dadc90565852231712345",
            "image_title" : "Malone",
            "image_url" : "/uploads/995519329911062100/7842820844573IMG-4000.jpg",
            "likes" : null,
            "flags" : 0,
            "nsfw" : null
        }
],
    "install_date" : "2022-01-22T05:45:48.011Z",
    "discord" : {
        "id" : "549483811550042074",
        "owner_id" : "792864524197578834",
        "system_channel_id" : "849421811440042077",
        "name" : "jazz"
    }
}

My strategy thus far has been to #1 pull a user’s images from the GUILDS collection but before doing that #2 copy data to push to the DELETED_CONTENT collection.

I have #1 finished

For #2 I have a query that collects a user’s image data and adds a date_deleted timestamp to each image. I also include other GUILD data in query. I only return guild entries where a user has images posted.

('GUILDS').aggregate([
   {

           $project:
          {    
               discord:1,
               install_date:1,
               installed_by_id:1,
               installed_by_username:1,
               preferred_locale:1,
               nsfw:1,
               guild_deleted:1,
             
               user_images:
               {
                   $filter:
                   {
                       input:"$image_pool",
                       as: "image",                             
                       cond:{ $eq: ["$$image.uploaded_by_id",'619dadc90565852231771659'] }
                   }
               }
           }
       },
           {
       $addFields: {
           guild_deleted:false,
           "user_images":{
               $map:{
                   input: "$user_images",
                    as:"image",
                    in:{
                       _id:"$$image._id",
                       date_deleted: "$$NOW",
                       date_uploaded:"$$image.date_uploaded",
                      uploaded_by_discord_username:"$$image.uploaded_by_discord_username",
                       uploaded_by_id:"$$image.uploaded_by_id",
                       image_title:"$$image.image_title",
                       image_url:"$$image.image_url",
                       likes:"$$image.likes",
                        flags:"$$image.flags",
                        nsfw:"$$image.nsfw"
                       }
               }
           }
       }
   },
       {
           $match:{ 'user_images.0':{ $exists: true }    }
       }  
])

I retrieve user data based on an images ‘uploaded_by_id’ value. I include static guild info in the event I have to upsert the whole document, user_images are a user’s images from a GUILD’s respective image_pool(s).

I want to be able to move this data without looping calls to the database. I’ve tried to use bulkWrite but have had no luck, I cannot find a concrete example that has a use-case for a dynamic number of entries. I’ve attempted to create a dynamic string for bulkWrite with no luck. I’ve also attempted to use $merge but I’m having trouble with the pipeline operators under whenMatched field.

Maybe my entire approach is off? I will spare my other attempts since this has gotten long. I’m not sure if anyone can help, but any attempt would be appreciated.

Next.js SSR with API not building properly

“Not building properly” meaning “not finishing building at all”. I’ve set up a very basic blog project with dynamic SSR which fetches data from the Notion-API to generate static blog pages. Everything works fine when I’m running it in next dev – however when trying to build the project, it runs into an endless loop without any errors shown.

One thought I had was the following:
If I understand the sequence of everything correctly, Next.js already tries building the static sites during next build. The dynamic site generation relies on an API that I have also coded within the same project, which forwards requests to Notion in order to obfuscate secrets. Obviously no local API will be active during the build, which I am guessing is the error I’m running into?

To illustrate – here’s the code for the pages that are to be generated:

import Head from 'next/head';

export default function Post( { postData, postBlocks } ) {
  console.log( { postData, postBlocks } );
  return (
    <>

      <Head>
        <title>Placeholder</title>
        <meta name="description" content="" />
      </Head>

      <h1>Placeholder</h1>

    </>
  )
}

// Get further info on the specific "Post" from Notion via my API
export async function getStaticProps( { params } ) {
  const postDataRequest = fetch( `${ process.env.API_ROOT }/posts/${ params.id }` );
  const postBlocksRequest = fetch( `${ process.env.API_ROOT }/blocks/${ params.id }` );

  const [ postData, postBlocks ] = await Promise.all(
    ( await Promise.all( [ postDataRequest, postBlocksRequest ] ) )
      .map( response => response.json() )
  );

  return {
    props: { postData, postBlocks: postBlocks.results },
    revalidate: 86400,
  };

}

// Fetch  all "Posts" from Notion via my API, get their ID and generate a static route for each 
export async function getStaticPaths() {
  const req = await fetch( `${ process.env.API_ROOT }/posts?limit=999` );
  const data = await req.json();

  const paths = data.results.map( page => {
    return { params: { id: page.id } };
  } )

  return {
    paths,
    fallback: false,
  };
}

I’ve also tried to start the API locally and build the project in another terminal, this didn’t work either. Have I missed something somewhere?

I have also published my project on GitHub for further inspection.

How to get index page to show HTML instead of JSON with NEXT JS?

I’m trying out Next.js with a pluralsight course and running into a weird issue where my index page will randomly stop working, then only ever return JSON without any error logging or indication that something is wrong. It doesn’t always start out doing this, but once it does there’s no recovering outside of wiping out what’s in the existing file. Is there maybe a specific syntax for form elements Next needs?

index.js and index.tsx output:

{
  "props": {
    "pageProps": {}
  },
  "page": "/",
  "query": {},
  "buildId": "development",
  "nextExport": true,
  "autoExport": true,
  "isFallback": false,
  "scriptLoader": []
}

The index page as tsx (also happened on a js version which lead me to use npx create-next-app@latest --ts hoping it would work better and I prefer to use TS anyway)

import { useState } from 'react';
import type { NextPage } from 'next';

const About: NextPage = () => {
    const [inputText, setInputText] = useState<string>("");

    return (
        <div>
            <input onChange={(e) => { setInputText(e.target.value) }} placeholder="Enter Text Here" />
            <p>{inputText}</p>
        </div>
    );
}

export default About;

If there’s anything obvious breaking Next please point it out, I’m not sure what’s going on here and am surprised how easy it is to bork a page with such simple html/jsx. Any tips or suggestions appreciated!

how to download the file when selected an option from the dropdown list. The items in the drop down list are from json file

I have json file

[
{
   "name": "Documents",
   "types": [
       {"name": "Documents1",
        "url": "http://www.google.com" },
        {"name": "Documents2",
         "url": "http://www.facebook.com" },
        ] 
},
{
    "name": "binary",
    "types": [
        {"name": "binary1",
         "link": "href=./mosq.tar.gz"
        },
        {"name": "binary2",
         "link": "href=./mosq1.tar.gz" 
        }
        ] 
 }

]

I have the html code for this

<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>
 <body>
 <label for="">Documents</label>
 <select id="ddlDocuments">  </select> <br>
 <label for="">Binary Download</label> 
 <select id="ddlbinary">  </select> <br>

<script type="text/javascript">
   $(document).ready(function () {

    // FETCHING DATA FROM JSON FILE
        $.getJSON("test.json",
                function (data) {
            var details = '';
         
            // ITERATING THROUGH OBJECTS
            document.getElementById("ddlDocuments").insertBefore(new Option('', ''), 
            document.getElementById("ddlDocuments").firstChild);
            $.each(data[0].types, function (key, value) {
                var option = document.createElement("OPTION");
                option.innerHTML = value.name;
                option.value = value.url;              
                ddlDocuments.options.add(option);           
            });
            $('#ddlDocuments').on('click', function () {
                var url = $(this).val(); // get selected value
                if (url) { // require a URL
                    window.open(url,'_blank');
                    // window.location = url; // redirect
                }
                 return false;
            });


            document.getElementById("ddlbinary").insertBefore(new Option('', ''), 
            document.getElementById("ddlbinary").firstChild);
            $.each(data[2].types, function (key, value) {
                var option = document.createElement("OPTION");
                option.innerHTML = value.name;
                option.value = value.link;
                ddlbinary.options.add(option);
            });

            $('#ddlbinary').on('click', function () {
                var retVal = confirm("Do you want to download ?");
                if( retVal == true ) {
                    window.location = document.getElementById('test').href;
                     return true;
                } else {
                    event.preventDefault();
                    return false;
                }
            });
        });
    });
</script>

Download

How its working right now is we get 2 dropdowns on the webpage for Documents and binary. On select of an option of binary we get a confirmation box to download or not. on click of yes it would download because i am using the div tag. But how do we download the respective file coming from the json.

It would be great if someone would help me.

Node/Express: How to avoid status code 302 from a POST request made from a redirect button

I am trying to achieve a button that allows the client to navigate to and and from 2 sets of “to do lists”.

I want the button name to say “Home” when on the works to do list, and “Work” when on the home to do list page. and to navigate to and from these pages using just the one button.

I am using node, express and EJS, and my current attempt at making this work is to create an HTML button witch sends a post request to a “divert” route, and then executing a conditional statement to decide which route to redirect to depending on what the current page title is.

However i can redirect from the home page to the work page but once there i can not redirect back to the home page!.

console shows a 302 status code the moment i click the button to redirect me a second time. (from work to home.

I am a freshman on node and Express!

My codes below,

HTML

`<%- include("header") -%>    
<div class="box" id="heading">
<h1><%=listTitle%></h1>
</div>

<div class="box">
<% for (let i =0; i< newListItems.length; i++) { %>
<div class="item">
<input type="checkbox">
<p><%= newListItems[i] %></p>
</div>
<% }; %>

<form class="item" action="/" method="post">
<input type="text" name="newItem" placeholder="New item?" autocomplete="off">
<button type="submit" name="list" value=<%= listTitle %>>+</button>
</form>

</div>

<form class="" action="/divert" method="post">
<button type="submit" class="btn1" name="todoType" value="identify" style="width: 
100px"><%=btnName%></button>
</form> 

<%- include("footer") -%>`

app.js

`//jshint esversion:6

const express = require("express");
const bodyParser = require("body-parser");

// globals.
let items = [];
let workItems = [];
let btnIdentify = "Work";

const app = express();
app.use(bodyParser.urlencoded({extended: true}));

//Send static css file to browser.
app.use(express.static("public"));

app.set('view engine', 'ejs');


app.get("/", function(req, res) {
const date = new Date();
const options = {
weekday: "long",
day: "numeric",
month: "long"
};

let day = date.toLocaleDateString("en-US", options);
res.render('list', {listTitle: day, newListItems: items, btnName: btnIdentify});
});


app.post("/", function(req, res) {
let item = req.body.newItem;

if (req.body.list === "Work")  { //only uses frist word off the listTitle value.
workItems.push(item);
res.redirect("/work");
} else {
items.push(item);
res.redirect("/");
}
console.log(req.body);
})

app.get("/work", function(req,res) {

res.render("list", {listTitle: "Work list", newListItems: workItems, btnName: btnIdentify });
});

app.post("/divert", function(req,res) {
if (req.body.list !== "Work") {
res.redirect("/work");
btnIdentify = "Work";
} else if (req.body.list === "Work") {
res.redirect("/");
btnIdentify = "Home";
}
})

app.listen(3000, function() {
console.log("Server is running on port 3000")
});`

Insecure Use of setAtributeNS()

Im fixing some security issues that AppScan found on my Angular Application, one of them is the insecure use of “setAttributeNS()” I use this method in my application to inject some namespaces in the correct htmlElemnt

I have reader about the setAttribute() XSS vulnerability and that a workaround for it is directly injecting the code in the attribute name instead of using ‘setAttribute()’, but for setAttributeNS() I haven’t found any workaround to avoid this vulnerability

Example code:

.setAttributeNS("http://www.w3.org/1999/xlink", "href", canvas.toDataURL('image/png')

Any suggestions will be appreciated

I’m having problems playing áudio files in Discord

So, It’s been two long days traying to figure what the reck is going on… I’m creating a Bot to my Discord Channel that plays an audio.mp3 when a command is written, like !laugh then the bot should enter the voice channel and reproduce laugh.mp3. I’ve tried in so manny different ways but the bot keeps entering the channel, the green circle quickly appears but no sound is played…

const { join } = require('path');
const { joinVoiceChannel,  createAudioPlayer,  createAudioResource, getVoiceConnection, entersState, StreamType,  AudioPlayerStatus,  VoiceConnectionStatus, AudioResource } = require("@discordjs/voice");

module.exports = {
   name: 'laugh', 
   aliases: ["l"], 

   run: async(client, message, args) => {

   const player = createAudioPlayer()
   const connection = joinVoiceChannel({
   channelId: message.member.voice.channel.id,
   guildId: message.guild.id,
   adapterCreator: message.guild.voiceAdapterCreator
                     }).subscribe(player)
   let resource = createAudioResource(join('./som/', 'laugh.mp3'));
   player.play(resource)
   player.on(AudioPlayerStatus.AutoPaused, () => {
   player.stop();
         
     });
   }
}

I’ve already tried to caugh error but apparently nothing is wrong, I already have all intents in my index.js.

So, anyone could help me find a solution?

Smooth scroll – additional margin

I am trying to create template for CMS joomla 4, and I am using Template Toaster tool for such purpose. I have some issue with page converted to onepage style of website. I have set anchors for my menu, and when I click to any position of menu, then page is scrooling to my anchor but my floating menu cover some part of my text. I am trying to find how I can add some margin for smooth scrool and when I select any menu postion then when page will be scrolled to menu then text will be not hidden under menu.

Thank you for support