MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / downloadFileWithProgress

Function downloadFileWithProgress

plugins/terabox.js:40–71  ·  view source on GitHub ↗
(url, filepath, maxRetries = 3)

Source from the content-addressed store, hash-verified

38 }
39 };
40 const downloadFileWithProgress = async (url, filepath, maxRetries = 3) => {
41 for (let attempt = 1; attempt <= maxRetries; attempt++) {
42 try {
43 const response = await axios({
44 method: 'GET',
45 url,
46 responseType: 'arraybuffer', // Changed to arraybuffer for better stability
47 timeout: 600000, // 10 minutes
48 maxContentLength: Infinity,
49 maxBodyLength: Infinity,
50 headers: {
51 'User-Agent': 'Mozilla/5.0',
52 'Referer': 'https://1024terabox.com/',
53 'Accept': '*/*',
54 'Connection': 'keep-alive'
55 }
56 });
57 fs.writeFileSync(filepath, response.data);
58 return true;
59 }
60 catch (error) {
61 console.error(`Download attempt ${attempt} failed:`, error.message);
62 if (attempt === maxRetries) {
63 throw error;
64 }
65 // Wait before retry
66 const delay = 2000 * attempt;
67 console.log(`Retrying download in ${delay}ms...`);
68 await wait(delay);
69 }
70 }
71 };
72 const isValidTeraBoxUrl = (url) => {
73 return url.includes('terabox.com') ||
74 url.includes('1024terabox.com') ||

Callers 1

handlerFunction · 0.85

Calls 1

waitFunction · 0.70

Tested by

no test coverage detected