Spaces:
Sleeping
Sleeping
Update server.js
Browse files
server.js
CHANGED
|
@@ -14,61 +14,30 @@ const DUMMY_ZIP = 'dummy_lite.zepeto.zip';
|
|
| 14 |
if (!fs.existsSync('uploads')) fs.mkdirSync('uploads', { recursive: true });
|
| 15 |
|
| 16 |
/**
|
| 17 |
-
*
|
| 18 |
*/
|
| 19 |
-
function
|
| 20 |
-
const
|
| 21 |
-
for (const
|
| 22 |
-
const fullPath = path.join(
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
if (found) return found;
|
| 26 |
-
} else if (file.toLowerCase().endsWith(extension)) {
|
| 27 |
-
return fullPath;
|
| 28 |
}
|
| 29 |
}
|
| 30 |
return null;
|
| 31 |
}
|
| 32 |
|
| 33 |
-
/**
|
| 34 |
-
* FUNGSI: Mencari folder assetbundles secara rekursif
|
| 35 |
-
*/
|
| 36 |
-
function findAssetBundlesDir(dir) {
|
| 37 |
-
const files = fs.readdirSync(dir);
|
| 38 |
-
for (const file of files) {
|
| 39 |
-
const fullPath = path.join(dir, file);
|
| 40 |
-
if (fs.lstatSync(fullPath).isDirectory()) {
|
| 41 |
-
if (file.toLowerCase() === 'assetbundles') return fullPath;
|
| 42 |
-
const found = findAssetBundlesDir(fullPath);
|
| 43 |
-
if (found) return found;
|
| 44 |
-
}
|
| 45 |
-
}
|
| 46 |
-
return null;
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* FUNGSI: Membungkus ZIP Flat-Root (Isi folder saja, bukan foldernya)
|
| 51 |
-
*/
|
| 52 |
-
function createZepetoFile(sourceDir, outPath) {
|
| 53 |
-
return new Promise((resolve, reject) => {
|
| 54 |
-
const output = fs.createWriteStream(outPath);
|
| 55 |
-
const archive = archiver('zip', { zlib: { level: 6 } });
|
| 56 |
-
output.on('close', resolve);
|
| 57 |
-
archive.on('error', reject);
|
| 58 |
-
archive.pipe(output);
|
| 59 |
-
// 🎯 KUNCI MUTLAK: Masukkan isi sourceDir langsung ke root ZIP
|
| 60 |
-
archive.directory(sourceDir, false);
|
| 61 |
-
archive.finalize();
|
| 62 |
-
});
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
app.post('/convert', async (req, res) => {
|
| 66 |
const logs = [];
|
| 67 |
const logMsg = (msg) => { console.log(msg); logs.push(msg); };
|
| 68 |
|
| 69 |
const targetFilename = req.body.filename || 'result.zepeto';
|
| 70 |
logMsg(`\n======================================================`);
|
| 71 |
-
logMsg(`[INIT] MENEMBAK! Misi: Flat-Root Surgical Bypass
|
| 72 |
|
| 73 |
const timeId = Date.now();
|
| 74 |
const tempHP = path.join(__dirname, 'uploads', `hp_${timeId}.zepeto`);
|
|
@@ -78,14 +47,14 @@ app.post('/convert', async (req, res) => {
|
|
| 78 |
const finalOut = path.join(__dirname, 'uploads', `final_${timeId}.zepeto`);
|
| 79 |
|
| 80 |
try {
|
| 81 |
-
logMsg(`[STEP 1]
|
| 82 |
const response = await axios({ method: 'GET', url: req.body.file_url, responseType: 'stream' });
|
| 83 |
const writer = fs.createWriteStream(tempHP);
|
| 84 |
response.data.pipe(writer);
|
| 85 |
|
| 86 |
writer.on('finish', async () => {
|
| 87 |
try {
|
| 88 |
-
logMsg(`[STEP 2] Ekstraksi &
|
| 89 |
fs.mkdirSync(extDummy, { recursive: true });
|
| 90 |
fs.mkdirSync(extHP, { recursive: true });
|
| 91 |
fs.mkdirSync(stagePath, { recursive: true });
|
|
@@ -93,58 +62,59 @@ app.post('/convert', async (req, res) => {
|
|
| 93 |
execSync(`unzip -q -o "${DUMMY_ZIP}" -d "${extDummy}"`);
|
| 94 |
execSync(`unzip -q -o "${tempHP}" -d "${extHP}"`);
|
| 95 |
|
| 96 |
-
// 🎯 TEKNIK FLAT-ROOT:
|
| 97 |
-
const dummyMetaPath =
|
| 98 |
-
if (!dummyMetaPath) throw new Error("File .meta Dummy tidak ditemukan!
|
| 99 |
-
|
| 100 |
-
|
|
|
|
| 101 |
const stageBundles = path.join(stagePath, 'assetbundles');
|
| 102 |
fs.mkdirSync(stageBundles, { recursive: true });
|
| 103 |
|
| 104 |
-
//
|
| 105 |
fs.copyFileSync(dummyMetaPath, path.join(stagePath, dummyPrefabName + '.meta'));
|
| 106 |
|
| 107 |
-
//
|
| 108 |
-
const hpPrefabPath =
|
| 109 |
if (!hpPrefabPath) throw new Error("File .prefab Raksasa tidak ditemukan!");
|
| 110 |
fs.copyFileSync(hpPrefabPath, path.join(stagePath, dummyPrefabName));
|
| 111 |
|
| 112 |
-
//
|
| 113 |
-
const hpBundleDir =
|
| 114 |
-
const dummyBundleDir =
|
| 115 |
-
if (!hpBundleDir || !dummyBundleDir) throw new Error("Folder assetbundles tidak ditemukan
|
| 116 |
|
| 117 |
-
// Salin
|
| 118 |
-
|
| 119 |
-
hpPlatforms.forEach(p => {
|
| 120 |
const src = path.join(hpBundleDir, p);
|
| 121 |
-
if (fs.lstatSync(src).isFile())
|
| 122 |
-
fs.copyFileSync(src, path.join(stageBundles, p));
|
| 123 |
-
}
|
| 124 |
});
|
| 125 |
|
| 126 |
-
logMsg(`[STEP 3] Surgical Patching
|
| 127 |
try {
|
| 128 |
-
// Kita kirim folder stageBundles dan hpBundleDir sebagai referensi
|
| 129 |
const pyLog = execSync(`python3 uabe_packer.py "${stageBundles}" "${hpBundleDir}"`).toString();
|
| 130 |
logMsg(`[UABE LOG]\n${pyLog}`);
|
| 131 |
|
| 132 |
-
if (!pyLog.includes('Injeksi selesai 100%')) throw new Error("
|
| 133 |
-
|
| 134 |
-
logMsg(`[STEP 4]
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
| 147 |
});
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
} catch (pyErr) {
|
| 150 |
logMsg(`[CRASH] ${pyErr.message}`);
|
|
@@ -161,4 +131,4 @@ app.post('/convert', async (req, res) => {
|
|
| 161 |
}
|
| 162 |
});
|
| 163 |
|
| 164 |
-
app.listen(7860, () => console.log(`🚀 Server Flat-Root
|
|
|
|
| 14 |
if (!fs.existsSync('uploads')) fs.mkdirSync('uploads', { recursive: true });
|
| 15 |
|
| 16 |
/**
|
| 17 |
+
* MENCARI FILE/FOLDER SECARA DINAMIS (Anti-Struktur Berantakan)
|
| 18 |
*/
|
| 19 |
+
function findPath(base, targetName, isFolder = false) {
|
| 20 |
+
const items = fs.readdirSync(base);
|
| 21 |
+
for (const item of items) {
|
| 22 |
+
const fullPath = path.join(base, item);
|
| 23 |
+
const stat = fs.lstatSync(fullPath);
|
| 24 |
+
if (isFolder && stat.isDirectory() && item.toLowerCase() === targetName.toLowerCase()) return fullPath;
|
| 25 |
+
if (!isFolder && stat.isFile() && item.toLowerCase().endsWith(targetName.toLowerCase())) return fullPath;
|
| 26 |
+
if (stat.isDirectory()) {
|
| 27 |
+
const found = findPath(fullPath, targetName, isFolder);
|
| 28 |
if (found) return found;
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
}
|
| 31 |
return null;
|
| 32 |
}
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
app.post('/convert', async (req, res) => {
|
| 35 |
const logs = [];
|
| 36 |
const logMsg = (msg) => { console.log(msg); logs.push(msg); };
|
| 37 |
|
| 38 |
const targetFilename = req.body.filename || 'result.zepeto';
|
| 39 |
logMsg(`\n======================================================`);
|
| 40 |
+
logMsg(`[INIT] MENEMBAK! Misi: Flat-Root Surgical Bypass v9.0 untuk: ${targetFilename}`);
|
| 41 |
|
| 42 |
const timeId = Date.now();
|
| 43 |
const tempHP = path.join(__dirname, 'uploads', `hp_${timeId}.zepeto`);
|
|
|
|
| 47 |
const finalOut = path.join(__dirname, 'uploads', `final_${timeId}.zepeto`);
|
| 48 |
|
| 49 |
try {
|
| 50 |
+
logMsg(`[STEP 1] Downloading Baju Raksasa...`);
|
| 51 |
const response = await axios({ method: 'GET', url: req.body.file_url, responseType: 'stream' });
|
| 52 |
const writer = fs.createWriteStream(tempHP);
|
| 53 |
response.data.pipe(writer);
|
| 54 |
|
| 55 |
writer.on('finish', async () => {
|
| 56 |
try {
|
| 57 |
+
logMsg(`[STEP 2] Ekstraksi & Rekonstruksi Struktur...`);
|
| 58 |
fs.mkdirSync(extDummy, { recursive: true });
|
| 59 |
fs.mkdirSync(extHP, { recursive: true });
|
| 60 |
fs.mkdirSync(stagePath, { recursive: true });
|
|
|
|
| 62 |
execSync(`unzip -q -o "${DUMMY_ZIP}" -d "${extDummy}"`);
|
| 63 |
execSync(`unzip -q -o "${tempHP}" -d "${extHP}"`);
|
| 64 |
|
| 65 |
+
// 🎯 TEKNIK FLAT-ROOT: Ambil identitas Dummy (.meta)
|
| 66 |
+
const dummyMetaPath = findPath(extDummy, '.prefab.meta', false);
|
| 67 |
+
if (!dummyMetaPath) throw new Error("File .meta Dummy tidak ditemukan!");
|
| 68 |
+
const dummyPrefabName = path.basename(dummyMetaPath, '.meta');
|
| 69 |
+
|
| 70 |
+
// Siapkan folder Stage (Root Level)
|
| 71 |
const stageBundles = path.join(stagePath, 'assetbundles');
|
| 72 |
fs.mkdirSync(stageBundles, { recursive: true });
|
| 73 |
|
| 74 |
+
// Salin .meta dummy ke Root Stage
|
| 75 |
fs.copyFileSync(dummyMetaPath, path.join(stagePath, dummyPrefabName + '.meta'));
|
| 76 |
|
| 77 |
+
// Cari & Salin .prefab raksasa ke Root Stage (Ganti Nama)
|
| 78 |
+
const hpPrefabPath = findPath(extHP, '.prefab', false);
|
| 79 |
if (!hpPrefabPath) throw new Error("File .prefab Raksasa tidak ditemukan!");
|
| 80 |
fs.copyFileSync(hpPrefabPath, path.join(stagePath, dummyPrefabName));
|
| 81 |
|
| 82 |
+
// Identifikasi Folder Biner
|
| 83 |
+
const hpBundleDir = findPath(extHP, 'assetbundles', true);
|
| 84 |
+
const dummyBundleDir = findPath(extDummy, 'assetbundles', true);
|
| 85 |
+
if (!hpBundleDir || !dummyBundleDir) throw new Error("Folder assetbundles tidak ditemukan!");
|
| 86 |
|
| 87 |
+
// Salin biner raksasa ke stage
|
| 88 |
+
fs.readdirSync(hpBundleDir).forEach(p => {
|
|
|
|
| 89 |
const src = path.join(hpBundleDir, p);
|
| 90 |
+
if (fs.lstatSync(src).isFile()) fs.copyFileSync(src, path.join(stageBundles, p));
|
|
|
|
|
|
|
| 91 |
});
|
| 92 |
|
| 93 |
+
logMsg(`[STEP 3] Surgical Patching...`);
|
| 94 |
try {
|
|
|
|
| 95 |
const pyLog = execSync(`python3 uabe_packer.py "${stageBundles}" "${hpBundleDir}"`).toString();
|
| 96 |
logMsg(`[UABE LOG]\n${pyLog}`);
|
| 97 |
|
| 98 |
+
if (!pyLog.includes('Injeksi selesai 100%')) throw new Error("Gagal memalsukan identitas biner!");
|
| 99 |
+
|
| 100 |
+
logMsg(`[STEP 4] Packing ZIP Flat-Root...`);
|
| 101 |
+
const output = fs.createWriteStream(finalOut);
|
| 102 |
+
const archive = archiver('zip', { zlib: { level: 6 } });
|
| 103 |
+
output.on('close', () => {
|
| 104 |
+
logMsg(`[SUCCESS] Bypass Berhasil! Struktur 100% Flat & CAB Identik.\n`);
|
| 105 |
+
res.download(finalOut, targetFilename, () => {
|
| 106 |
+
try {
|
| 107 |
+
fs.rmSync(extDummy, { recursive: true, force: true });
|
| 108 |
+
fs.rmSync(extHP, { recursive: true, force: true });
|
| 109 |
+
fs.rmSync(stagePath, { recursive: true, force: true });
|
| 110 |
+
fs.unlinkSync(tempHP);
|
| 111 |
+
fs.unlinkSync(finalOut);
|
| 112 |
+
} catch (e) {}
|
| 113 |
+
});
|
| 114 |
});
|
| 115 |
+
archive.pipe(output);
|
| 116 |
+
archive.directory(stagePath, false); // FALSE agar tidak ada folder pembungkus
|
| 117 |
+
archive.finalize();
|
| 118 |
|
| 119 |
} catch (pyErr) {
|
| 120 |
logMsg(`[CRASH] ${pyErr.message}`);
|
|
|
|
| 131 |
}
|
| 132 |
});
|
| 133 |
|
| 134 |
+
app.listen(7860, () => console.log(`🚀 Server Flat-Root v9.0 Aktif!`));
|