feat: debug! more logs
All checks were successful
Deploy on Push / deploy (push) Successful in 1m33s
All checks were successful
Deploy on Push / deploy (push) Successful in 1m33s
This commit is contained in:
parent
ef2c902b32
commit
46759142df
12
main.py
12
main.py
|
@ -1,13 +1,16 @@
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import uuid
|
import uuid
|
||||||
import aioboto3 # Ensure this is only imported once
|
import aioboto3
|
||||||
from starlette.applications import Starlette
|
from starlette.applications import Starlette
|
||||||
from starlette.responses import JSONResponse
|
from starlette.responses import JSONResponse
|
||||||
from starlette.routing import Route
|
from starlette.routing import Route
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
from auth import check_auth
|
from auth import check_auth
|
||||||
|
|
||||||
|
# Logging configuration
|
||||||
|
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
STORJ_ACCESS_KEY = os.environ.get('STORJ_ACCESS_KEY')
|
STORJ_ACCESS_KEY = os.environ.get('STORJ_ACCESS_KEY')
|
||||||
STORJ_SECRET_KEY = os.environ.get('STORJ_SECRET_KEY')
|
STORJ_SECRET_KEY = os.environ.get('STORJ_SECRET_KEY')
|
||||||
|
@ -17,14 +20,17 @@ CDN_DOMAIN = os.environ.get('CDN_DOMAIN')
|
||||||
|
|
||||||
@check_auth
|
@check_auth
|
||||||
async def upload_handler(request: Request):
|
async def upload_handler(request: Request):
|
||||||
|
logging.debug("Received upload request")
|
||||||
form = await request.form()
|
form = await request.form()
|
||||||
file = form.get('file')
|
file = form.get('file')
|
||||||
|
|
||||||
if file is None:
|
if file is None:
|
||||||
|
logging.error("No file uploaded")
|
||||||
return JSONResponse({'error': 'No file uploaded'}, status_code=400)
|
return JSONResponse({'error': 'No file uploaded'}, status_code=400)
|
||||||
|
|
||||||
file_name, file_extension = os.path.splitext(file.filename)
|
file_name, file_extension = os.path.splitext(file.filename)
|
||||||
key = str(uuid.uuid4()) + file_extension
|
key = str(uuid.uuid4()) + file_extension
|
||||||
|
logging.debug(f"Generated file key: {key}")
|
||||||
|
|
||||||
async with aioboto3.client('s3',
|
async with aioboto3.client('s3',
|
||||||
aws_access_key_id=STORJ_ACCESS_KEY,
|
aws_access_key_id=STORJ_ACCESS_KEY,
|
||||||
|
@ -38,17 +44,21 @@ async def upload_handler(request: Request):
|
||||||
tmp_file.write(chunk)
|
tmp_file.write(chunk)
|
||||||
tmp_file.flush()
|
tmp_file.flush()
|
||||||
|
|
||||||
|
logging.debug("Starting file upload to S3")
|
||||||
await s3.upload_file(
|
await s3.upload_file(
|
||||||
Filename=tmp_file.name,
|
Filename=tmp_file.name,
|
||||||
Bucket=STORJ_BUCKET_NAME,
|
Bucket=STORJ_BUCKET_NAME,
|
||||||
Key=key,
|
Key=key,
|
||||||
ExtraArgs={"ContentType": file.content_type}
|
ExtraArgs={"ContentType": file.content_type}
|
||||||
)
|
)
|
||||||
|
logging.debug("File upload completed")
|
||||||
|
|
||||||
url = f'http://{CDN_DOMAIN}/{key}'
|
url = f'http://{CDN_DOMAIN}/{key}'
|
||||||
|
logging.info(f"File uploaded successfully: {url}")
|
||||||
return JSONResponse({'url': url, 'originalFilename': file.filename})
|
return JSONResponse({'url': url, 'originalFilename': file.filename})
|
||||||
|
|
||||||
async def home(request: Request):
|
async def home(request: Request):
|
||||||
|
logging.debug("Home route called")
|
||||||
return JSONResponse({'message': 'Hello World!'})
|
return JSONResponse({'message': 'Hello World!'})
|
||||||
|
|
||||||
routes = [
|
routes = [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user