fullpwerr commited on
Commit
2bcf1c8
·
1 Parent(s): d08421d

Refactor bypass_shinigami function to remove HTTP request checks and enhance response structure with title and meta headers

Browse files
Files changed (2) hide show
  1. app/main.py +11 -4
  2. app/utils.py +17 -15
app/main.py CHANGED
@@ -8,10 +8,17 @@ async def root():
8
  return {"message": "API Aktif"}
9
 
10
  @app.get("/bypass")
11
- async def bypass(url: str = Query(..., description="URL Shinigami yang mau dibypass")):
12
- if not url.startswith("http"):
 
 
 
 
 
 
 
13
  raise HTTPException(status_code=400, detail="URL tidak valid")
14
  result = bypass_shinigami(url)
15
- if result["status"] == "error":
16
- raise HTTPException(status_code=502, detail=result["message"])
17
  return result
 
8
  return {"message": "API Aktif"}
9
 
10
  @app.get("/bypass")
11
+ async def bypass(
12
+ url: str = Query(
13
+ ...,
14
+ description="URL Shinigami yang mau dibypass",
15
+ example="https://shinigami.link/xxxx"
16
+ )
17
+ ):
18
+ url = url.strip()
19
+ if not url or not url.startswith("http"):
20
  raise HTTPException(status_code=400, detail="URL tidak valid")
21
  result = bypass_shinigami(url)
22
+ if result.get("status") != "success":
23
+ raise HTTPException(status_code=502, detail=result.get("message", "Unknown error"))
24
  return result
app/utils.py CHANGED
@@ -3,23 +3,12 @@ from selenium import webdriver
3
  from selenium.webdriver.chrome.options import Options
4
  from selenium.webdriver.common.by import By
5
  import time
6
- import requests
7
 
8
  # Force all cache to go to /tmp/.cache
9
  os.environ["XDG_CACHE_HOME"] = "/tmp/.cache"
10
  os.environ["XDG_CONFIG_HOME"] = "/tmp/.config"
11
 
12
  def bypass_shinigami(url: str) -> dict:
13
- # Cek status code dulu
14
- try:
15
- resp = requests.get(url, timeout=10)
16
- status_code = resp.status_code
17
- except Exception as e:
18
- return {"status": "error", "message": f"Gagal akses url: {e}", "code": None, "bypassed_url": None}
19
-
20
- if status_code != 200:
21
- return {"status": "error", "message": f"Status code: {status_code}", "code": status_code, "bypassed_url": None}
22
-
23
  chrome_options = Options()
24
  chrome_options.add_argument("--headless")
25
  chrome_options.add_argument("--disable-gpu")
@@ -37,18 +26,31 @@ def bypass_shinigami(url: str) -> dict:
37
  time.sleep(5)
38
  # Ambil link pertama yang ditemukan
39
  link = driver.find_element(By.TAG_NAME, "a").get_attribute("href")
 
 
 
 
 
 
 
 
 
 
 
40
  return {
41
  "status": "success",
42
  "message": "OK",
43
- "code": status_code,
44
- "bypassed_url": link or None
 
45
  }
46
  except Exception as e:
47
  return {
48
  "status": "error",
49
  "message": f"Error: {e}",
50
- "code": status_code,
51
- "bypassed_url": None
 
52
  }
53
  finally:
54
  driver.quit()
 
3
  from selenium.webdriver.chrome.options import Options
4
  from selenium.webdriver.common.by import By
5
  import time
 
6
 
7
  # Force all cache to go to /tmp/.cache
8
  os.environ["XDG_CACHE_HOME"] = "/tmp/.cache"
9
  os.environ["XDG_CONFIG_HOME"] = "/tmp/.config"
10
 
11
  def bypass_shinigami(url: str) -> dict:
 
 
 
 
 
 
 
 
 
 
12
  chrome_options = Options()
13
  chrome_options.add_argument("--headless")
14
  chrome_options.add_argument("--disable-gpu")
 
26
  time.sleep(5)
27
  # Ambil link pertama yang ditemukan
28
  link = driver.find_element(By.TAG_NAME, "a").get_attribute("href")
29
+ # Ambil title halaman
30
+ title = driver.title
31
+ # Ambil semua meta tag di head sebagai "headers"
32
+ meta_elements = driver.find_elements(By.XPATH, "//head/meta")
33
+ headers = {}
34
+ for meta in meta_elements:
35
+ name = meta.get_attribute("name") or meta.get_attribute("property")
36
+ content = meta.get_attribute("content")
37
+ if name and content:
38
+ headers[name] = content
39
+
40
  return {
41
  "status": "success",
42
  "message": "OK",
43
+ "bypassed_url": link or None,
44
+ "title": title,
45
+ "headers": headers
46
  }
47
  except Exception as e:
48
  return {
49
  "status": "error",
50
  "message": f"Error: {e}",
51
+ "bypassed_url": None,
52
+ "title": None,
53
+ "headers": {}
54
  }
55
  finally:
56
  driver.quit()