patch downloading and uploading
This commit is contained in:
18
index.js
18
index.js
@ -263,9 +263,19 @@ const uploadToSFTP = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await sftp.connect(connectOptions);
|
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) {
|
for (const file of files) {
|
||||||
const local = path.join(DOWNLOAD_PATH, file);
|
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}`);
|
console.log(`🚀 Uploading ${file} → ${remoteFile}`);
|
||||||
await sftp.put(local, remoteFile);
|
await sftp.put(local, remoteFile);
|
||||||
}
|
}
|
||||||
@ -279,6 +289,12 @@ const uploadToSFTP = async () => {
|
|||||||
// --- Main ---
|
// --- Main ---
|
||||||
(async () => {
|
(async () => {
|
||||||
ensureDir(DOWNLOAD_PATH);
|
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) {
|
for (const url of config.urls) {
|
||||||
console.log(`\n📥 ${url}`);
|
console.log(`\n📥 ${url}`);
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "download-plugs",
|
"name": "download-plugs",
|
||||||
"version": "1.0.0",
|
"version": "1.0.4",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"run": "node index.js"
|
"run": "node index.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Sophia Atkinson",
|
"author": "Sophia Atkinson",
|
||||||
"license": "MIT?",
|
"license": "MIT",
|
||||||
"description": "",
|
"description": "",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.9.0",
|
"axios": "^1.9.0",
|
||||||
|
Reference in New Issue
Block a user