Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
e4210aa9db
|
|||
|
ec1b8a4929
|
48
index.js
48
index.js
@@ -61,6 +61,8 @@ const ensureDir = (dir) => {
|
|||||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
|
||||||
};
|
};
|
||||||
const DOWNLOAD_PATH = config.global.downloadPath || "downloads";
|
const DOWNLOAD_PATH = config.global.downloadPath || "downloads";
|
||||||
|
ensureDir(DOWNLOAD_PATH);
|
||||||
|
|
||||||
const isDownloaded = (filename) => fs.existsSync(path.join(DOWNLOAD_PATH, filename));
|
const isDownloaded = (filename) => fs.existsSync(path.join(DOWNLOAD_PATH, filename));
|
||||||
|
|
||||||
const downloadJar = async (url, name) => {
|
const downloadJar = async (url, name) => {
|
||||||
@@ -98,7 +100,7 @@ const handleJenkins = async (url) => {
|
|||||||
|
|
||||||
const base = new URL(url);
|
const base = new URL(url);
|
||||||
const preferred = ["paper", "spigot", "bukkit"];
|
const preferred = ["paper", "spigot", "bukkit"];
|
||||||
const skip = ["javadoc", "sources", "cli", "bootstrap", "mojangapi", "nashorn", "remapper"];
|
const skip = ["javadoc", "sources", "cli", "bootstrap", "mojangapi", "nashorn", "remapper", "fabric", "neoforge"];
|
||||||
const essentialsOK = ["EssentialsX", "EssentialsXChat", "EssentialsXSpawn", "EssentialsXGeoIP"];
|
const essentialsOK = ["EssentialsX", "EssentialsXChat", "EssentialsXSpawn", "EssentialsXGeoIP"];
|
||||||
|
|
||||||
const valid = links
|
const valid = links
|
||||||
@@ -125,8 +127,7 @@ const handleJenkins = async (url) => {
|
|||||||
|
|
||||||
// Fallback: all valid jars
|
// Fallback: all valid jars
|
||||||
for (const f of valid) {
|
for (const f of valid) {
|
||||||
const finalURL = new URL(f.href, base).href;
|
await downloadJar(new URL(f.href, base).href, path.basename(f.href));
|
||||||
await downloadJar(finalURL, path.basename(f.href));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -245,7 +246,7 @@ const uploadToSFTP = async () => {
|
|||||||
|
|
||||||
const sftp = new SftpClient();
|
const sftp = new SftpClient();
|
||||||
const remote = sftpConfig.remotePath || "/";
|
const remote = sftpConfig.remotePath || "/";
|
||||||
const files = fs.readdirSync(DOWNLOAD_PATH).filter((f) => f.endsWith(".jar"));
|
const localFiles = fs.readdirSync(DOWNLOAD_PATH).filter(f => f.endsWith(".jar"));
|
||||||
|
|
||||||
const connectOptions = {
|
const connectOptions = {
|
||||||
host: sftpConfig.host,
|
host: sftpConfig.host,
|
||||||
@@ -261,28 +262,35 @@ const uploadToSFTP = async () => {
|
|||||||
throw new Error("Missing SFTP password or private key.");
|
throw new Error("Missing SFTP password or private key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const extractBaseName = (filename) => {
|
||||||
|
return filename.replace(/[-_.](v?\d.*)?\.jar$/, "").trim();
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await sftp.connect(connectOptions);
|
await sftp.connect(connectOptions);
|
||||||
const remoteFiles = await sftp.list(remote);
|
const remoteFiles = await sftp.list(remote);
|
||||||
for (const file of remoteFiles) {
|
const remoteJars = remoteFiles.filter(f => f.name.endsWith(".jar"));
|
||||||
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 localFile of localFiles) {
|
||||||
for (const file of files) {
|
const baseName = extractBaseName(localFile);
|
||||||
const local = path.join(DOWNLOAD_PATH, file);
|
const toDelete = remoteJars.filter(remoteFile =>
|
||||||
const remoteFile = path.posix.join(remote, file);
|
extractBaseName(remoteFile.name) === baseName
|
||||||
console.log(`🚀 Uploading ${file} → ${remoteFile}`);
|
);
|
||||||
await sftp.put(local, remoteFile);
|
for (const file of toDelete) {
|
||||||
|
const fullPath = path.posix.join(remote, file.name);
|
||||||
|
await sftp.delete(fullPath);
|
||||||
|
console.log(`🗑️ Deleted remote: ${file.name}`);
|
||||||
|
}
|
||||||
|
// 🚀 Upload new files
|
||||||
|
const localPath = path.join(DOWNLOAD_PATH, localFile);
|
||||||
|
const remotePath = path.posix.join(remote, localFile);
|
||||||
|
await sftp.fastPut(localPath, remotePath);
|
||||||
|
console.log(`⬆️ Uploaded: ${localFile}`);
|
||||||
}
|
}
|
||||||
await sftp.end();
|
|
||||||
console.log("✅ SFTP upload finished.");
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("❌ SFTP upload failed:", err.message);
|
console.error("❌ SFTP Error:", err.message);
|
||||||
|
} finally {
|
||||||
|
sftp.end();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "download-plugs",
|
"name": "download-plugs",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"run": "node index.js"
|
"run": "node index.js"
|
||||||
|
|||||||
Reference in New Issue
Block a user