fix: Update API base URL and improve request logging in UploadCog
This commit is contained in:
parent
bfd0d606ab
commit
c6ad3aeae0
@ -68,13 +68,14 @@ class UploadCog(commands.Cog, name="Upload"):
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
self.api_base_url = "https://upload.slipstreamm.dev/upload"
|
||||
# Remove trailing "/upload" from base URL as it's already part of the endpoint paths
|
||||
self.api_base_url = "https://upload.slipstreamm.dev"
|
||||
self.session = None
|
||||
self.captcha_cache = {} # Store captcha IDs temporarily
|
||||
self.headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
|
||||
}
|
||||
print("UploadCog initialized!")
|
||||
print(f"UploadCog initialized with API base URL: {self.api_base_url}")
|
||||
|
||||
# Create command group
|
||||
self.upload_group = app_commands.Group(
|
||||
@ -128,6 +129,14 @@ class UploadCog(commands.Cog, name="Upload"):
|
||||
|
||||
url = f"{self.api_base_url}{endpoint}"
|
||||
|
||||
# Debug the request details
|
||||
print(f"Full URL: {url}")
|
||||
print(f"Method: {method.upper()}")
|
||||
print(f"Headers: {self.headers}")
|
||||
|
||||
# For FormData, don't set Content-Type header as aiohttp will set it with boundary
|
||||
request_headers = self.headers.copy()
|
||||
|
||||
try:
|
||||
if method.upper() == "GET":
|
||||
async with self.session.get(url, **kwargs) as response:
|
||||
@ -137,11 +146,21 @@ class UploadCog(commands.Cog, name="Upload"):
|
||||
error_text = await response.text()
|
||||
raise Exception(f"API request failed: {response.status} - {error_text}")
|
||||
elif method.upper() == "POST":
|
||||
async with self.session.post(url, **kwargs) as response:
|
||||
print(f"Sending POST request to {url}")
|
||||
# If we're sending form data, make sure we don't manually set Content-Type
|
||||
if 'data' in kwargs and isinstance(kwargs['data'], aiohttp.FormData):
|
||||
print("Sending multipart/form-data request")
|
||||
# aiohttp will automatically set the correct Content-Type with boundary
|
||||
|
||||
async with self.session.post(url, headers=request_headers, **kwargs) as response:
|
||||
print(f"Response status: {response.status}")
|
||||
print(f"Response headers: {response.headers}")
|
||||
|
||||
if response.status in (200, 201):
|
||||
return await response.json()
|
||||
else:
|
||||
error_text = await response.text()
|
||||
print(f"Error response body: {error_text}")
|
||||
raise Exception(f"API request failed: {response.status} - {error_text}")
|
||||
else:
|
||||
raise ValueError(f"Unsupported HTTP method: {method}")
|
||||
@ -157,7 +176,7 @@ class UploadCog(commands.Cog, name="Upload"):
|
||||
|
||||
try:
|
||||
# 1. Generate Image Captcha
|
||||
captcha_data = await self._make_api_request("GET", "/api/captcha/image")
|
||||
captcha_data = await self._make_api_request("GET", "/upload/api/captcha/image")
|
||||
captcha_id = captcha_data.get("captcha_id")
|
||||
image_data = captcha_data.get("image", "")
|
||||
|
||||
@ -218,8 +237,27 @@ class UploadCog(commands.Cog, name="Upload"):
|
||||
form_data.add_field('captcha_solution', captcha_solution)
|
||||
form_data.add_field('expires_after', str(expires_after))
|
||||
|
||||
# Debug form data fields
|
||||
print(f"Form data fields: file, captcha_id={captcha_id}, captcha_solution={captcha_solution}, expires_after={expires_after}")
|
||||
|
||||
# Make API request to upload file
|
||||
upload_data = await self._make_api_request("POST", "/api/upload/third-party", data=form_data)
|
||||
try:
|
||||
print("Attempting to upload file to third-party endpoint...")
|
||||
upload_data = await self._make_api_request("POST", "/upload/api/upload/third-party", data=form_data)
|
||||
print(f"Upload successful, received data: {upload_data}")
|
||||
except Exception as e:
|
||||
print(f"Upload failed with error: {e}")
|
||||
# Try a direct approach as a fallback
|
||||
print("Trying direct aiohttp request as fallback...")
|
||||
url = f"{self.api_base_url}/upload/api/upload/third-party"
|
||||
async with self.session.post(url, data=form_data) as response:
|
||||
if response.status in (200, 201):
|
||||
upload_data = await response.json()
|
||||
print(f"Direct upload successful: {upload_data}")
|
||||
else:
|
||||
error_text = await response.text()
|
||||
print(f"Direct upload failed: {response.status} - {error_text}")
|
||||
raise Exception(f"API request failed: {response.status} - {error_text}")
|
||||
|
||||
# Create embed with upload information
|
||||
embed = discord.Embed(
|
||||
@ -229,7 +267,7 @@ class UploadCog(commands.Cog, name="Upload"):
|
||||
)
|
||||
|
||||
file_id = upload_data.get("id", "unknown")
|
||||
file_url = f"{self.api_base_url}/uploads/{file_id}"
|
||||
file_url = f"{self.api_base_url}/upload/uploads/{file_id}"
|
||||
|
||||
# Format file size nicely
|
||||
file_size_bytes = upload_data.get('file_size', 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user