Update index.js
Browse files607 unmodified lines60860961061161261161261361461561661761823 unmodified lines64264364464564664764815 unmodified lines6646656666676686696706716726736746756761 unmodified line67867968067668168268368420 unmodified lines70570670770870971071156 unmodified lines76876977076576676777176876977077277377412 unmodified lines7877887897897907917927936 unmodified lines80080180280280380480580674 unmodified lines88188288388488588688788888989012 unmodified lines9039049059039069079089094 unmodified lines914915916914917918919920607 unmodified lines if (!data.trim()) continue; if (data === "[DONE]") continue; const linejosn = JSON.parse(data); Logger.error(JSON.stringify(linejosn, null, 2), 'Server'); if (linejosn?.error) { if (linejosn?.error) { Logger.error(JSON.stringify(linejosn, null, 2), 'Server'); if(linejosn.error?.name === "RateLimitError"){ CONFIG.API.TEMP_COOKIE = null; } stream.destroy(); reject(new Error("RateLimitError")); return;23 unmodified lines })(); dataPromises.push(processPromise); } catch (error) { Logger.error(error, 'Server'); continue; } }15 unmodified lines CONFIG.IS_IMG_GEN2 = false; resolve(); } catch (error) { Logger.error(error, 'Server'); reject(error); } });
stream.on('error', (error) => { Logger.error(error, 'Server'); reject(error); }); });1 unmodified line Logger.error(error, 'Server'); CONFIG.IS_IMG_GEN = false; CONFIG.IS_IMG_GEN2 = false; throw error; throw new Error(error); }}
20 unmodified lines await new Promise(resolve => setTimeout(resolve, CONFIG.API.RETRY_TIME * retryCount));
} catch (error) { Logger.error(error, 'Server'); retryCount++; if (retryCount === MAX_RETRIES) { throw error;56 unmodified lines } else { Logger.info("生图成功", 'Server'); const result = await responseURL.json(); try { var url = result.data.links.url return `` return `` } catch (error) { return error } } }}12 unmodified lines allowedHeaders: ['Content-Type', 'Authorization']}));
app.get('/hf/v1/models', (req, res) => {app.get('/v1/models', (req, res) => { res.json({ object: "list", data: Object.keys(CONFIG.MODELS).map((model, index) => ({6 unmodified lines});
app.post('/hf/v1/chat/completions', async (req, res) => {app.post('/v1/chat/completions', async (req, res) => { try { const authToken = req.headers.authorization?.replace('Bearer ', ''); if (CONFIG.API.IS_CUSTOM_SSO) {74 unmodified lines Logger.info(`当前剩余可用令牌数: ${tokenManager.getTokenCount()}`, 'Server'); try { await handleResponse(response, req.body.model, res, req.body.stream); Logger.info(`请求结束`, 'Server'); return; } catch (error) { Logger.error(error, 'Server'); if (isTempCookie) { await Utils.get_signature(); } else {12 unmodified lines if (response.status === 429) { if (isTempCookie) { await Utils.get_signature(); } else { } else { tokenManager.setModelLimit(CONFIG.SSO_INDEX, req.body.model); for (let i = 1; i <= tokenManager.getTokenCount(); i++) { CONFIG.SSO_INDEX = (CONFIG.SSO_INDEX + 1) % tokenManager.getTokenCount();4 unmodified lines } } } } else { } else { // 非429错误直接抛出 if (isTempCookie) { await Utils.get_signature();index.js+16-13