const API = require('../../lib/API.js') const { BaseStdResponse } = require('../../BaseStdResponse.js') const { importFromRemoteUrl, batchCheckProxies, getGlobalOrThrow } = require('../../lib/Lepao/lepaoProxyPoolService') /** * Corn:拉取全局 import_url 上的代理文本并写入池,随后全表探活。 * 建议由 crontab 定时 GET 调用(与 UpdateState 类同,依赖网络隔离)。 */ class ProxySync extends API { constructor() { super() this.noEncrypt() this.setPath('/Corn/ProxySync') this.setMethod('GET') } async onRequest(req, res) { try { res.json({ ...BaseStdResponse.OK }) try { const g = await getGlobalOrThrow() const url = String(g.import_url || '').trim() if (!url) { this.logger.error('[Corn/ProxySync] import_url 为空') return } const impr = await importFromRemoteUrl(url, 'cron') this.logger.info(`[Corn/ProxySync] 导入完成 imported=${impr.imported} url=${url}`) } catch (e) { this.logger.error(`[Corn/ProxySync] 导入失败: ${e.stack || e}`) } try { const st = await batchCheckProxies(null, { logger: this.logger }) this.logger.info( `[Corn/ProxySync] 探活完成 total=${st.total} ok=${st.ok} fail=${st.fail} probe=${st.probeUrl}` ) } catch (e) { this.logger.error(`[Corn/ProxySync] 探活失败: ${e.stack || e}`) } } catch (e) { this.logger.error(`[Corn/ProxySync]: ${e.stack || e}`) } } } module.exports.ProxySync = ProxySync