diff --git a/config.json.example b/config.json.example index f70c84f..fc19cba 100644 --- a/config.json.example +++ b/config.json.example @@ -1,4 +1,8 @@ { + "global": { + "useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36", + "downloadPath": "downloads" + }, "urls": [ "https://github.com/McPlugin/SoCool", ], diff --git a/index.js b/index.js index a54992e..c5ba5a2 100644 --- a/index.js +++ b/index.js @@ -60,20 +60,20 @@ if (sftpConfig.password && !sftpConfig.encryptedPassword) { const ensureDir = (dir) => { if (!fs.existsSync(dir)) fs.mkdirSync(dir); }; - -const isDownloaded = (filename) => fs.existsSync(path.join("downloads", filename)); +const DOWNLOAD_PATH = config.global.downloadPath || "downloads"; +const isDownloaded = (filename) => fs.existsSync(path.join(DOWNLOAD_PATH, filename)); const downloadJar = async (url, name) => { if (isDownloaded(name)) { console.log(`🟔 Skipped (already exists): ${name}`); return; } - + const USER_AGENT = config.global?.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36"; const response = await axios.get(url, { responseType: "stream", headers: { "User-Agent": - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36", + USER_AGENT, }, }); @@ -84,7 +84,7 @@ const downloadJar = async (url, name) => { response.data.on("data", (chunk) => bar.increment(chunk.length)); response.data.on("end", () => bar.stop()); - const filePath = path.join("downloads", name); + const filePath = path.join(DOWNLOAD_PATH, name); await pipeline(response.data, fs.createWriteStream(filePath)); console.log(`āœ”ļø Saved: ${name}`); }; @@ -245,7 +245,7 @@ const uploadToSFTP = async () => { const sftp = new SftpClient(); const remote = sftpConfig.remotePath || "/"; - const files = fs.readdirSync("downloads").filter((f) => f.endsWith(".jar")); + const files = fs.readdirSync(DOWNLOAD_PATH).filter((f) => f.endsWith(".jar")); const connectOptions = { host: sftpConfig.host, @@ -264,7 +264,7 @@ const uploadToSFTP = async () => { try { await sftp.connect(connectOptions); for (const file of files) { - const local = path.join("downloads", file); + const local = path.join(DOWNLOAD_PATH, file); const remoteFile = path.join(remote, file).replace(/\\/g, "/"); console.log(`šŸš€ Uploading ${file} → ${remoteFile}`); await sftp.put(local, remoteFile); @@ -278,7 +278,7 @@ const uploadToSFTP = async () => { // --- Main --- (async () => { - ensureDir("downloads"); + ensureDir(DOWNLOAD_PATH); for (const url of config.urls) { console.log(`\nšŸ“„ ${url}`);