Spaces:
Sleeping
Sleeping
| import os | |
| import requests | |
| from fastapi import FastAPI, HTTPException | |
| from pydantic import BaseModel | |
| app = FastAPI() | |
| class UploadRequest(BaseModel): | |
| key: str | |
| image_url: str | |
| asset_name: str | |
| user_id: str | |
| async def upload_to_roblox(request: UploadRequest): | |
| # 1. Скачиваем картинку из Pollinations | |
| img_res = requests.get(request.image_url) | |
| if img_res.status_code != 200: | |
| raise HTTPException(status_code=400, detail="Failed to fetch image from Pollinations") | |
| # 2. Формируем запрос к Roblox Open Cloud API | |
| roblox_url = "https://apis.roblox.com/assets/v1/assets" | |
| headers = {"x-api-key": request.key} | |
| # ВАЖНО: Настройка данных ассета | |
| asset_data = { | |
| "assetType": "Decal", | |
| "displayName": request.asset_name, | |
| "description": "Generated by Bacon AI", | |
| "creationContext": { | |
| "expectedCreator": { | |
| "userId": 10006950195 # Твой ID | |
| } | |
| } | |
| } | |
| # Подготовка multipart запроса | |
| import json | |
| files = { | |
| 'request': (None, json.dumps(asset_data), 'application/json'), | |
| 'fileContent': ('image.png', img_res.content, 'image/png') | |
| } | |
| try: | |
| response = requests.post(roblox_url, headers=headers, files=files) | |
| return response.json() | |
| except Exception as e: | |
| return {"error": str(e)} | |
| def read_root(): | |
| return {"status": "Bacon Proxy is Online"} |