0

How to get raw url of latest release so i can download through node js streams

import https from "https"
const { pipeline } = require("stream/promises")
import path from "path"
import fs from "fs"

async function download(url) {
    return new Promise(async (onSuccess) => {
        https.get(url, async (res) => {
            let fileName = url.split("/").pop()
            const fileWriteStream = fs.createWriteStream(path.join(__dirname, fileName), {
                autoClose: true,
                flags: "w",
            })
            await pipeline(res, fileWriteStream)
            onSuccess("success")
        })
    })
}
// works fine
await download("https://raw.githubusercontent.com/spicetify/spicetify-cli/master/install.ps1")
// doesnt work
await download("https://github.com/spicetify/spicetify-cli/releases/download/v2.15.0/spicetify-2.15.0-windows-x64.zip")

if this is not possible whats the way to download latest release throught node-js as i use electron

  • Whats the problem with your code? Works on my machine. – Marc Dec 19 '22 at 09:47
  • I want to download the latest release zip from this repo `https://github.com/spicetify/spicetify-cli` when using this link (`https://github.com/spicetify/spicetify-cli/releases/download/v2.15.0/spicetify-2.15.0-windows-x64.zip`) it only saves a file .zip extension there is no contents – Raghavan Vidhyasagar Dec 19 '22 at 11:27
  • Because its a redirect. A get request returns a 302 status. You have to follow the redirect. You have absolutely 0 error handling in your download function. – Marc Dec 19 '22 at 11:40
  • how to get the redirected url? i want that file's url – Raghavan Vidhyasagar Dec 19 '22 at 11:43
  • Look at the http header? Get your self familiar how a http request works and what the status codes mean. – Marc Dec 19 '22 at 13:05

0 Answers0