Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
e4210aa9db
|
|||
|
ec1b8a4929
|
46
index.js
46
index.js
@@ -61,6 +61,8 @@ const ensureDir = (dir) => {
|
||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
|
||||
};
|
||||
const DOWNLOAD_PATH = config.global.downloadPath || "downloads";
|
||||
ensureDir(DOWNLOAD_PATH);
|
||||
|
||||
const isDownloaded = (filename) => fs.existsSync(path.join(DOWNLOAD_PATH, filename));
|
||||
|
||||
const downloadJar = async (url, name) => {
|
||||
@@ -98,7 +100,7 @@ const handleJenkins = async (url) => {
|
||||
|
||||
const base = new URL(url);
|
||||
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 valid = links
|
||||
@@ -125,8 +127,7 @@ const handleJenkins = async (url) => {
|
||||
|
||||
// Fallback: all valid jars
|
||||
for (const f of valid) {
|
||||
const finalURL = new URL(f.href, base).href;
|
||||
await downloadJar(finalURL, path.basename(f.href));
|
||||
await downloadJar(new URL(f.href, base).href, path.basename(f.href));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -245,7 +246,7 @@ const uploadToSFTP = async () => {
|
||||
|
||||
const sftp = new SftpClient();
|
||||
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 = {
|
||||
host: sftpConfig.host,
|
||||
@@ -261,28 +262,35 @@ const uploadToSFTP = async () => {
|
||||
throw new Error("Missing SFTP password or private key.");
|
||||
}
|
||||
|
||||
const extractBaseName = (filename) => {
|
||||
return filename.replace(/[-_.](v?\d.*)?\.jar$/, "").trim();
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
const remoteJars = remoteFiles.filter(f => f.name.endsWith(".jar"));
|
||||
|
||||
for (const localFile of localFiles) {
|
||||
const baseName = extractBaseName(localFile);
|
||||
const toDelete = remoteJars.filter(remoteFile =>
|
||||
extractBaseName(remoteFile.name) === baseName
|
||||
);
|
||||
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
|
||||
for (const file of files) {
|
||||
const local = path.join(DOWNLOAD_PATH, file);
|
||||
const remoteFile = path.posix.join(remote, file);
|
||||
console.log(`🚀 Uploading ${file} → ${remoteFile}`);
|
||||
await sftp.put(local, remoteFile);
|
||||
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) {
|
||||
console.error("❌ SFTP upload failed:", err.message);
|
||||
console.error("❌ SFTP Error:", err.message);
|
||||
} finally {
|
||||
sftp.end();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "download-plugs",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"run": "node index.js"
|
||||
|
||||
Reference in New Issue
Block a user