88
99from datetime import timedelta
1010from sys import stderr
11- from typing import Any , Dict , Optional , List , Union , cast
11+ from typing import Any , Dict , Optional , List , Union , cast , Tuple
1212
1313from alembic import command
1414import click
@@ -180,14 +180,16 @@ def upload_file(auth_dict: Optional[Dict[str, Any]] = None):
180180 assert dir_path
181181 assert parent
182182 assert owner
183- file_model = add_file (filename , dir_path , parent , "" , owner )
183+ mime , file_model = add_file (filename , dir_path , parent , "" , owner )
184184
185185 # Upload File
186186 file_stat = os .stat (filepath )
187187 with open (filepath , "rb" ) as f_hnd :
188188 storage_interface .put (
189189 "files/{}" .format (file_model .s3_id ),
190- f_hnd
190+ f_hnd ,
191+ filename ,
192+ mime
191193 )
192194 os .remove (filepath )
193195
@@ -198,6 +200,8 @@ def upload_file(auth_dict: Optional[Dict[str, Any]] = None):
198200 storage_interface .put (
199201 "thumbnails/" + file_model .s3_id ,
200202 f_hnd ,
203+ "thumb_" + filename + "." + filepath .split ("." )[- 1 ],
204+ "image/gif" if filepath .endswith (".gif" ) else "image/jpeg"
201205 )
202206 os .remove (filepath )
203207 os .rmdir (dir_path )
@@ -347,6 +351,8 @@ def init_root():
347351 storage_interface .put (
348352 "files/{}" .format (DEFAULT_THUMBNAIL_NAME ),
349353 f_hnd ,
354+ "thumb_" + DEFAULT_THUMBNAIL_NAME + ".jpg" ,
355+ "image/jpeg"
350356 )
351357
352358
@@ -367,12 +373,12 @@ def add_directory(parent_id: str, name: str, description: str, owner: str):
367373 return dir_model .id
368374
369375
370- def add_file (file_name : str , path : str , dir_id : str , description : str , owner : str ) -> Optional [File ]:
376+ def add_file (file_name : str , path : str , dir_id : str , description : str , owner : str ) -> Tuple [ str , Optional [File ] ]:
371377 file_path = os .path .join ('/' , path , file_name )
372378
373- file_data = parse_file_info (file_path , path )
379+ mime , file_data = parse_file_info (file_path , path )
374380 if file_data is None :
375- return None
381+ return mime , None
376382
377383 file_model = File (
378384 dir_id ,
@@ -389,7 +395,7 @@ def add_file(file_name: str, path: str, dir_id: str, description: str, owner: st
389395 db .session .flush ()
390396 db .session .commit ()
391397 db .session .refresh (file_model )
392- return file_model
398+ return mime , file_model
393399
394400
395401def refresh_directory_thumbnail (dir_model : Directory ) -> str :
0 commit comments