mirror of
https://github.com/langgenius/dify.git
synced 2026-01-14 06:07:33 +08:00
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Main CI Pipeline / Check Changed Files (push) Waiting to run
Main CI Pipeline / API Tests (push) Blocked by required conditions
Main CI Pipeline / Web Tests (push) Blocked by required conditions
Main CI Pipeline / Style Check (push) Waiting to run
Main CI Pipeline / VDB Tests (push) Blocked by required conditions
Main CI Pipeline / DB Migration Test (push) Blocked by required conditions
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
from collections.abc import Generator
|
|
|
|
import boto3 # type: ignore
|
|
from botocore.exceptions import ClientError # type: ignore
|
|
|
|
from configs import dify_config
|
|
from extensions.storage.base_storage import BaseStorage
|
|
|
|
|
|
class OracleOCIStorage(BaseStorage):
|
|
"""Implementation for Oracle OCI storage."""
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
self.bucket_name = dify_config.OCI_BUCKET_NAME
|
|
self.client = boto3.client(
|
|
"s3",
|
|
aws_secret_access_key=dify_config.OCI_SECRET_KEY,
|
|
aws_access_key_id=dify_config.OCI_ACCESS_KEY,
|
|
endpoint_url=dify_config.OCI_ENDPOINT,
|
|
region_name=dify_config.OCI_REGION,
|
|
)
|
|
|
|
def save(self, filename, data):
|
|
self.client.put_object(Bucket=self.bucket_name, Key=filename, Body=data)
|
|
|
|
def load_once(self, filename: str) -> bytes:
|
|
try:
|
|
data: bytes = self.client.get_object(Bucket=self.bucket_name, Key=filename)["Body"].read()
|
|
except ClientError as ex:
|
|
if ex.response.get("Error", {}).get("Code") == "NoSuchKey":
|
|
raise FileNotFoundError("File not found")
|
|
else:
|
|
raise
|
|
return data
|
|
|
|
def load_stream(self, filename: str) -> Generator:
|
|
try:
|
|
response = self.client.get_object(Bucket=self.bucket_name, Key=filename)
|
|
yield from response["Body"].iter_chunks()
|
|
except ClientError as ex:
|
|
if ex.response.get("Error", {}).get("Code") == "NoSuchKey":
|
|
raise FileNotFoundError("File not found")
|
|
else:
|
|
raise
|
|
|
|
def download(self, filename, target_filepath):
|
|
self.client.download_file(self.bucket_name, filename, target_filepath)
|
|
|
|
def exists(self, filename):
|
|
try:
|
|
self.client.head_object(Bucket=self.bucket_name, Key=filename)
|
|
return True
|
|
except:
|
|
return False
|
|
|
|
def delete(self, filename):
|
|
self.client.delete_object(Bucket=self.bucket_name, Key=filename)
|