Spaces:
Sleeping
Sleeping
Update index.js
Browse files11 unmodified lines121314151617186 unmodified lines2526272829303132333435363738394041424344454647484950515253545556575859606162636411 unmodified linesconst fetchWithRetry = async (url, options, maxRetries = 3) => {let lastChunkTime = Date.now();let totalTime = Date.now();let fullResponse = [];let currentRetry = 0;while(currentRetry < maxRetries) {6 unmodified lines}});const reader = response.body.getReader();while(true) {const {value, done} = await reader.read();if(done) break;if(value) {fullResponse.push(value);lastChunkTime = Date.now();}// Проверяем таймаутыconst chunkIdle = Date.now() - lastChunkTime;const totalElapsed = Date.now() - totalTime;if(chunkIdle > 2000 || totalElapsed > 6000) {reader.cancel();currentRetry++;fullResponse = []; // Сбрасываем буферlastChunkTime = Date.now();totalTime = Date.now();break;}}// Если дошли сюда без breaks - значит успешноreturn Buffer.concat(fullResponse);} catch(error) {currentRetry++;if(currentRetry === maxRetries) throw error;}}};// Прокси для всех остальных путей11 unmodified lines1213141516176 unmodified lines24252627282930313233343536373839404142434445464748495051525354555657585911 unmodified linesconst fetchWithRetry = async (url, options, maxRetries = 3) => {let lastChunkTime = Date.now();let totalTime = Date.now();let currentRetry = 0;while(currentRetry < maxRetries) {6 unmodified lines}});let chunks = [];for await (const chunk of response.body) {chunks.push(chunk);lastChunkTime = Date.now();// Проверяем таймаутыconst chunkIdle = Date.now() - lastChunkTime;const totalElapsed = Date.now() - totalTime;if(chunkIdle > 2000 || totalElapsed > 6000) {chunks = [];currentRetry++;lastChunkTime = Date.now();totalTime = Date.now();break;}}// Если дошли сюда со всеми чанками - возвращаем результатif(chunks.length > 0) {return Buffer.concat(chunks);}} catch(error) {currentRetry++;if(currentRetry === maxRetries) throw error;}}throw new Error('Max retries reached');};// Прокси для всех остальных путей
index.js+11-16