How to redirect 404 page inside an axios service – nextjs

I’m using axios.
I want to check status when I got response of my api.
for example I want to redirect to 404 page.

const api = axios.create({
  headers: {
    common: {
      'Content-Type': 'application/json'
    },
    post: {

    }
  }
});
api.interceptors.response.use(
  ...

  (error) => {
const code = parseInt(error.response && error.response.status)
     if (code === 404) {
          console.log("responsive",error)
          if(data){
            data.forEach(itemError => {
              toast.error(itemError, {
                theme: 'colored',
              });
            });
          }else{
            //redirect to 404 page. but it doesn't work. 
            //return window.location.href = '/404';
          }
...

But I don’t know How I can to redirect inside of it.

POST a form in which some element are file

In a js web project,
I want to POST a form with a complexe json schema, and in which some field will be file.

How do I do It?

I currently upload a file alone like this

  const data = new FormData();
    data.append('mimetype', file.type);
    data.append('filename', file.name);
    data.append('file', file);
    return this.httpClient.post(url, data)

but I want my new form look like this:

 var data ={username:"John doe", 
    profilPhoto:{mimetype:..., filename:..., file: ...},
    house:{
       photo:{mimetype:..., filename:..., file: ...},
    },
    documents:[{mimetype:..., filename:..., file: ...}]

  }

How can I return the value of a key based on a different value in a dictionary (JavaScript)

    const array = [
  {
    username: "john",
    team: "red",
    score: 5,
    items: ["ball", "book", "pen"]
  },
  {
    username: "becky",
    team: "blue",
    score: 10,
    items: ["tape", "backpack", "pen"]
  },
  {
    username: "susy",
    team: "red",
    score: 55,
    items: ["ball", "eraser", "pen"]
  },
  {
    username: "tyson",
    team: "green",
    score: 1,
    items: ["book", "pen"]
  },

];

I have the above array. I have filtered the users that are in team red. Is there a way to return only the usernames of all users in team red instead of returning the whole data entry? So the output should be “[ John, Susy ]”. I have this code so far.

const filterArray = array.filter(user3 => {
  return user3.team === "red";
})

How to display all JSON objects with arrays on React JSX?

I only learned React 3 days ago. It’s very alien to me cos I come from a beginner’s PHP background.

I’m given a GitHub code that looks like below called NFTBalance.jsx which displays the JSON. It calls useNFTBalance.js which parses the JSON.

I wish to display the attributes each in a meta element like <Meta title={nft.name} description={nft.contract_type} />

I’ve been reading about this and more but I still failed to efficiently render the JSON attributes objects array.

I could do like NFT.type = data.attributes[0].value; but I find that’s very inefficient because I need to name each object and the attributes’ objects will change.

Could we use map function or something?

NFTBalance.jsx
...
 )}
        {NFTBalance &&
          NFTBalance.map((nft, index) => (
            <Card
              hoverable
              actions={[
                <Tooltip title="View On Blockexplorer">
                  <FileSearchOutlined
                    onClick={() =>
                      window.open(
                        `${getExplorer(chainId)}address/${nft.token_address}`,
                        "_blank"
                      )
                    }
                  />
                </Tooltip>,
                <Tooltip title="List NFT for sale">
                  <ShoppingCartOutlined onClick={() => handleSellClick(nft)} />
                </Tooltip>,
              ]}
              style={{ width: 300, border: "2px solid #e7eaf3" }}
              cover={
                <Image
                  preview={false}
                  src={nft?.image || "error"}
                  fallback="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADDCAYAAADQvc6UAAABRWlDQ1BJQ0MgUHJvZmlsZQAAKJFjYGASSSwoyGFhYGDIzSspCnJ3UoiIjFJgf8LAwSDCIMogwMCcmFxc4BgQ4ANUwgCjUcG3awyMIPqyLsis7PPOq3QdDFcvjV3jOD1boQVTPQrgSkktTgbSf4A4LbmgqISBgTEFyFYuLykAsTuAbJEioKOA7DkgdjqEvQHEToKwj4DVhAQ5A9k3gGyB5IxEoBmML4BsnSQk8XQkNtReEOBxcfXxUQg1Mjc0dyHgXNJBSWpFCYh2zi+oLMpMzyhRcASGUqqCZ16yno6CkYGRAQMDKMwhqj/fAIcloxgHQqxAjIHBEugw5sUIsSQpBobtQPdLciLEVJYzMPBHMDBsayhILEqEO4DxG0txmrERhM29nYGBddr//5/DGRjYNRkY/l7////39v///y4Dmn+LgeHANwDrkl1AuO+pmgAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAwqADAAQAAAABAAAAwwAAAAD9b/HnAAAHlklEQVR4Ae3dP3PTWBSGcbGzM6GCKqlIBRV0dHRJFarQ0eUT8LH4BnRU0NHR0UEFVdIlFRV7TzRksomPY8uykTk/zewQfKw/9znv4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KNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiEC/wGgKKC4YMA4TAAAAABJRU5ErkJggg=="
                  alt=""
                  style={{ height: "300px" }}
                />
              }
              key={index}
            >
              <Meta title={nft.name} description={nft.contract_type} />
...
...
export const useNFTBalance = (options) => {
  const { account } = useMoralisWeb3Api();
  const { chainId } = useMoralisDapp();
  const { resolveLink } = useIPFS();
  const [NFTBalance, setNFTBalance] = useState([]);
  const {
    fetch: getNFTBalance,
    data,
    error,
    isLoading,
  } = useMoralisWeb3ApiCall(account.getNFTs, { chain: chainId, ...options });
  const [fetchSuccess, setFetchSuccess] = useState(true);

  useEffect(() => {
    async function fetchData() {
      if (data?.result) {
        const NFTs = data.result;
        setFetchSuccess(true);
        for (let NFT of NFTs) {
          if (NFT?.metadata) {
            NFT.metadata = JSON.parse(NFT.metadata);
            NFT.image = resolveLink(NFT.metadata?.image);
          } else if (NFT?.token_uri) {
            try {
              await fetch(NFT.token_uri)
                .then((response) => response.json())
                .then((data) => {
                  NFT.image = resolveLink(data.image);
                  
                  {/*I think this is how I suppose to grab the JSON attributes object*/}
                  NFT.itemName = data.name;
                  NFT.description = data.description;
                  NFT.type = data.attributes;
                });
            } catch (error) {
              setFetchSuccess(false);
            }
          }
        }
        setNFTBalance(NFTs);
      }
    }
    fetchData();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [data]);

  return { getNFTBalance, NFTBalance, fetchSuccess, error, isLoading };
};

The JSON file is like this..

{
  "description": "Windsor my cat is found dead. An investigation is being carried out. My neighbor? A car? He goes up to heaven and we are saddened. By Guive Khosravi",
  "name": "The Incredible Windsor",
  "attributes": [
    {
      "trait_type": "Type",
      "value": "Acrylic, Spray paint on Linen"
    },
    {
      "trait_type": "Year",
      "value": "2020"
    },
    {
      "trait_type": "Style",
      "value": "Contemporary"
    },
    {
      "trait_type": "Location",
      "value": "Paris, France"
    }
  ]
}

JavaScript: How to grab thumbnail (first frame) of video with only raw byte data (mp4 and possibly other types)

I want to grab a thumbnail of a video (let’s say the thumbnail is at 0:00 of the video, so the first frame), however, I am streaming the video and want to display the thumbnail before the video fully loads (so fully loading it, saving it as a blob url and using the HTML5Video element isn’t an option).

Also, the URL that I am originally fetching the video from will not accept any more requests after I make the initial request to download the video, so I also can’t use the HTML5Video element to load that URL.

All I have access to are the raw bytes that are being streamed in from the response. So my question is how can I grab the first frame of the video when just enough bytes have loaded for it. Are there any tools for this, or will I have to interpret the file contents myself?

If I were to build my own solution, I assume the steps would be something like:

  • Wait for file metadata/headers to load first.
  • get the dimensions (x.y) of the video from the metadata.
  • the next x.y bytes will be the first frame of the video. Store this as an ArrayBuffer and create a data URL to use with an HTML img tag.

Let’s start with an mp4 solution but a solution to other formats would be appreciated as well, thanks in advance :).

Ojet uses encoded URL when params are used in router.go

When I use router.go in Ojet like below

self.args.router.go({ path: serverData.nextViewUrl, params: { c: serverData.sessionId } });

I get the following URL

?ojr=start_form%3Bc%3D63A4CC7E647582AF7E6C634B7FBF82F2

Above is the encoded URL. How do I get the correct decoded url by default in Ojet like below:

?ojr=start_form&c=D63A4CC7E647582AF7E6C634B7FBF82F2

Additional info:
Following is my router setup:

// Router setup
      let router = new CoreRouter(navData, {
        urlAdapter: new UrlParamAdapter()
      });
      router.sync();

      this.moduleAdapter = new ModuleRouterAdapter(router);

      this.selection = new KnockoutRouterAdapter(router);

      // Setup the navDataProvider with the routes, excluding the first redirected
      // route.
      this.navDataProvider = new ArrayDataProvider(navData.slice(1), { keyAttributes: "path" });

I am using the latest OJet v11

How to check if element has any attributes in it?

I’m trying to make a conditional checker check whether the element has any attributes or not.

var result = parentElm.hasAttribute(); i tried using this but I’m not sure I want a specific attribute by name, I just want to check whether the element has any attributes or attribute like length, size, or idk.

copyFormatCommand.js

    const model = this.editor.model;
    const selection = model.document.selection;
    const parentElm = selection.focus.parent;
    this.isEnabled = !!parentElm;
  

Here is the HTML I’m using to test if there are multiple nested elements and want to check whether the textNode‘s parent element has any attributes
HTML

<p style="font: 11pt Times New Roman, Times, Serif; margin: 0;" xvid="c0fc3b7176d15af5d8c5c488a7fa675e"><span xvid="6f8db94eb5824fc90d39a2d9a127a98d">Annual Fund Operating Expenses</span></p>
<p style="font: 11pt Times New Roman, Times, Serif; margin: 0;" xvid="c0fc3b7176d15af5d8c5c488a7fa675e">
    <span xvid="6f8db94eb5824fc90d39a2d9a127a98d"><span xvid="1">hello</span></span>
</p>
<p>hello</p>

how can i can fix my leaftlat map problems?

I have a div with id map for leatleft and its only show one tile of map
i really have problem to show full map
please help me

enter image description here

my css style is

#map {
        height: 350px;
        width: 100%;
    }

and my code is

var mymap = L.map('map').setView([35.7336466, 51.3458287], 12);

    L.tileLayer('https://b.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
        attribution: 'hello world',
        maxZoom: 18,
    }).addTo(mymap);

mymap.locate({
        setView: true,
        maxZoom: 12
    });

How do I check if object property is true/false and output based on true/false [closed]

I’ve been trying to figure this one out – if someone has some pointers I would appriciate it. Basically I got an object which has 3 properties, I need to check if one of those properties is true or false, and return based true/false.
So far, made this code but as I understand it doesn’t recognize object.properties..

const library = [
  {
    title: "Bill Gates",
    author: "The Road Ahead",
    isRead: true
  },
  {
    title: "Steve Jobs",
    author: "Walter Isaacson",
    isRead: true
  },
  {
    title: "Mockingjay: The Final Book of The Hunger Games",
    author: "Suzanne Collins",
    isRead: false
  }
];

const showStatus = (arg) => {
  let book = arg;
  for(let i = 0;i < book.length; i++){
    if(book.isRead === true){
       console.log(`Already read ${book.title} by ${book.author}.`)
    } else {
      console.log(`You still need to read ${book.title} by ${book.author}`)
    }

  }

};

showStatus(library);

Getting all the objects in the JavaScript from Django

I want to get all my object models from the database and store them in someway, the model I have is:

class Device (models.Model):
    patientId = models.IntegerField(unique=True)
    deviceId = models.CharField(unique=True,max_length=100)
    hour = models.DateTimeField()
    type = models.IntegerField()
    glucoseValue = models.IntegerField()

I’m sending them in views.py:

device_list = list(Device.objects.all())
context = {"filename": filename,
           "deviceList": device_list,
               }

In JS I managed to get each object like that:

{% for item in deviceList%}
console.log( "{{item}}" );
{% endfor %}

What I want is to store those objects in some way, but I don’t really know how, because they are coming like that Model object (1).

Dimension Converter

Trying to make a website with multiple different dimension conversions. have successfully completed length however with almost the exact same code weight is not working. Here is my code:

    <section class="inputsW">
                <input type="number"  name="tonne" id="tonne" class="inputW" placeholder="Tonnes">
                
                <input type="number" name="kilo" id="kilo" class="inputW" placeholder="Kilograms">
                
                <input type="number" name="gram" id="gram" class="inputW" placeholder="Grams">
                
                <input type="number" name="milligram" id="milligram" class="inputW" placeholder="Milligrams">
                
                <input type="number" name="ton" id="ton" class="inputW" placeholder="US Tons">
                
                <input type="number" name="stone" id="stone" class="inputW" placeholder="Stone">
                
                <input type="number" name="pound" id="pound" class="inputW" placeholder="Pounds">
                
                <input type="number" name="ounce" id="ounce" class="inputW" placeholder="Ounces">
                
            </section>

I am pretty happy with my html, I believe the problem lies within the (e.target.name) for the switch statement as this code works perfectly well for the first converter.

const tonneInput = document.getElementById("tonne");
const kiloInput = document.getElementById("kilo");
const gramInput = document.getElementById("gram");
const milligramInput = document.getElementById("milligram");
const tonInput = document.getElementById("ton");
const stoneInput = document.getElementById("stone");
const poundInput = document.getElementById("pound");
const ounceInput = document.getElementById("ounce");
const inputs = document.getElementsByClassName("input");


for (let i = 0; i < inputsL.length; i++) {
  let input = inputsL[i];

    input.addEventListener("input", function (e) {
        let value = parseFloat(e.target.value);
    
    
        switch (e.target.name) {
            case "tonne":
            
                kiloInput.value = (value*1000).toPrecision(4);
                gramInput.value = (value*1e+6).toPrecision(4);
                milligramInput.value = (value*1e+9).toPrecision(4);
                tonInput.value = (value*1.102).toPrecision(4);
                stoneInput.value = (value*157).toPrecision(4);
                poundInput.value = (value*2205).toPrecision(4);
                ounceInput.value = (value*35274).toPrecision(4);
               break; 

            case "kilo":
                tonneInput.value = (value/1000).toPrecision(4);
                gramInput.value = (value*1000).toPrecision(4);
                milligramInput.value = (value*1e+6).toPrecision(4);
                tonInput.value = (value/907).toPrecision(4);
                stoneInput.value = (value/6.35).toPrecision(4);
                poundInput.value = (value*2.2046).toPrecision(4);
                ounceInput.value = (value*35.274).toPrecision(4);
                break; 

            case "gram":
                tonneInput.value = (value/1e+6).toPrecision(4);
                kiloInput.value = (value/1000).toPrecision(4);
                milligramInput.value = (value*1000).toPrecision(4);
                tonInput.value = (value/907185).toPrecision(4);
                stoneInput.value = (value/6350).toPrecision(4);
                poundInput.value = (value/454).toPrecision(4);
                ounceInput.value = (value/28.35).toPrecision(4);
                break; 

            case "milligram":
                tonneInput.value = (value/1e+9).toPrecision(4);
                kiloInput.value = (value/1e+6).toPrecision(4);
                gramInput.value = (value/1000).toPrecision(4);
                tonInput.value = (value/9.072e+8).toPrecision(4);
                stoneInput.value = (value/ 6.35e+6).toPrecision(4);
                poundInput.value = (value/453592).toPrecision(4);
                ounceInput.value = (value/28350).toPrecision(4);
                break; 

            case "ton":
                tonneInput.value = (value/1.102).toPrecision(4);
                kiloInput.value = (value*907).toPrecision(4);
                gramInput.value = (value*907185).toPrecision(4);
                milligramInput.value = (value*9.072e+8).toPrecision(4);
                stoneInput.value = (value*143).toPrecision(4);
                poundInput.value = (value*2000).toPrecision(4);
                ounceInput.value = (value*32000).toPrecision(4);
                break; 

            case "stone":
                tonneInput.value = (value/157).toPrecision(4);
                kiloInput.value = (value*6.35).toPrecision(4);
                gramInput.value = (value*6350).toPrecision(4);
                milligramInput.value = (value*6.35e+6).toPrecision(4);
                tonInput.value = (value/143).toPrecision(4);
                poundInput.value = (value*14).toPrecision(4);
                ounceInput.value = (value*224).toPrecision(4);
                break; 
    
            case "pound":
                tonneInput.value = (value/2205).toPrecision(4);
                kiloInput.value = (value/2.205).toPrecision(4);
                gramInput.value = (value*454).toPrecision(4);
                milligramInput.value = (value*453592).toPrecision(4);
                tonInput.value = (value/2000).toPrecision(4);
                stoneInput.value = (value/14).toPrecision(4);
                ounceInput.value = (value*16).toPrecision(4);
                break; 
    
            case "ounce":
                tonneInput.value = (value/35274).toPrecision(4);
                kiloInput.value = (value/35.274).toPrecision(4);
                gramInput.value = (value*28.35).toPrecision(4);
                milligramInput.value = (value*28350).toPrecision(4);
                tonInput.value = (value/32000).toPrecision(4);
                stoneInput.value = (value/224).toPrecision(4);
                poundInput.value = (value/16).toPrecision(4);
                break; 
            default:
    }
  });
}

JavaScript On-click Function to start and stop Intervals

I have two onclick functions that performing start and stop functions using socket when i click start it start requesting images from server(i am using intervals) when i click stop the server is stopped but the request keep coming to the server. the intervals seems not stopped after clicking kindly review my code

Code:

  var interval;
  
  function onclick() {
    interval = setInterval(() => {
      socket.emit("get_image", "Click");
      socket.on('send_image', (message) => {
        setImage(message.image); 
      });
    }, 350)
  }

  function onclicks() {
    clearInterval(interval);
    setImage(blanked);

  }

I have tried to add clearInterval function but it seems not working

how to filter based on two values from the array of array

I have a bunch array of objects with participants and messages, I want to filter the object with the below array of two participants, can anyone help with this

this is the example participnats of array :

["61badffe4ccf060b329441e0","61bc33a84ccf060b32944354"]

bunch of sample messages and participants :

  {
    "messages": [],
    "participants": [
      "61badffe4ccf060b329441e0",
      "61bae01b4ccf060b329441ef"
    ],
    "_id": "61bae0394ccf060b329441fb",
  },
  {
    "messages": [],
    "participants": [
      "61bae1014ccf060b3294420e",
      "61bae01b4ccf060b329441ef"
    ],
    "_id": "61bb230c4ccf060b3294421c"
  },
  {
    "messages": [],
    "participants": [
      "61badffe4ccf060b329441e0",
      "61bc33a84ccf060b32944354"
    ],
    "_id": "61d476dff651471663a72971",
  },
  {
    "messages": [],
    "participants": [
      "61badffe4ccf060b329441e0",
      "61e54b82eab592e7fef65656"
    ],
    "_id": "61e54ba3eab592e7fef6567a",
]





**expected below object after filter participants:** 

```{
    "messages": [],
    "participants": [
      "61badffe4ccf060b329441e0",
      "61bc33a84ccf060b32944354"
    ],
    "_id": "61d476dff651471663a72971",
  },

how to add number to field in every doucment in monogdb using nodejs

my collection has phonenumber field. i want to add 91 infront of phonenumber.

{
"_id": "6137392141bbb7723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":9000000001
},
{
"_id": "6137392141bbe30723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":9000000002
}

i want to update my collection like this.

{
"_id": "6137392141bbb7723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000001
},
{
"_id": "6137392141bbe30723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000002
}

im trying with this code but its not updating the field.

var x = await User.find({});
        x.forEach(async function(d)
            { 
                var phone = d.phonenumber;  
                var newPhoneNumber = 910000000000+phone;
                console.log(newPhoneNumber);

                //update 
            await User.updateMany({},{$set:{phonenumber:newPhoneNumber}},
                {
                    new: true, 
                    runValidators : true
                });
            })

im getting only one value for all documents like this:

{
"_id": "6137392141bbb7723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000001
},
{
"_id": "6137392141bbe30723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000001
},
{
"_id": "6137392141bbe30723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000001
}

i don’t know whether this approach is correct or not.Thank you