Upload files to "/"

This commit is contained in:
b016488d-939a-4910-a596-93b77fc9ab9c
2026-07-24 15:26:33 +00:00
parent 99bb20a1e9
commit d061cf5c8d
4 changed files with 195 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ RecNetDomain = "rec.net"
auth = None
refreshToken = None
clientSecret = "54oc5C4BH7jpqp42KhChkNZOLP0U3yTx"
clientId = "recroom.studio"#recroom.studio
c = httpx.Client(http1=False, http2=True)
@@ -87,7 +88,7 @@ def sendRequest(method: HTTPMethod, service: Service, path: str, useAuth=True, j
scheme = "https"
url = f"{scheme}://{service.value}.{RecNetDomain}/{path}"
headers = {
"User-Agent": "BestHTTP"
"User-Agent": "RRStudio"
}
if auth and useAuth:
headers.update({
@@ -103,23 +104,13 @@ def sendRequest(method: HTTPMethod, service: Service, path: str, useAuth=True, j
raise RecNetError(f"Failed to refresh token: {re.error}")
auth = re.accessToken
refreshToken = re.refreshToken
sendRequest(method, service, path, json=json, files=files, data=data, https=https)
return sendRequest(method, service, path, json=json, files=files, data=data, https=https)
else:
raise RecNetError("Unauthorized: No access token provided.")
return req
def genAuthCode():
"""
Generates a device authorization code by sending a POST request to the authentication api.
Returns:
dto.DeviceAuthorization: An object containing the device authorization response if successful.
None: If the request fails or no response is received.
Side Effects:
Prints an error message to the console if the device authorization response fails.
"""
payload = {"client_id": "recroom.studio", "client_secret": clientSecret}
payload = {"client_id": clientId, "client_secret": clientSecret}
req = sendRequest(HTTPMethod.POST, Service.Auth, "connect/deviceauthorization", data=payload)
if req is not None:
return dto.DeviceAuthorization(req.json())
@@ -128,7 +119,7 @@ def genAuthCode():
return None
def loginWithDeviceCode(DeviceCode: str):
payload = {"client_id": "recroom.studio", "client_secret": clientSecret, "grant_type": "urn:ietf:params:oauth:grant-type:device_code", "device_code": DeviceCode}
payload = {"client_id": clientId, "client_secret": clientSecret, "grant_type": "urn:ietf:params:oauth:grant-type:device_code", "device_code": DeviceCode}
req = sendRequest(HTTPMethod.POST, Service.Auth, "connect/token", data=payload)
if req is not None:
return dto.Login(req.json())
@@ -137,7 +128,7 @@ def loginWithDeviceCode(DeviceCode: str):
return None
def loginWithRefreshToken(refreshToken: str):
payload = {"client_id": "recroom.studio", "client_secret": clientSecret, "grant_type": "refresh_token", "refresh_token": refreshToken}
payload = {"client_id": clientId, "client_secret": clientSecret, "grant_type": "refresh_token", "refresh_token": refreshToken}
req = sendRequest(HTTPMethod.POST, Service.Auth, "connect/token", data=payload)
print(refreshToken)
if req is not None:

114
dto.py Normal file
View File

@@ -0,0 +1,114 @@
from typing import Optional, List
from enum import Enum
import uuid
class DeviceAuthorization:
"""
Represents device authorization data.
Attributes:
deviceCode (str): The device code.
userCode (str): The user code.
verificationUri (str): The verification URI.
verificationUriComplete (str): The complete verification URI.
expiresIn (int): Expiration time in seconds.
interval (int): Polling interval in seconds.
"""
def __init__(self, jsonData: dict):
self.error: Optional[str] = jsonData.get("error")
self.deviceCode: str = jsonData.get("device_code")
self.userCode: str = jsonData.get("user_code")
self.verificationUri: str = jsonData.get("verification_uri")
self.verificationUriComplete: str = jsonData.get("verification_uri_complete")
self.expiresIn: int = jsonData.get("expires_in")
self.interval: int = jsonData.get("interval")
class Login:
"""
Represents the login response data parsed from a JSON dictionary.
Attributes:
error (Optional[str]): Error message if login failed, otherwise None.
idToken (str): The ID token issued by RecNet.
accessToken (str): The access token for accessing protected resources.
tokenType (str): The type of the token issued (e.g., "Bearer").
expiresIn (str): The duration in seconds until the token expires.
refreshToken (int): The refresh token used to obtain new access tokens.
scope (str): The scope of access granted by the token.
Args:
jsonData (dict): The JSON dictionary containing login response data.
"""
def __init__(self, jsonData: dict):
self.error: Optional[str] = jsonData.get("error")
self.idToken: str = jsonData.get("id_token")
self.accessToken: str = jsonData.get("access_token")
self.tokenType: str = jsonData.get("token_type")
self.expiresIn: str = jsonData.get("expires_in")
self.refreshToken: int = jsonData.get("refresh_token")
self.scope: str = jsonData.get("scope")
class Account:
def __init__(self, jsonData: dict):
self.accountId: int = jsonData.get("accountId")
self.displayName: str = jsonData.get("displayName")
self.username: str = jsonData.get("username")
self.profileImage: str = jsonData.get("profileImage")
class TagType(Enum):
General = 0
Auto = 1
AGOnly = 2
class Tag:
def __init__(self, jsonData: dict):
self.Tag: str = jsonData.get("Tag")
tagType = jsonData.get("Type")
if tagType == 0:
Type = TagType.General
elif tagType == 1:
Type = TagType.Auto
elif tagType == 2:
Type = TagType.AGOnly
self.Type: TagType = Type
class Upload:
def __init__(self, jsonData: dict):
self.Filename = jsonData.get("filename")
self.Hash = jsonData.get("hash")
self.OwnershipProof = jsonData.get("ownershipProof")
class InventionCurrentVersion:
def __init__(self, jsonData: dict):
self.BlobName: str = jsonData.get("BlobName")
self.HasBetaContent: bool = jsonData.get("HasBetaContent")
self.HasDevContent: bool = jsonData.get("BlobName")
self.HasImageFileReference: bool = jsonData.get("HasImageFileReference")
self.ReferencedUnityAssetIds: List[str] = jsonData.get("ReferencedUnityAssetIds")
self.InstantiationCost: int = jsonData.get("InstantiationCost")
self.LightsCost: int = jsonData.get("LightsCost")
self.ChipsCost: int = jsonData.get("ChipsCost")
self.CloudVariablesCost: int = jsonData.get("CloudVariablesCost")
class Invention:
def __init__(self, jsonData: dict):
self.InventionId: str = jsonData.get("InventionId")
self.ReplicationId: uuid.UUID = jsonData.get("ReplicationId")
self.CreatorPlayerId: int = jsonData.get("CreatorPlayerId")
self.CurrentVersion: InventionCurrentVersion = InventionCurrentVersion(jsonData.get("CurrentVersion"))
self.Description: str = jsonData.get("Description")
self.LongDescription: str = jsonData.get("LongDescription")
self.ImageName: str = jsonData.get("ImageName")
self.UgcVersion: int = jsonData.get("UgcVersion")
self.ForceCannotPublish: bool = jsonData.get("ForceCannotPublish")
self.CurrentVersionNumber: int = jsonData.get("CurrentVersionNumber")
self.LatestVersionNumber: int = jsonData.get("LatestVersionNumber")
self.Name: str = jsonData.get("Name")
self.Accessibility: int = jsonData.get("Accessibility")
self.IsPublished: bool = jsonData.get("IsPublished")
self.IsFeatured: bool = jsonData.get("IsFeatured")
self.FirstPublishedAt: Optional[str] = jsonData.get("FirstPublishedAt")
self.CreationRoomId: int = jsonData.get("CreationRoomId")
self.NumPlayersHaveUsedInRoom: int = jsonData.get("NumPlayersHaveUsedInRoom")
self.NumDownloads: int = jsonData.get("NumDownloads")

2
install.bat Normal file
View File

@@ -0,0 +1,2 @@
pip install PyJWT
pip install httpx[http2]

73
noGui.py Normal file
View File

@@ -0,0 +1,73 @@
import RecNet as rn
import dto
import time
import random
import jwt
import webbrowser
import sys
inventionId = None
for arg in sys.argv:
if arg.startswith("inventionId="):
inventionId = arg.split("inventionId=")[1]
if inventionId is None:
print("Missing required 'inventionId' argument.")
sys.exit(1)
#Check out this invention in RecRoom: https://rec.net/d/store/invention/7659560881412086938
loggedIn = False
testauth = rn.genAuthCode()
print(testauth.verificationUriComplete)
webbrowser.open(testauth.verificationUriComplete)
while not loggedIn:
test2 = rn.loginWithDeviceCode(testauth.deviceCode)
if test2.accessToken is not None:
token = jwt.decode(test2.accessToken, options={"verify_signature": False})
print(test2.accessToken)
role = token.get("role")
betastudio = False
if isinstance(role, list):
if "betastudio" in role:
betastudio = True
elif role == "betastudio":
betastudio = True
if not betastudio:
print("Your account does not have access to Beta Studio.")
sys.exit(1)
rn.auth = test2.accessToken
loggedIn = True
break
if test2.error != "authorization_pending":
print(f"Error: {test2.error}")
break
time.sleep(testauth.interval)
#print(test2.accessToken)
myAccount = rn.sendRequest(rn.HTTPMethod.GET, rn.Service.Accounts, "account/me")
myAccount = dto.Account(myAccount.json())
inventions = rn.sendRequest(rn.HTTPMethod.GET, rn.Service.API, f"api/inventions/v2/batch?id={inventionId}")
if len(inventions.json()) == 0:
sys.exit(3)
invention = dto.Invention(inventions.json()[0])
newInventionPayoad = {
"creatorAccountRole": 30,
"instantiationCost": invention.CurrentVersion.InstantiationCost,
"lightsCost": invention.CurrentVersion.LightsCost,
"chipsCost": invention.CurrentVersion.ChipsCost,
"cloudVariablesCost": invention.CurrentVersion.CloudVariablesCost,
"ugcVersion": invention.UgcVersion,
"hasBetaContent": invention.CurrentVersion.HasBetaContent,
"name": invention.Name,
"imageName": invention.ImageName,
"inventionDataFilename":invention.CurrentVersion.BlobName
}
newInvention = rn.sendRequest(rn.HTTPMethod.POST, rn.Service.API, f"api/inventions/v9/save", data=newInventionPayoad)
print(newInvention)
print(newInvention.text)
#7416601836735484223 -00zay