[WEB-5044] fix: ruff lint and format errors (#7868)
* fix: lint errors * fix: file formatting * fix: code refactor
This commit is contained in:
parent
1fb22bd252
commit
9237f568dd
261 changed files with 2199 additions and 6378 deletions
|
|
@ -28,9 +28,7 @@ class S3Storage(S3Boto3Storage):
|
|||
# Use the AWS_REGION environment variable for the region
|
||||
self.aws_region = os.environ.get("AWS_REGION")
|
||||
# Use the AWS_S3_ENDPOINT_URL environment variable for the endpoint URL
|
||||
self.aws_s3_endpoint_url = os.environ.get(
|
||||
"AWS_S3_ENDPOINT_URL"
|
||||
) or os.environ.get("MINIO_ENDPOINT_URL")
|
||||
self.aws_s3_endpoint_url = os.environ.get("AWS_S3_ENDPOINT_URL") or os.environ.get("MINIO_ENDPOINT_URL")
|
||||
|
||||
if os.environ.get("USE_MINIO") == "1":
|
||||
# Determine protocol based on environment variable
|
||||
|
|
@ -44,11 +42,7 @@ class S3Storage(S3Boto3Storage):
|
|||
aws_access_key_id=self.aws_access_key_id,
|
||||
aws_secret_access_key=self.aws_secret_access_key,
|
||||
region_name=self.aws_region,
|
||||
endpoint_url=(
|
||||
f"{endpoint_protocol}://{request.get_host()}"
|
||||
if request
|
||||
else self.aws_s3_endpoint_url
|
||||
),
|
||||
endpoint_url=(f"{endpoint_protocol}://{request.get_host()}" if request else self.aws_s3_endpoint_url),
|
||||
config=boto3.session.Config(signature_version="s3v4"),
|
||||
)
|
||||
else:
|
||||
|
|
@ -62,9 +56,7 @@ class S3Storage(S3Boto3Storage):
|
|||
config=boto3.session.Config(signature_version="s3v4"),
|
||||
)
|
||||
|
||||
def generate_presigned_post(
|
||||
self, object_name, file_type, file_size, expiration=3600
|
||||
):
|
||||
def generate_presigned_post(self, object_name, file_type, file_size, expiration=3600):
|
||||
"""Generate a presigned URL to upload an S3 object"""
|
||||
fields = {"Content-Type": file_type}
|
||||
|
||||
|
|
@ -76,9 +68,7 @@ class S3Storage(S3Boto3Storage):
|
|||
|
||||
# Add condition for the object name (key)
|
||||
if object_name.startswith("${filename}"):
|
||||
conditions.append(
|
||||
["starts-with", "$key", object_name[: -len("${filename}")]]
|
||||
)
|
||||
conditions.append(["starts-with", "$key", object_name[: -len("${filename}")]])
|
||||
else:
|
||||
fields["key"] = object_name
|
||||
conditions.append({"key": object_name})
|
||||
|
|
@ -142,9 +132,7 @@ class S3Storage(S3Boto3Storage):
|
|||
def get_object_metadata(self, object_name):
|
||||
"""Get the metadata for an S3 object"""
|
||||
try:
|
||||
response = self.s3_client.head_object(
|
||||
Bucket=self.aws_storage_bucket_name, Key=object_name
|
||||
)
|
||||
response = self.s3_client.head_object(Bucket=self.aws_storage_bucket_name, Key=object_name)
|
||||
except ClientError as e:
|
||||
log_exception(e)
|
||||
return None
|
||||
|
|
@ -152,11 +140,7 @@ class S3Storage(S3Boto3Storage):
|
|||
return {
|
||||
"ContentType": response.get("ContentType"),
|
||||
"ContentLength": response.get("ContentLength"),
|
||||
"LastModified": (
|
||||
response.get("LastModified").isoformat()
|
||||
if response.get("LastModified")
|
||||
else None
|
||||
),
|
||||
"LastModified": (response.get("LastModified").isoformat() if response.get("LastModified") else None),
|
||||
"ETag": response.get("ETag"),
|
||||
"Metadata": response.get("Metadata", {}),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue