JerryCoder commited on
Commit
66d865b
·
verified ·
1 Parent(s): 255f350

Update bot.py

Browse files
Files changed (1) hide show
  1. bot.py +6 -10
bot.py CHANGED
@@ -2,7 +2,6 @@ import os
2
  import io
3
  import zipfile
4
  import base64
5
- import random
6
  import tempfile
7
  from fastapi import FastAPI, Request
8
  import aiohttp
@@ -31,22 +30,17 @@ def xor_bytes(data: bytes, key: bytes) -> bytes:
31
 
32
  def encode_bytes(file_bytes: bytes, filename: str):
33
  """Encrypt + wrap into Python file."""
34
- # Step 1: Zip the file
35
  zipped = make_zip_bytes(filename, file_bytes)
36
-
37
- # Step 2: Encrypt with XOR
38
  key = rand_bytes(16)
39
  enc = xor_bytes(zipped, key)
40
  enc_b64 = base64.b64encode(enc).decode()
41
  key_b64 = base64.b64encode(key).decode()
42
 
43
- # Step 3: Build output Python file
44
  wrapper = f"""# Auto Encrypted by JerryCoder Encryptor
45
- import base64,zlib
46
  D=base64.b64decode('{enc_b64}')
47
  K=base64.b64decode('{key_b64}')
48
  O=bytes([b^K[i%len(K)] for i,b in enumerate(D)])
49
- import io,zipfile,tempfile,os,runpy
50
  t=tempfile.mkdtemp()
51
  zipfile.ZipFile(io.BytesIO(O)).extractall(t)
52
  p=[f for f in os.listdir(t) if f.endswith('.py')][0]
@@ -66,6 +60,10 @@ async def encode_endpoint(request: Request):
66
  file_url = data.get("url")
67
  filename = data.get("filename", "file.py")
68
 
 
 
 
 
69
  if not file_url:
70
  return {"ok": False, "error": "No file URL provided"}
71
 
@@ -81,9 +79,7 @@ async def encode_endpoint(request: Request):
81
  with open(out_path, "wb") as f:
82
  f.write(encoded_bytes)
83
 
84
- # ⚠️ NOTE: Hugging Face doesn’t auto-host tmp files publicly.
85
- # You’ll need to upload to a hosting service (like tmpfiles.org, catbox.moe, etc.)
86
- # For now, just return ok=True and filename.
87
  return {
88
  "ok": True,
89
  "result_url": f"https://jerrycoder-kuttuxd.hf.space/tmp/{out_name}",
 
2
  import io
3
  import zipfile
4
  import base64
 
5
  import tempfile
6
  from fastapi import FastAPI, Request
7
  import aiohttp
 
30
 
31
  def encode_bytes(file_bytes: bytes, filename: str):
32
  """Encrypt + wrap into Python file."""
 
33
  zipped = make_zip_bytes(filename, file_bytes)
 
 
34
  key = rand_bytes(16)
35
  enc = xor_bytes(zipped, key)
36
  enc_b64 = base64.b64encode(enc).decode()
37
  key_b64 = base64.b64encode(key).decode()
38
 
 
39
  wrapper = f"""# Auto Encrypted by JerryCoder Encryptor
40
+ import base64,zipfile,io,tempfile,os,runpy
41
  D=base64.b64decode('{enc_b64}')
42
  K=base64.b64decode('{key_b64}')
43
  O=bytes([b^K[i%len(K)] for i,b in enumerate(D)])
 
44
  t=tempfile.mkdtemp()
45
  zipfile.ZipFile(io.BytesIO(O)).extractall(t)
46
  p=[f for f in os.listdir(t) if f.endswith('.py')][0]
 
60
  file_url = data.get("url")
61
  filename = data.get("filename", "file.py")
62
 
63
+ # ✅ Only allow Python files
64
+ if not filename.endswith(".py"):
65
+ return {"ok": False, "error": "Only Python (.py) files are allowed"}
66
+
67
  if not file_url:
68
  return {"ok": False, "error": "No file URL provided"}
69
 
 
79
  with open(out_path, "wb") as f:
80
  f.write(encoded_bytes)
81
 
82
+ # ⚠️ NOTE: Replace this URL with an actual file hosting if you need public download
 
 
83
  return {
84
  "ok": True,
85
  "result_url": f"https://jerrycoder-kuttuxd.hf.space/tmp/{out_name}",