lexlepty commited on
Commit
ea2be53
·
verified ·
1 Parent(s): dcc07d8

Delete utils.py

Browse files
Files changed (1) hide show
  1. utils.py +0 -28
utils.py DELETED
@@ -1,28 +0,0 @@
1
- import os
2
-
3
- def get_file_type(filename):
4
- """根据文件扩展名判断文件类型"""
5
- ext = os.path.splitext(filename)[1].lower()
6
-
7
- # 文件类型映射
8
- type_map = {
9
- 'image': ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'],
10
- 'video': ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv'],
11
- 'document': ['.pdf', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.txt'],
12
- 'audio': ['.mp3', '.wav', '.ogg', '.m4a'],
13
- 'archive': ['.zip', '.rar', '.7z', '.tar', '.gz'],
14
- 'code': ['.py', '.js', '.html', '.css', '.json', '.xml']
15
- }
16
-
17
- for file_type, extensions in type_map.items():
18
- if ext in extensions:
19
- return file_type
20
- return 'other'
21
-
22
- def format_file_size(size):
23
- """格式化文件大小"""
24
- for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
25
- if size < 1024:
26
- return f"{size:.2f} {unit}"
27
- size /= 1024
28
- return f"{size:.2f} PB"