nicolaydef commited on
Commit
5057783
·
verified ·
1 Parent(s): 375b2b6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ from fastapi import FastAPI, HTTPException
4
+ from pydantic import BaseModel
5
+
6
+ app = FastAPI()
7
+
8
+ class UploadRequest(BaseModel):
9
+ key: str
10
+ image_url: str
11
+ asset_name: str
12
+ user_id: str
13
+
14
+ @app.post("/upload")
15
+ async def upload_to_roblox(request: UploadRequest):
16
+ # 1. Скачиваем картинку из Pollinations
17
+ img_res = requests.get(request.image_url)
18
+ if img_res.status_code != 200:
19
+ raise HTTPException(status_code=400, detail="Failed to fetch image from Pollinations")
20
+
21
+ # 2. Формируем запрос к Roblox Open Cloud API
22
+ roblox_url = "https://apis.roblox.com/assets/v1/assets"
23
+ headers = {"x-api-key": request.key}
24
+
25
+ # ВАЖНО: Настройка данных ассета
26
+ asset_data = {
27
+ "assetType": "Decal",
28
+ "displayName": request.asset_name,
29
+ "description": "Generated by Bacon AI",
30
+ "creationContext": {
31
+ "expectedCreator": {
32
+ "userId": 10006950195 # Твой ID
33
+ }
34
+ }
35
+ }
36
+
37
+ # Подготовка multipart запроса
38
+ import json
39
+ files = {
40
+ 'request': (None, json.dumps(asset_data), 'application/json'),
41
+ 'fileContent': ('image.png', img_res.content, 'image/png')
42
+ }
43
+
44
+ try:
45
+ response = requests.post(roblox_url, headers=headers, files=files)
46
+ return response.json()
47
+ except Exception as e:
48
+ return {"error": str(e)}
49
+
50
+ @app.get("/")
51
+ def read_root():
52
+ return {"status": "Bacon Proxy is Online"}