统一的路径生成
(
file_name: str, upload_id: Optional[str] = None
)
| 40 | |
| 41 | @staticmethod |
| 42 | async def generate_file_path( |
| 43 | file_name: str, upload_id: Optional[str] = None |
| 44 | ) -> tuple[str, str, str, str, str]: |
| 45 | """统一的路径生成""" |
| 46 | today = datetime.datetime.now() |
| 47 | storage_path = settings.storage_path.strip("/") |
| 48 | file_uuid = upload_id or uuid.uuid4().hex |
| 49 | filename = await sanitize_filename(unquote(file_name)) |
| 50 | base_path = f"share/data/{today.strftime('%Y/%m/%d')}/{file_uuid}" |
| 51 | path = f"{storage_path}/{base_path}" if storage_path else base_path |
| 52 | prefix, suffix = os.path.splitext(filename) |
| 53 | save_path = f"{path}/{filename}" |
| 54 | return path, suffix, prefix, filename, save_path |
| 55 | |
| 56 | @staticmethod |
| 57 | async def create_file_record( |
no test coverage detected