mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-11 20:06:54 +08:00
chore(api): Introduce Ruff Formatter. (#7291)
This commit is contained in:
@@ -10,24 +10,24 @@ from extensions.storage.base_storage import BaseStorage
|
||||
|
||||
|
||||
class S3Storage(BaseStorage):
|
||||
"""Implementation for s3 storage.
|
||||
"""
|
||||
"""Implementation for s3 storage."""
|
||||
|
||||
def __init__(self, app: Flask):
|
||||
super().__init__(app)
|
||||
app_config = self.app.config
|
||||
self.bucket_name = app_config.get('S3_BUCKET_NAME')
|
||||
if app_config.get('S3_USE_AWS_MANAGED_IAM'):
|
||||
self.bucket_name = app_config.get("S3_BUCKET_NAME")
|
||||
if app_config.get("S3_USE_AWS_MANAGED_IAM"):
|
||||
session = boto3.Session()
|
||||
self.client = session.client('s3')
|
||||
self.client = session.client("s3")
|
||||
else:
|
||||
self.client = boto3.client(
|
||||
's3',
|
||||
aws_secret_access_key=app_config.get('S3_SECRET_KEY'),
|
||||
aws_access_key_id=app_config.get('S3_ACCESS_KEY'),
|
||||
endpoint_url=app_config.get('S3_ENDPOINT'),
|
||||
region_name=app_config.get('S3_REGION'),
|
||||
config=Config(s3={'addressing_style': app_config.get('S3_ADDRESS_STYLE')})
|
||||
)
|
||||
"s3",
|
||||
aws_secret_access_key=app_config.get("S3_SECRET_KEY"),
|
||||
aws_access_key_id=app_config.get("S3_ACCESS_KEY"),
|
||||
endpoint_url=app_config.get("S3_ENDPOINT"),
|
||||
region_name=app_config.get("S3_REGION"),
|
||||
config=Config(s3={"addressing_style": app_config.get("S3_ADDRESS_STYLE")}),
|
||||
)
|
||||
|
||||
def save(self, filename, data):
|
||||
self.client.put_object(Bucket=self.bucket_name, Key=filename, Body=data)
|
||||
@@ -35,9 +35,9 @@ class S3Storage(BaseStorage):
|
||||
def load_once(self, filename: str) -> bytes:
|
||||
try:
|
||||
with closing(self.client) as client:
|
||||
data = client.get_object(Bucket=self.bucket_name, Key=filename)['Body'].read()
|
||||
data = client.get_object(Bucket=self.bucket_name, Key=filename)["Body"].read()
|
||||
except ClientError as ex:
|
||||
if ex.response['Error']['Code'] == 'NoSuchKey':
|
||||
if ex.response["Error"]["Code"] == "NoSuchKey":
|
||||
raise FileNotFoundError("File not found")
|
||||
else:
|
||||
raise
|
||||
@@ -48,12 +48,13 @@ class S3Storage(BaseStorage):
|
||||
try:
|
||||
with closing(self.client) as client:
|
||||
response = client.get_object(Bucket=self.bucket_name, Key=filename)
|
||||
yield from response['Body'].iter_chunks()
|
||||
yield from response["Body"].iter_chunks()
|
||||
except ClientError as ex:
|
||||
if ex.response['Error']['Code'] == 'NoSuchKey':
|
||||
if ex.response["Error"]["Code"] == "NoSuchKey":
|
||||
raise FileNotFoundError("File not found")
|
||||
else:
|
||||
raise
|
||||
|
||||
return generate()
|
||||
|
||||
def download(self, filename, target_filepath):
|
||||
|
||||
Reference in New Issue
Block a user