Spaces:
webzepetoku
/
Sleeping

webzepetoku commited on
Commit
bb8b08c
·
verified ·
1 Parent(s): 9d075ae

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +50 -80
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
- * FUNGSI: Mencari file secara rekursif (Anti-Nesting)
18
  */
19
- function findFileInDir(dir, extension) {
20
- const files = fs.readdirSync(dir);
21
- for (const file of files) {
22
- const fullPath = path.join(dir, file);
23
- if (fs.lstatSync(fullPath).isDirectory()) {
24
- const found = findFileInDir(fullPath, extension);
 
 
 
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 v8.0 untuk: ${targetFilename}`);
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] Mendownload Baju Raksasa...`);
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 & Pemetaan Struktur...`);
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: Mencari organ inti Dummy (KTP) di manapun letaknya
97
- const dummyMetaPath = findFileInDir(extDummy, '.prefab.meta');
98
- if (!dummyMetaPath) throw new Error("File .meta Dummy tidak ditemukan! Pastikan dummy_lite.zepeto.zip benar.");
99
-
100
- const dummyPrefabName = path.basename(dummyMetaPath, '.meta'); // untitled.prefab
 
101
  const stageBundles = path.join(stagePath, 'assetbundles');
102
  fs.mkdirSync(stageBundles, { recursive: true });
103
 
104
- // 1. Salin KTP Dummy (.meta) ke Stage Root (Lantai Dasar)
105
  fs.copyFileSync(dummyMetaPath, path.join(stagePath, dummyPrefabName + '.meta'));
106
 
107
- // 2. Cari & Salin Kertas Raksasa (.prefab) ke Stage Root (Ganti Nama agar menyamar)
108
- const hpPrefabPath = findFileInDir(extHP, '.prefab');
109
  if (!hpPrefabPath) throw new Error("File .prefab Raksasa tidak ditemukan!");
110
  fs.copyFileSync(hpPrefabPath, path.join(stagePath, dummyPrefabName));
111
 
112
- // 3. Identifikasi Folder Biner (AssetBundles)
113
- const hpBundleDir = findAssetBundlesDir(extHP);
114
- const dummyBundleDir = findAssetBundlesDir(extDummy);
115
- if (!hpBundleDir || !dummyBundleDir) throw new Error("Folder assetbundles tidak ditemukan di salah satu file!");
116
 
117
- // Salin isi HP bundles ke stage/assetbundles sebagai bahan dasar patching
118
- const hpPlatforms = fs.readdirSync(hpBundleDir);
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 pada Struktur Flat...`);
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("Patching biner gagal di level bit.");
133
-
134
- logMsg(`[STEP 4] Repacking ZIP (Akar Murni Tanpa Folder Pembungkus)...`);
135
- await createZepetoFile(stagePath, finalOut);
136
-
137
- logMsg(`[SUCCESS] Selesai! Struktur 100% Flat Root & Ukuran Biner Identik.\n`);
138
-
139
- res.download(finalOut, targetFilename, () => {
140
- try {
141
- fs.rmSync(extDummy, { recursive: true, force: true });
142
- fs.rmSync(extHP, { recursive: true, force: true });
143
- fs.rmSync(stagePath, { recursive: true, force: true });
144
- fs.unlinkSync(tempHP);
145
- fs.unlinkSync(finalOut);
146
- } catch (e) {}
 
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 Surgical v8.0 Aktif!`));
 
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!`));