feat(storage): support remove old files

This commit is contained in:
MingxuanGame
2025-08-28 12:17:35 +00:00
parent cbc46d63b6
commit 80b102af2d
7 changed files with 68 additions and 0 deletions

View File

@@ -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