diff --git a/index.js b/index.js index c5ba5a2..f41d247 100644 --- a/index.js +++ b/index.js @@ -263,9 +263,19 @@ const uploadToSFTP = async () => { try { await sftp.connect(connectOptions); + const remoteFiles = await sftp.list(remote); + for (const file of remoteFiles) { + if (file.name.endsWith(".jar") && files.includes(file.name)) { + const remoteFilePath = path.posix.join(remote, file.name); + console.log(`šŸ—‘ļø Deleting remote file: ${remoteFilePath}`); + await sftp.delete(remoteFilePath); + } + } + + // šŸš€ Upload new files for (const file of files) { const local = path.join(DOWNLOAD_PATH, file); - const remoteFile = path.join(remote, file).replace(/\\/g, "/"); + const remoteFile = path.posix.join(remote, file); console.log(`šŸš€ Uploading ${file} → ${remoteFile}`); await sftp.put(local, remoteFile); } @@ -279,6 +289,12 @@ const uploadToSFTP = async () => { // --- Main --- (async () => { ensureDir(DOWNLOAD_PATH); + const existingFiles = fs.readdirSync(DOWNLOAD_PATH).filter(f => f.endsWith(".jar")); + for (const file of existingFiles) { + const filePath = path.join(DOWNLOAD_PATH, file); + fs.unlinkSync(filePath); + console.log(`šŸ—‘ļø Deleted local file: ${file}`); + } for (const url of config.urls) { console.log(`\nšŸ“„ ${url}`); diff --git a/package.json b/package.json index a295312..2004b6c 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "download-plugs", - "version": "1.0.0", + "version": "1.0.4", "main": "index.js", "scripts": { "run": "node index.js" }, "keywords": [], "author": "Sophia Atkinson", - "license": "MIT?", + "license": "MIT", "description": "", "dependencies": { "axios": "^1.9.0",