Download large file in an external url using javascript and PHP

I have a simple system where a user adds a url of a file he wants to download (for example an image that is on the freepik website), and then via API my PHP system generates the file to be downloaded for the user. The problem is that the API does not return a download link, but an endpoint where I should make a request passing some parameters including my API token to download. So, so that the user doesn’t see this url with my API token, I used this simple code to get the API file and make it available for the user to download:

<?php

   $filename = $_GET['filename'];
   $url = $_GET['url'];

   header('Content-Type: application/octet-stream');
   header("Content-Transfer-Encoding: Binary"); 
   header("Content-disposition: attachment; filename="$filename""); 
   readfile(urldecode($url)); 

This works for small files but when the file is too big it gives out memory limit error.

So my idea would be to rescue pieces of that file that is in the API using javascript and PHP, so that the user could download it little by little, but I don’t know if that would be possible.

Is there a strategy I could use here?

How can I render a list of components in ReactJS using map()?

import React from 'react';
import MyComponent from './MyComponent';

const ItemsList = ({ items }) => {
  return (
    <div>
      {/* Here I'm trying to use map() to render the items */}
      {items.map(item => (
        <MyComponent key={item.id} data={item} />
      ))}
    </div>
  );
};

export default ItemsList;

Hello, I’m developing a web application using ReactJS, and I’m trying to render a list of components based on an array of data. I’m using the JavaScript map() function to iterate through the array and dynamically create the components. However, I’m having trouble getting it to work correctly. My current code is as follows:

However, the components are not being rendered correctly in my application. I have checked the data array, and I’m sure it’s correct. Can anyone help me identify the issue and find a solution to correctly render the list of components using map() in ReactJS? Thanks in advance for the help!

how to style like element like this image with below code?

I provide here some CSS,html and JavaScript code. what i using in my blogspot web site. this code give me another style post view. I have share also a image in this below code.

now I want to show my post on homepage like below image, what i provide here.

So How to show post like this image with below CSS, html and JavaScript code. there is any way to show post like this image.

   
const National = document.querySelector(".national");
     
const populateLabelPosts = (data, container) => {
data.forEach(post => {
const thumbContainer = document.createElement('a');
thumbContainer.href = post.link[post.link.length - 1].href;
thumbContainer.classList.add('thumb-container');
    
const thumbnail = document.createElement('img');
thumbnail.src = post.media$thumbnail.url.replace('/s72', '/s300');
    
thumbContainer.appendChild(thumbnail);
    
const textContent = document.createElement('div');
textContent.classList.add('text-content');
    
const postTitleContainer = document.createElement('a');
postTitleContainer.href = post.link[post.link.length - 1].href;
postTitleContainer.classList.add('post-title-container');   
    
const title = document.createElement('h3');
title.classList.add('post-title');
title.innerHTML = post.title.$t;
    
postTitleContainer.appendChild(title);
        
textContent.appendChild(postTitleContainer);
       
const labelPost = document.createElement('div');
labelPost.classList.add('label-post');
        
labelPost.appendChild(thumbContainer);
labelPost.appendChild(textContent);
    
container.appendChild(labelPost);
});
    
}
    
const displayNational = (posts) => {
populateLabelPosts(posts.feed.entry, National);
}
   
<script src='https://www.sebahotnews.org/feeds/posts/summary/-/জাতীয়?max-results=5&amp;alt=json-in-script&amp;callback=displayNational'></script>
label-posts-container .label-post img {
height: 50px;
object-fit: cover;
width: 100%;
display: flex;
}

.label-posts-container {
display: flex;
flex-direction: column;
gap: 5px;
background: #fff;
padding: 10px;
margin: 10px 0;
align-items: center;
}
.label-posts-container .label-post {
background: #fff;
display: flex;
align-items: center;
width: 100%;
max-width: 400px;
box-shadow: 0 4px 40px -8px rgba(0, 0, 0, 0.3);
}

.label-posts-container .thumb-container {
flex: 0.75;
width: 100%;
}

.label-posts-container .text-content {
flex: 2;
padding: 10px 5px;
display: flex;
flex-direction: column;
}
.label-posts-container .post-title-container {
text-decoration: none;
}
.label-posts-container .post-title-container:hover {
text-decoration: underline;
}

.label-posts-container .post-title {
margin: 0;
font-size: 15px;
margin-bottom: 5px;
color: #000;
line-height: 1.2;
}
<div class='label-posts-container national'>Posts related to জাতীয়:</div>

I want to show my post like this image with above code

Form2CSV Java script > Trying to change the name of the downloaded CSV based on a formfield id value

