From b30bdfdf39545ffaa9fbfea6fe2cc1e9ebc7fef0 Mon Sep 17 00:00:00 2001 From: Hsdi Date: Mon, 16 Mar 2026 01:27:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=AF=8F=E6=97=A5=E8=BF=BD?= =?UTF-8?q?=E8=B8=AA=E5=99=A8=E5=90=8C=E6=AD=A5=E5=B7=A5=E4=BD=9C=E6=B5=81?= =?UTF-8?q?=E5=92=8C=E5=90=8C=E6=AD=A5=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/daily-tracker-sync.yml | 28 +++++++++++++ sync-trackers.js | 50 ++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 .github/workflows/daily-tracker-sync.yml create mode 100644 sync-trackers.js diff --git a/.github/workflows/daily-tracker-sync.yml b/.github/workflows/daily-tracker-sync.yml new file mode 100644 index 0000000..aa65ef3 --- /dev/null +++ b/.github/workflows/daily-tracker-sync.yml @@ -0,0 +1,28 @@ +name: Daily Tracker Sync + +on: + schedule: + - cron: '0 0 * * *' # 每天凌晨运行 + workflow_dispatch: # 允许手动在页面点击“重新运行” + +jobs: + update-list: + runs-on: ubuntu-latest # 你的 act_runner 标签 + steps: + - uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Run sync script + run: node sync-trackers.js + + - name: Commit and Push + run: | + git config --local user.email "action@gitea.com" + git config --local user.name "Gitea Action" + git add list/ + git commit -m "Update tracker list: $(date +%Y-%m-%d)" || exit 0 + git push origin main diff --git a/sync-trackers.js b/sync-trackers.js new file mode 100644 index 0000000..7c0f4b2 --- /dev/null +++ b/sync-trackers.js @@ -0,0 +1,50 @@ +const fs = require('fs'); +const path = require('path'); + +async function syncTrackers() { + const today = new Date().toISOString().split('T')[0]; + const dirPath = path.join(__dirname, 'list'); + const filePath = path.join(dirPath, `${today}.txt`); + + // 1. 检查文件是否已存在 + if (fs.existsSync(filePath)) { + console.log(`文件 ${today}.txt 已存在,跳过下载。`); + return; + } + + const urls = [ + "https://trackerslist.com/all.txt", + "https://trackerslist.com/http.txt" + ]; + + try { + console.log("开始获取追踪器列表..."); + + // 2. 并行获取内容 + const responses = await Promise.all(urls.map(url => + fetch(url).then(res => { + if (!res.ok) throw new Error(`无法获取 ${url}`); + return res.text(); + }) + )); + + // 3. 合并、去重、过滤空行 + const allLines = responses.flatMap(text => text.trim().split('\n')); + const uniqueLines = [...new Set(allLines.map(line => line.trim()))].filter(line => line.length > 0); + const finalContent = uniqueLines.join('\n'); + + // 4. 确保目录存在并保存 + if (!fs.existsSync(dirPath)) { + fs.mkdirSync(dirPath, { recursive: true }); + } + + fs.writeFileSync(filePath, finalContent, 'utf8'); + console.log(`成功生成: ${filePath}`); + + } catch (error) { + console.error("执行出错:", error.message); + process.exit(1); + } +} + +syncTrackers(); \ No newline at end of file