MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / downloadSteam

Function downloadSteam

daemon/src/tools/steam_cmd.ts:22–64  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

20}
21
22export 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}

Callers 1

initSteamCmdFunction · 0.85

Calls 3

getCommonHeadersFunction · 0.90
infoMethod · 0.80
chmodMethod · 0.80

Tested by

no test coverage detected