How to use nodejs to call WeChat Mini Programs's [get temporary material] interface, and download the material to the local?

I want to use nodejs to call WeChat Mini Programs"s API "get temporary material" to download the material locally. So far, I have written a logic that can be downloaded locally, but the file format can only be defined as" jpeg", "assuming that the material type is unknown, how to download? Does anyone know how to handle it? Is it convenient to paste the code?
paste my code

  * downloadPic(url = "", path = "") {
    // url: 
    // path: 
    // TODO jpg
    url = {url: url}
    const fs = require("fs")
    const request = require("request")
    // 
    if (!fs.existsSync(path)) {
      fs.mkdirSync(path);
    }
    path = path + "/" + this.getRandom(20) + ".jpeg" 
    yield new Promise((resolve, reject) => {  
      request  
        .get(url)  
        .on("response", (response) => {  
          console.log("img type:", response.headers["content-type"])  
        })  
        .pipe(fs.createWriteStream(path))  
        .on("error", (e) => {  
          console.log("pipe error", e)  
          resolve("");  
        })  
        .on("finish", () => {  
          console.log("finish");  
          resolve("ok");  
        })  
        .on("close", () => {  
          console.log("close");  
        })  
    })
    // 
    return path.replace("app/", "")
  }
Apr.07,2021

is saved as a tmp file first, and then according to the header, of content-type, according to content-type comparison table , the correct suffix can be changed to

.
Menu