feat(storage): support remove old files
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from .aws_s3 import AWSS3StorageService
|
||||
|
||||
|
||||
@@ -24,3 +26,18 @@ class CloudflareR2StorageService(AWSS3StorageService):
|
||||
@property
|
||||
def endpoint_url(self) -> str:
|
||||
return f"https://{self.account_id}.r2.cloudflarestorage.com"
|
||||
|
||||
def get_file_name_by_url(self, url: str) -> str | None:
|
||||
if not url:
|
||||
return None
|
||||
|
||||
parsed = urlparse(url)
|
||||
path = parsed.path.lstrip("/")
|
||||
|
||||
if self.public_url_base and url.startswith(self.public_url_base.rstrip("/")):
|
||||
return path
|
||||
|
||||
if ".r2.cloudflarestorage.com" in parsed.netloc:
|
||||
return path
|
||||
|
||||
return path or None
|
||||
|
||||
Reference in New Issue
Block a user