添加每日追踪器同步工作流和同步脚本
This commit is contained in:
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