deepak191z commited on
Commit
ecb8429
·
verified ·
1 Parent(s): 3117a93

Delete index.js

Browse files
Files changed (1) hide show
  1. index.js +0 -80
index.js DELETED
@@ -1,80 +0,0 @@
1
- const express = require('express');
2
- const fileUpload = require('express-fileupload');
3
- const path = require('path');
4
- const { exec } = require('child_process');
5
- const fs = require('fs').promises;
6
- const rimraf = require('rimraf');
7
-
8
- const app = express();
9
- const PORT = process.env.PORT || 8000; // Use env var or default to 8000
10
- const UPLOAD_DIR = 'uploads';
11
-
12
- // Middleware to handle file uploads with a 500MB limit
13
- app.use(fileUpload({
14
- limits: { fileSize: 500 * 1024 * 1024 }, // 500MB limit
15
- abortOnLimit: true,
16
- }));
17
-
18
- app.use(express.static('public'));
19
-
20
- (async () => {
21
- if (!await fs.access(UPLOAD_DIR).then(() => true).catch(() => false)) {
22
- await fs.mkdir(UPLOAD_DIR);
23
- }
24
- })();
25
-
26
- app.get('/', (req, res) => {
27
- res.sendFile(path.join(__dirname, 'views', 'index.html'));
28
- });
29
-
30
- app.post('/process/debug', async (req, res) => {
31
- if (!req.files || !req.files.file || !req.files.file.name.endsWith('.apk')) {
32
- return res.status(400).json({ error: 'File must be an APK' });
33
- }
34
-
35
- const file = req.files.file;
36
- const sanitizedFileName = file.name.replace(/\s/g, '_');
37
- const filePath = path.join(UPLOAD_DIR, sanitizedFileName);
38
-
39
- try {
40
- await file.mv(filePath);
41
- const outputPath = await debugApk(filePath, UPLOAD_DIR);
42
- if (outputPath && await fs.access(outputPath).then(() => true).catch(() => false)) {
43
- res.download(outputPath, path.basename(outputPath), async (err) => {
44
- if (err) console.error(err);
45
- await cleanupFiles();
46
- });
47
- } else {
48
- await cleanupFiles();
49
- res.status(500).json({ error: 'Failed to debug APK' });
50
- }
51
- } catch (err) {
52
- await cleanupFiles();
53
- res.status(500).json({ error: 'Failed to process request' });
54
- }
55
- });
56
-
57
- function debugApk(inputPath, outputDir) {
58
- return new Promise((resolve) => {
59
- const command = `apk-mitm ${inputPath} -o ${outputDir}`;
60
- exec(command, (error, stdout) => {
61
- if (error) {
62
- console.error(`Error: ${error.message}`);
63
- return resolve(null);
64
- }
65
- const outputFileMatch = stdout.match(/Patched file: (.+)/);
66
- const outputFileName = outputFileMatch ? outputFileMatch[1].trim() : null;
67
- resolve(outputFileName ? path.join(outputDir, outputFileName) : null);
68
- });
69
- });
70
- }
71
-
72
- async function cleanupFiles() {
73
- return new Promise((resolve) => {
74
- rimraf(UPLOAD_DIR, () => resolve());
75
- });
76
- }
77
-
78
- app.listen(PORT, () => {
79
- console.log(`Server running on http://localhost:${PORT}`);
80
- });