version 1

This commit is contained in:
2025-07-15 14:11:39 +08:00
parent 81d4874926
commit dc94cc41c2
16 changed files with 1872 additions and 445 deletions

45
utils/asset_manager.py Normal file
View File

@ -0,0 +1,45 @@
# utils/asset_manager.py
import streamlit as st
from pathlib import Path
from config import SHARED_ASSETS_DIR
def list_shared_videos() -> list[str]:
"""列出所有共享影片的檔案名稱。"""
try:
if not SHARED_ASSETS_DIR.exists():
return []
return sorted(
[f.name for f in SHARED_ASSETS_DIR.glob('*') if f.suffix.lower() in ['.mp4', '.mov']]
)
except Exception as e:
# 可以在這裡記錄錯誤日誌
st.error(f"讀取共享素材庫時出錯: {e}")
return []
def save_uploaded_shared_videos(uploaded_files: list) -> tuple[int, list[str]]:
"""
將上傳的檔案儲存到共享素材庫。
回傳 (成功數量, 錯誤訊息列表)。
"""
if not uploaded_files:
return 0, []
saved_count = 0
errors = []
try:
SHARED_ASSETS_DIR.mkdir(parents=True, exist_ok=True)
for uploaded_file in uploaded_files:
try:
with open(SHARED_ASSETS_DIR / uploaded_file.name, "wb") as f:
f.write(uploaded_file.getbuffer())
saved_count += 1
except Exception as e:
errors.append(f"儲存 '{uploaded_file.name}' 時出錯: {e}")
except Exception as e:
errors.append(f"無法建立共享資料夾 '{SHARED_ASSETS_DIR}': {e}")
return saved_count, errors