添加每日追踪器同步工作流和同步脚本
This commit is contained in:
28
.github/workflows/daily-tracker-sync.yml
vendored
Normal file
28
.github/workflows/daily-tracker-sync.yml
vendored
Normal file
@@ -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
|
||||||
50
sync-trackers.js
Normal file
50
sync-trackers.js
Normal file
@@ -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();
|
||||||
Reference in New Issue
Block a user