(url: string)
| 20 | } |
| 21 | |
| 22 | export async function downloadSteam(url: string): Promise<string> { |
| 23 | const tmpPath = path.normalize(path.join(process.cwd(), "lib", "tmp_steamcmd.zip")); |
| 24 | logger.info(`Starting Steam command line tool download: ${url} --> ${tmpPath}`); |
| 25 | |
| 26 | return new Promise(async (resolve, reject) => { |
| 27 | try { |
| 28 | // Ensure target directory exists |
| 29 | const targetDir = path.dirname(tmpPath); |
| 30 | if (!fs.existsSync(targetDir)) { |
| 31 | fs.mkdirsSync(targetDir); |
| 32 | } |
| 33 | |
| 34 | // Remove existing file if it exists |
| 35 | if (fs.existsSync(tmpPath)) { |
| 36 | fs.removeSync(tmpPath); |
| 37 | } |
| 38 | |
| 39 | // Download file |
| 40 | const response = await axios<Readable>({ |
| 41 | url: url, |
| 42 | responseType: "stream", |
| 43 | timeout: 1000 * 60 * 10, // 10 minutes timeout |
| 44 | headers: getCommonHeaders(url) |
| 45 | }); |
| 46 | |
| 47 | // Create write stream |
| 48 | const writeStream = fs.createWriteStream(path.normalize(tmpPath)); |
| 49 | |
| 50 | // Use pipeline to handle streams |
| 51 | pipeline(response.data, writeStream, async (err) => { |
| 52 | if (err) { |
| 53 | fs.remove(tmpPath, () => {}); |
| 54 | reject(err); |
| 55 | } else { |
| 56 | fs.chmod(tmpPath, 0o755, () => {}); |
| 57 | resolve(tmpPath); |
| 58 | } |
| 59 | }); |
| 60 | } catch (error: any) { |
| 61 | reject(error.message || error); |
| 62 | } |
| 63 | }); |
| 64 | } |
no test coverage detected