nvd commited on
Update bot.py
Browse files
bot.py
CHANGED
|
@@ -185,16 +185,15 @@ async def download_file(url, dest_path):
|
|
| 185 |
f.write(chunk)
|
| 186 |
logger.info(f"✅ Downloaded file to {dest_path}")
|
| 187 |
|
| 188 |
-
# ---------- APK →
|
| 189 |
-
def
|
| 190 |
"""
|
| 191 |
-
Creates a
|
| 192 |
-
Uses built‑in zipfile (ZipCrypto encryption).
|
| 193 |
"""
|
| 194 |
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
|
| 195 |
arcname = os.path.basename(apk_path)
|
| 196 |
-
zf.write(apk_path, arcname=arcname
|
| 197 |
-
logger.info(f"
|
| 198 |
|
| 199 |
# ---------- Message / Callback handlers ----------
|
| 200 |
async def handle_message(message: dict):
|
|
@@ -260,13 +259,13 @@ async def handle_callback(callback: dict):
|
|
| 260 |
|
| 261 |
logger.info(f"⬇️ Requested asset: {original_filename}")
|
| 262 |
|
| 263 |
-
# APK handling: compress
|
| 264 |
is_apk = original_filename.lower().endswith('.apk')
|
| 265 |
if is_apk:
|
| 266 |
base_name = original_filename[:-4] # remove ".apk"
|
| 267 |
zip_filename = base_name + ".zip"
|
| 268 |
-
caption = "
|
| 269 |
-
await send_message(chat_id, "
|
| 270 |
else:
|
| 271 |
zip_filename = None
|
| 272 |
caption = "Here you go!"
|
|
@@ -282,17 +281,17 @@ async def handle_callback(callback: dict):
|
|
| 282 |
await download_file(url, tmp_path)
|
| 283 |
|
| 284 |
if is_apk:
|
| 285 |
-
# Create
|
| 286 |
zip_tmp = tempfile.NamedTemporaryFile(delete=False, suffix="_" + zip_filename)
|
| 287 |
zip_path = zip_tmp.name
|
| 288 |
zip_tmp.close()
|
| 289 |
-
|
| 290 |
# Remove original APK
|
| 291 |
os.unlink(tmp_path)
|
| 292 |
upload_path = zip_path
|
| 293 |
upload_filename = zip_filename
|
| 294 |
file_size = os.path.getsize(upload_path)
|
| 295 |
-
await send_message(chat_id, f"
|
| 296 |
else:
|
| 297 |
upload_path = tmp_path
|
| 298 |
upload_filename = original_filename
|
|
|
|
| 185 |
f.write(chunk)
|
| 186 |
logger.info(f"✅ Downloaded file to {dest_path}")
|
| 187 |
|
| 188 |
+
# ---------- APK → ZIP (no password) ----------
|
| 189 |
+
def create_zip(apk_path, zip_path):
|
| 190 |
"""
|
| 191 |
+
Creates a plain ZIP archive containing the APK.
|
|
|
|
| 192 |
"""
|
| 193 |
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
|
| 194 |
arcname = os.path.basename(apk_path)
|
| 195 |
+
zf.write(apk_path, arcname=arcname)
|
| 196 |
+
logger.info(f"📦 Created ZIP: {zip_path}")
|
| 197 |
|
| 198 |
# ---------- Message / Callback handlers ----------
|
| 199 |
async def handle_message(message: dict):
|
|
|
|
| 259 |
|
| 260 |
logger.info(f"⬇️ Requested asset: {original_filename}")
|
| 261 |
|
| 262 |
+
# APK handling: compress into ZIP (no password)
|
| 263 |
is_apk = original_filename.lower().endswith('.apk')
|
| 264 |
if is_apk:
|
| 265 |
base_name = original_filename[:-4] # remove ".apk"
|
| 266 |
zip_filename = base_name + ".zip"
|
| 267 |
+
caption = "📦 APK inside ZIP archive."
|
| 268 |
+
await send_message(chat_id, "📦 Compressing APK into ZIP...")
|
| 269 |
else:
|
| 270 |
zip_filename = None
|
| 271 |
caption = "Here you go!"
|
|
|
|
| 281 |
await download_file(url, tmp_path)
|
| 282 |
|
| 283 |
if is_apk:
|
| 284 |
+
# Create ZIP (no password)
|
| 285 |
zip_tmp = tempfile.NamedTemporaryFile(delete=False, suffix="_" + zip_filename)
|
| 286 |
zip_path = zip_tmp.name
|
| 287 |
zip_tmp.close()
|
| 288 |
+
create_zip(tmp_path, zip_path)
|
| 289 |
# Remove original APK
|
| 290 |
os.unlink(tmp_path)
|
| 291 |
upload_path = zip_path
|
| 292 |
upload_filename = zip_filename
|
| 293 |
file_size = os.path.getsize(upload_path)
|
| 294 |
+
await send_message(chat_id, f"📦 Compressed. ZIP size: {file_size/1024/1024:.2f} MB")
|
| 295 |
else:
|
| 296 |
upload_path = tmp_path
|
| 297 |
upload_filename = original_filename
|