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

@@ -40,6 +40,11 @@ async def upload_avatar(
# check file
check_image(content, 5 * 1024 * 1024, 256, 256)
if url := current_user.avatar_url:
path = storage.get_file_name_by_url(url)
if path:
await storage.delete_file(path)
filehash = hashlib.sha256(content).hexdigest()
storage_path = f"avatars/{current_user.id}_{filehash}.png"
if not await storage.is_exists(storage_path):