Update app.py
Browse files
app.py
CHANGED
@@ -176,30 +176,19 @@ def get_files_api():
|
|
176 |
|
177 |
@app.route('/api/add-file', methods=['POST'])
|
178 |
def add_file_api():
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
return jsonify({"error": "File ID, file name, and file size are required"}), 400
|
188 |
-
file = Media(
|
189 |
-
file_id=file_id,
|
190 |
-
file_ref=file_ref,
|
191 |
-
file_name=file_name,
|
192 |
-
file_size=int(file_size),
|
193 |
-
file_type=file_type,
|
194 |
-
mime_type=mime_type,
|
195 |
-
caption=caption
|
196 |
-
)
|
197 |
-
try:
|
198 |
loop = asyncio.get_event_loop()
|
199 |
-
loop.run_until_complete(
|
200 |
-
|
201 |
-
return jsonify({"
|
202 |
-
return jsonify({"
|
203 |
|
204 |
@app.route('/api/delete-file', methods=['POST'])
|
205 |
def delete_file_api():
|
@@ -336,10 +325,22 @@ def broadcast_api():
|
|
336 |
deleted = 0
|
337 |
failed = 0
|
338 |
success = 0
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
return jsonify({
|
344 |
"total_users": total_users,
|
345 |
"completed": done,
|
@@ -349,18 +350,6 @@ def broadcast_api():
|
|
349 |
"failed": failed
|
350 |
})
|
351 |
|
352 |
-
async def handle_user(user, message_text, success, blocked, deleted, failed, done):
|
353 |
-
try:
|
354 |
-
await bot.send_message(user['id'], message_text)
|
355 |
-
success += 1
|
356 |
-
except UserIsBlocked:
|
357 |
-
blocked += 1
|
358 |
-
except InputUserDeactivated:
|
359 |
-
deleted += 1
|
360 |
-
except Exception as e:
|
361 |
-
failed += 1
|
362 |
-
done += 1
|
363 |
-
|
364 |
@app.route('/api/ban-users')
|
365 |
def ban_users_api():
|
366 |
loop = asyncio.get_event_loop()
|
@@ -406,11 +395,12 @@ def chat_info_api(chat_id):
|
|
406 |
try:
|
407 |
loop = asyncio.get_event_loop()
|
408 |
chat = loop.run_until_complete(bot.get_chat(int(chat_id)))
|
|
|
409 |
return jsonify({
|
410 |
"title": chat.title,
|
411 |
"username": chat.username,
|
412 |
"id": chat.id,
|
413 |
-
"members_count":
|
414 |
})
|
415 |
except Exception as e:
|
416 |
return jsonify({"error": str(e)}), 500
|
@@ -507,4 +497,5 @@ def connections_api():
|
|
507 |
return jsonify({"connections": connections})
|
508 |
|
509 |
if __name__ == '__main__':
|
|
|
510 |
app.run(host='0.0.0.0', port=7860, debug=False)
|
|
|
176 |
|
177 |
@app.route('/api/add-file', methods=['POST'])
|
178 |
def add_file_api():
|
179 |
+
if 'fileUpload' not in request.files:
|
180 |
+
return jsonify({"error": "No file part"}), 400
|
181 |
+
file = request.files['fileUpload']
|
182 |
+
if file.filename == '':
|
183 |
+
return jsonify({"error": "No selected file"}), 400
|
184 |
+
if file:
|
185 |
+
file_path = os.path.join("/app/uploads", file.filename)
|
186 |
+
file.save(file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
loop = asyncio.get_event_loop()
|
188 |
+
file_id, file_ref = loop.run_until_complete(save_file(file_path))
|
189 |
+
os.remove(file_path)
|
190 |
+
return jsonify({"file_id": file_id, "file_ref": file_ref, "message": "File uploaded successfully"})
|
191 |
+
return jsonify({"error": "Failed to upload file"}), 500
|
192 |
|
193 |
@app.route('/api/delete-file', methods=['POST'])
|
194 |
def delete_file_api():
|
|
|
325 |
deleted = 0
|
326 |
failed = 0
|
327 |
success = 0
|
328 |
+
|
329 |
+
async def handle_user(user):
|
330 |
+
nonlocal success, blocked, deleted, failed, done
|
331 |
+
try:
|
332 |
+
await bot.send_message(user['id'], message_text)
|
333 |
+
success += 1
|
334 |
+
except UserIsBlocked:
|
335 |
+
blocked += 1
|
336 |
+
except InputUserDeactivated:
|
337 |
+
deleted += 1
|
338 |
+
except Exception as e:
|
339 |
+
failed += 1
|
340 |
+
done += 1
|
341 |
+
|
342 |
+
loop.run_until_complete(asyncio.gather(*(handle_user(user) for user in users)))
|
343 |
+
|
344 |
return jsonify({
|
345 |
"total_users": total_users,
|
346 |
"completed": done,
|
|
|
350 |
"failed": failed
|
351 |
})
|
352 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
@app.route('/api/ban-users')
|
354 |
def ban_users_api():
|
355 |
loop = asyncio.get_event_loop()
|
|
|
395 |
try:
|
396 |
loop = asyncio.get_event_loop()
|
397 |
chat = loop.run_until_complete(bot.get_chat(int(chat_id)))
|
398 |
+
members_count = loop.run_until_complete(bot.get_chat_members_count(int(chat_id)))
|
399 |
return jsonify({
|
400 |
"title": chat.title,
|
401 |
"username": chat.username,
|
402 |
"id": chat.id,
|
403 |
+
"members_count": members_count
|
404 |
})
|
405 |
except Exception as e:
|
406 |
return jsonify({"error": str(e)}), 500
|
|
|
497 |
return jsonify({"connections": connections})
|
498 |
|
499 |
if __name__ == '__main__':
|
500 |
+
bot.run()
|
501 |
app.run(host='0.0.0.0', port=7860, debug=False)
|