File size: 2,869 Bytes
1ebbb74 13c13e0 3c30325 d364c74 72ac18c e82c591 1ebbb74 e82c591 1ebbb74 e82c591 1ebbb74 e82c591 1ebbb74 e82c591 1ebbb74 e82c591 1ebbb74 e82c591 1ebbb74 e82c591 1b80d48 8b9f3aa 82213e3 e8daef3 8df7af4 1ebbb74 e82c591 1ebbb74 e82c591 1ebbb74 13c13e0 1ebbb74 13c13e0 e82c591 1ebbb74 e82c591 13c13e0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import logging
from importlib import resources
import httpx
import re
import string
from fastapi import FastAPI, Depends, Security, HTTPException
from fastapi.security import APIKeyQuery, APIKeyHeader
from starlette.responses import RedirectResponse
from starlette.staticfiles import StaticFiles
from mediaflow_proxy.configs import settings
from mediaflow_proxy.routes import proxy_router
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
app = FastAPI()
api_password_query = APIKeyQuery(name="api_password", auto_error=False)
api_password_header = APIKeyHeader(name="api_password", auto_error=False)
async def verify_api_key(api_key: str = Security(api_password_query), api_key_alt: str = Security(api_password_header)):
"""
Verifies the API key for the request.
Args:
api_key (str): The API key to validate.
api_key_alt (str): The alternative API key to validate.
Raises:
HTTPException: If the API key is invalid.
"""
if api_key == settings.api_password or api_key_alt == settings.api_password:
return
raise HTTPException(status_code=403, detail="Could not validate credentials")
@app.get("/health")
async def health_check():
return {"status": "healthy"}
@app.get("/real-link")
async def real_link():
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.10; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
'Accept-Language': 'en-US,en;q=0.5'
}
async with httpx.AsyncClient() as client:
real_link = "https://mixdrop.ps/e/7ro4946lhee7l8"
response = await client.get(real_link, headers=headers, follow_redirects=True,timeout = 30)
[s1, s2] = re.search(r"\}\('(.+)',.+,'(.+)'\.split", response.text).group(1, 2)
schema = s1.split(";")[2][5:-1]
terms = s2.split("|")
charset = string.digits + string.ascii_letters
d = dict()
for i in range(len(terms)):
d[charset[i]] = terms[i] or charset[i]
s = 'https:'
for c in schema:
s += d[c] if c in d else c
ip_address_data = httpx.get("https://api.ipify.org?format=json")
mamma = ip_address_data.json()
print("IP on /REAL-LINK",mamma)
response = await client.head(s)
print("Head request to URL",response)
return s
@app.get("/favicon.ico")
async def get_favicon():
return RedirectResponse(url="/logo.png")
app.include_router(proxy_router, prefix="/proxy", tags=["proxy"], dependencies=[Depends(verify_api_key)])
static_path = resources.files("mediaflow_proxy").joinpath("static")
app.mount("/", StaticFiles(directory=str(static_path), html=True), name="static")
def run():
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8888)
if __name__ == "__main__":
run()
|