Raybilhelp commited on
Commit
a192d44
·
verified ·
1 Parent(s): c1099dd

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +59 -9
app.js CHANGED
@@ -5,6 +5,54 @@ const crypto = require('crypto'); // Telegram Security-এর জন্য ই
5
  const app = express();
6
  app.use(express.json());
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  // ==========================================
9
  // ১. ফায়ারবেজ মাল্টিপল অ্যাডমিন সেটআপ
10
  // ==========================================
@@ -120,6 +168,7 @@ app.post('/creataccoumt', checkPostMethod, verifyTelegramAuth, async (req, res)
120
  join_date: admin.database.ServerValue.TIMESTAMP,
121
  total_refer: 0
122
  };
 
123
  await userRef.set(newUserData);
124
 
125
  if (refer_id) {
@@ -132,10 +181,7 @@ app.post('/creataccoumt', checkPostMethod, verifyTelegramAuth, async (req, res)
132
  });
133
 
134
  const referListRef = db3.ref('refer').child(refer_id);
135
- const referListSnap = await referListRef.once('value');
136
-
137
- // Admin 3 তে refer_id না থাকলে ক্রিয়েট করে পুশ করবে, থাকলে সরাসরি পুশ করবে
138
- await referListRef.push(user_id);
139
  }
140
  }
141
 
@@ -192,11 +238,15 @@ app.post('/withdraw-main', checkPostMethod, verifyTelegramAuth, async (req, res)
192
  // ৭. API: অ্যাড ব্যালেন্স উইথড্র (Admin 4 -> Admin 1)
193
  // ==========================================
194
  const adWithdrawPaths = [
195
- '/withdraw-link-visit', '/withdraw-adsgram-1', '/withdraw-adsgram-2',
196
- '/withdraw-gigapub-1', '/withdraw-gigapub-2', '/withdraw-monetag-1', '/withdraw-monetag-2'
 
 
 
 
 
197
  ];
198
 
199
- // এখানে verifyTelegramAuth দেওয়া হয়নি, কারণ তোমার ইনস্ট্রাকশন অনুযায়ী এটা শুধু আগের দুটোর জন্য
200
  app.post(adWithdrawPaths, checkPostMethod, async (req, res) => {
201
  const { user_id, amount, method } = req.body;
202
 
@@ -204,7 +254,7 @@ app.post(adWithdrawPaths, checkPostMethod, async (req, res) => {
204
  return res.status(400).json({ error: 'Invalid request. Method must be wallet and amount is required.' });
205
  }
206
 
207
- const adNetworkName = req.path.replace('/withdraw-', '');
208
  const requestAmount = Number(amount);
209
 
210
  try {
@@ -213,7 +263,7 @@ app.post(adWithdrawPaths, checkPostMethod, async (req, res) => {
213
 
214
  if (!adSnapshot.exists()) return res.status(404).json({ error: 'No ad earnings found for this user' });
215
 
216
- let adCurrentBalance = Number(adSnapshot.val().balance || 0);
217
 
218
  if (adCurrentBalance < requestAmount) {
219
  return res.status(400).json({ error: 'Insufficient ad balance' });
 
5
  const app = express();
6
  app.use(express.json());
7
 
8
+ // ==========================================
9
+ // ০. রিকোয়েস্ট এবং রেসপন্স লগার মিডলওয়্যার (Terminal Console Log)
10
+ // ==========================================
11
+ app.use((req, res, next) => {
12
+ const startTime = Date.now();
13
+
14
+ // original res.json এবং res.send মেথড ব্যাকআপ রাখা হচ্ছে রেসপন্স বডি ট্র্যাক করার জন্য
15
+ const oldJson = res.json;
16
+ const oldSend = res.send;
17
+ let responseBody;
18
+
19
+ res.json = function(data) {
20
+ responseBody = data;
21
+ return oldJson.apply(res, arguments);
22
+ };
23
+
24
+ res.send = function(data) {
25
+ responseBody = data;
26
+ return oldSend.apply(res, arguments);
27
+ };
28
+
29
+ // রিকোয়েস্ট শেষ হলে টার্মিনালে বা Docker লগ-এ প্রিন্ট হবে
30
+ res.on('finish', () => {
31
+ const duration = Date.now() - startTime;
32
+ console.log(`\n=========================================`);
33
+ console.log(`[${new Date().toISOString()}] ${req.method} -> ${req.originalUrl}`);
34
+ console.log(`Status: ${res.statusCode} (${res.statusMessage}) | Time: ${duration}ms`);
35
+
36
+ // রিকোয়েস্ট বডি বা কুয়েরি ডেটা দেখা
37
+ if (Object.keys(req.body).length > 0) {
38
+ // সিকিউরিটির জন্য এবং টার্মিনাল ক্লিন রাখতে বড় init_data হাইড করা হয়েছে
39
+ const cleanBody = { ...req.body };
40
+ if (cleanBody.init_data) cleanBody.init_data = "[TELEGRAM_INIT_DATA_HIDDEN]";
41
+ console.log(`Request Body:`, JSON.stringify(cleanBody, null, 2));
42
+ } else if (Object.keys(req.query).length > 0) {
43
+ console.log(`Request Query:`, JSON.stringify(req.query, null, 2));
44
+ }
45
+
46
+ // সার্ভার ক্লায়েন্টকে কী রিপ্লাই দিল তা প্রিন্ট করা
47
+ if (responseBody) {
48
+ console.log(`Server Reply:`, typeof responseBody === 'object' ? JSON.stringify(responseBody, null, 2) : responseBody);
49
+ }
50
+ console.log(`=========================================`);
51
+ });
52
+
53
+ next();
54
+ });
55
+
56
  // ==========================================
57
  // ১. ফায়ারবেজ মাল্টিপল অ্যাডমিন সেটআপ
58
  // ==========================================
 
168
  join_date: admin.database.ServerValue.TIMESTAMP,
169
  total_refer: 0
170
  };
171
+
172
  await userRef.set(newUserData);
173
 
174
  if (refer_id) {
 
181
  });
182
 
183
  const referListRef = db3.ref('refer').child(refer_id);
184
+ await referListRef.push(user_id);
 
 
 
185
  }
186
  }
187
 
 
238
  // ৭. API: অ্যাড ব্যালেন্স উইথড্র (Admin 4 -> Admin 1)
239
  // ==========================================
240
  const adWithdrawPaths = [
241
+ '/withdraw-link-visit',
242
+ '/withdraw-adsgram-1',
243
+ '/withdraw-adsgram-2',
244
+ '/withdraw-gigapub-1',
245
+ '/withdraw-gigapub-2',
246
+ '/withdraw-monetag-1',
247
+ '/withdraw-monetag-2'
248
  ];
249
 
 
250
  app.post(adWithdrawPaths, checkPostMethod, async (req, res) => {
251
  const { user_id, amount, method } = req.body;
252
 
 
254
  return res.status(400).json({ error: 'Invalid request. Method must be wallet and amount is required.' });
255
  }
256
 
257
+ const adNetworkName = req.path.replace('/withdraw-', '');
258
  const requestAmount = Number(amount);
259
 
260
  try {
 
263
 
264
  if (!adSnapshot.exists()) return res.status(404).json({ error: 'No ad earnings found for this user' });
265
 
266
+ let adCurrentBalance = Number(adSnapshot.val().balance || 0);
267
 
268
  if (adCurrentBalance < requestAmount) {
269
  return res.status(400).json({ error: 'Insufficient ad balance' });