I’m setting up a Form2CSV Java script. The form works and I can download the form as csv to the local download folder. The downloaded csv file is named generic/ automatically “download.csv” and I would like to change the name of the csv, so that it gets downloaded and named with one for the form field data, example: txtPOC1. How can I do this?



Part1)

<form action="/action_page.php" method="post" required autocomplete="off">

Part2) This is the form field I want to use fopr the csv naming

<td style="width: 300px"><input id="txtPOC1" type="text" rows="1" size="55" name="fPOC1"></td>

Part3) Download Button (class is in here because I also have a print feature added to the form)

<input type="button" id="addButton" class = "no-printme" value="Save to Download Folder" onClick="javascript: addToCSVFile()" />

Part4) The script

    <script type="text/javascript">
    function addToCSVFile() {
    var csvData = new Array();  // To collect the names

    // Collecting the names
    csvData[0] = document.getElementById('txtPOC1').value;
    window.open('data:text/csv;charset=utf-8,' + csvData.join(','));
    
    clearData();
    alert("Saved to Download Folder");
    }
    
    function clearData() {
    document.getElementById('txtPOC1').value = "";
    </script>


Searched online but things didn’t worked out

Enable linter rules to use `useEffect` instead of `React.useEffect` (named export instead of full export)

In our codebase we always wanna use

import { useEffect } from 'react';

instead of

import React from 'react';
// use in code as `React.useEffect`

Is it possible to achieve it with eslint longer rules? If yes then how?

Are there existing solutions?
And if there isn’t existing solution then how to write a custom one?

We wanna use such rules only for the react dependency.

types/value length mismatch (argument=”tuple”, value=’myAddress’

I’m having some problem with the arguments of a funcition writen in solidity and called in javascript. I’m using the Remix ballot default example, except I removed the first require in it. It looks like this:

function giveRightToVote(address voter) public {
    require(
        !voters[voter].voted,
        "The voter already voted."
    );
    require(voters[voter].weight == 0);
    voters[voter].weight = 1;
}

As far as I’m understanding, I should give it an address so it can give permision to that address. This is the javascript code that calls that function:

const permission = async () => {
    const ethereumAddress = web3.utils.toChecksumAddress(account);
    const gasEstimate = await window.contract.methods.giveRightToVote([ethereumAddress]).estimateGas({ from: account });
    console.log("1");
    const result = await window.contract.methods.giveRightToVote(account).send({ gas: gasEstimate, from: account});
    document.getElementById("permissionArea").innerHTML = "Permiso para votar obtenido";
    /**
    await window.contract.methods.giveRightToVote(account).send({ from: account });
    document.getElementById("permissionArea").innerHTML = "Permiso para votar obtenido";
    */
}

The last commented part was the original code. I have changed it a lot trying to make it work. I kind of guess the problem is the argument account. I have tried using [account] wich has worked in another function, but I seem to not be able to figure out how it wants the parameters. I know the account is right, I get it like this:

const accounts = await ethereum.request({method: "eth_requestAccounts"});
account = accounts[0];

And when I print it it’s the right address. The full error reads:

Error: types/value length mismatch (argument="tuple", value=["0x40bCba26F1ED151Fa34232E3CFf55d9C2867bCf1"], code=INVALID_ARGUMENT, version=abi/5.7.0)

I’m still confused that it wants a tuple when the smart contract only takes one argument.

Animating an element being added on click with Javascript

I’m trying to make a contact icon which, when pressed moves to the side, revealing the contact information. I would like the text to remain centred and for the contact info to fade in. So far I have this:

<div class="contacts">
    <div class="contactIcon">ICON<span class="contactInfo"> (+xx)xxxxxxx</span></div>
    <div class="contactIcon">ICON<span class="contactInfo"> (+xx)xxxxxxx</span></div>
</div>
 let contactIcon = document.querySelectorAll('.contactIcon');
    for (let i = 0; i < contactIcon.length; i++) {
        contactIcon[i].addEventListener('click', function () {
            let contactInfo = contactIcon[i].querySelector('.contactInfo');
            if (contactInfo.style.display == 'none') {
                contactInfo.style.visibility = 'visible'
                contactInfo.style.display = 'inline';
                contactInfo.style.maxWidth ='100px';
            }
            else {
                contactInfo.style.visibility = 'hidden';
                contactInfo.style.display = 'none';
                contactInfo.style.maxWidth = '0';
            }
        });
.contactIcon {
    overflow: hidden;
}

.contactInfo {
    visibility: hidden;
    display: none;
    opacity: 1;
    max-width: 500px;
    transition: visibility 0s, opacity 0.3s, max-width 0.6s linear;
}

The code works to a degree, the icon shifts to allow space, but there is no animation and I’m not sure why, I’ve tried toggling a ‘.hide’ class, but also couldn’t get that to work. Also it takes 2 clicks to make the content appear, and I’m struggling to understand that also.

Control script through modifying trigger files on unrelated website

For on-the-fly adjustment of a script distributed amongst multiple internal users, I have the idea to turn various features on/off by the presence or absence of trigger files on a public webserver.

For example, if https://example.com/files/runTest1.txt is present, then show the RunTest1 button. Or maybe, runTest1.jpg? One should be able to detect if the image is present? (Confirmed, this works)

However, I’m not sure (a) if accessing trigger data from a remote text file will work, or (b) how to configure it.

It would be great if I could put some switches (trigger words or key=value pairs) into a remote text file, read the file contents on page load, and set several options that way – but this morning I am drawing a blank on what that might look like.

Here is my current approach:

  1. Create desired number of 55px x 1px transparent background png files
  2. Inject each (invisible) trigger png file onto page via <img> tags
  3. In a setTimeout, get the .offsetWidth for the injected png files
  4. If source png file exists, width will be > 50px, else it will be < 50px (allowing for padding/margins/etc)
  5. By determining if any given source png file exists or not, I can set switches that work across all scripts, tailored for individual users (i.e. no need for separate scripts for each user)

As I say, the above is working but what a kludge. Are there better ideas?

how to use ngx-translate with formly-form to display dynamic error message

I am using formly in my angular application also using ngx-translate for language translation. I have multiple form controls with some custom validation. I want to display error message based on input field title e.g: “First Name is Required”, “Last Name is Required”.but I tried using translate.stream() method but only able to display “is Required” not able add form control label before this.
any suggestion will be very helpful. Thank You.

// form.json
[
  {
    "fieldGroupClassName": "row",
    "key": "applicantDetailsForm",
    "wrappers": [
      "panel"
    ],
    "templateOptions": {
      "label": "Applicant Details"
    },
    "fieldGroup": [
      {
        "key": "salutationCode",
        "type": "salutationList",
        "defaultValue": "",
        "className": "col-lg-3 col-md-6 col-sm-6 col-12",
        "templateOptions": {
          "required": true,
          "label": "form.salutation",
          "options": [],
          "modelObjkey": "applicantDetails",
          "key": "salutationCode",
          "respkey": "salutationDesc",
          "subFieldTypeVal": "ddl",
          "disabled": true
        }
      },
      {
        "key": "firstName",
        "type": "alphaOnly",
        "defaultValue": "",
        "className": "col-lg-3 col-md-6 col-sm-6 col-12",
        "templateOptions": {
          "required": true,
          "label": "form.firstName",
          "type": "text",
          "maxLength": 20,
          "pattern": "^([A-Za-z]+ )+[A-Za-z]+$|^[A-Za-z]+$",
          "modelObjkey": "applicantDetails",
          "key": "firstName",
          "disabled": true
        }
      }
    ]
  }
]

//module.ts
export function registerTranslateExtension(translate: TranslateService) {
  return {
    validationMessages: [
      {
        name: 'required',
        message() {
          return translate.stream('form.isrequired');
        },
      },
    ],
    extensions: [{
      name: 'translate',
      extension: new TranslateExtension(translate),
    }],
  };
}

export function requiredValidationMessage(err, field) {
  let fieldVal = field.templateOptions.labelName ? field.templateOptions.labelName : field.templateOptions.label
  return `${fieldVal} is required`;
}

imports:[
  FormlyModule.forRoot({
      extras:
      validationMessages: [
        { name: 'required', message: requiredValidationMessage }
       ]
       })
],
 providers: [
    { provide: FORMLY_CONFIG, multi: true, useFactory: registerTranslateExtension, deps: [TranslateService] },
  ]

SS

Replace url parameter without changing the others

I want to dynamically change a specific parameter in the navigation bar.
I have this url and want to change “pedro” by “max”:

http://mywebsite.com/?par1=mynameis&par2=pedro&par3=nicetomeetyou

By using this, it removes all my parameters.

hello = "max"
window.history.replaceState(null, null, "?par2="+hello);

This is what I want:

http://mywebsite.com/?par1=mynameis&par2=max&par3=nicetomeetyou

and not

http://mywebsite.com/?par1=mynameis&par2=max

want to integrate appsync api with cognito using SSo of Azure- AD

I have created an appsync api and i wanted to intregate with cognito and Azure-AD for SSO. but in an not able to find any resources for that ho to setup SAML and URLs in azure-AD. right now i am not using Amplify. I wanted to do it without Amplify. just a basic call for graphql api with SSO and have restriction manipulation for data for diff AD-Group like viewer and admin

secure call to access graphql api from simple JS calls