Spaces:
Paused
Paused
File size: 2,013 Bytes
8e6704f 1ef9ada 8e6704f 7769984 1ef9ada 7769984 8e6704f 1ef9ada 8e6704f 1ef9ada 8d74036 1ef9ada 8e6704f 8d74036 8e6704f 8d74036 e8527c7 8d74036 8e6704f 8d74036 e8527c7 8e6704f e8527c7 1ef9ada 8e6704f 734c3c8 8d74036 8e6704f 8d74036 8e6704f 8d74036 8e6704f 8d74036 8e6704f 734c3c8 e8527c7 8d74036 e8527c7 |
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 |
from fastapi import FastAPI, Request
import httpx
import asyncio
import json
app = FastAPI()
async def make_request(options):
url = f"https://{options['hostname']}{options['path']}"
async with httpx.AsyncClient() as client:
try:
response = await client.get(url, headers=options['headers'], follow_redirects=False)
return {
'status': response.status_code,
'headers': dict(response.headers)
}
except Exception as e:
raise Exception("Failed to fetch asset")
@app.post("/v1/assets/batch")
async def handler(request: Request):
if request.method != 'POST':
return {"errors":[{"code":0,"message":"MethodNotAllowed"}]}
try:
body = await request.body()
requests = json.loads(body)
except:
return {"errors":[{"code":0,"message":"BadRequest"}]}
if not isinstance(requests, list) or len(requests) > 300:
return {"errors":[{"code":0,"message":"BadRequest"}]}
async def process_request(req):
options = {
'hostname': 'assetdelivery.roblox.com',
'path': f"/v1/asset/?assetVersionId={req['assetId']}",
'method': 'GET',
'headers': {
'User-Agent': 'Roblox/WinInet'
}
}
try:
response = await make_request(options)
return {
'requestId': req['requestId'],
'location': response['headers'].get('location'),
'assetId': response['headers'].get('roblox-assetid'),
'assetTypeId': response['headers'].get('roblox-assettypeid')
}
except:
return {
'requestId': req['requestId'],
'error': "Failed to fetch asset"
}
results = await asyncio.gather(*[process_request(req) for req in requests])
return results
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860) |