1717 is_admin ,
1818 is_staff ,
1919 process_cover_image ,
20+ process_cd_cover ,
2021 download_image
2122)
2223from library_db .utils .db_utils import (
3839
3940
4041
41- ALLOWED_EXTENSIONS = {'.png' , '.jpg' , '.jpeg' }
42+ ALLOWED_EXTENSIONS = {'.png' , '.jpg' , '.jpeg' , '.webp' }
4243
4344def allowed_file (filename ):
4445 return Path (filename ).suffix in ALLOWED_EXTENSIONS
@@ -115,17 +116,17 @@ def ret_error(error: str):
115116 return ret_error ("Bad Form Data" )
116117
117118 media = get_media (id )
118-
119+
119120 if not media :
120121 return ret_error ("Bad Form Data" )
121-
122+
122123 if not media .title == title :
123124 media_title_id = get_media_id (title )
124125 if media_title_id :
125126 return ret_error ("Media With this Title already exsists" )
126-
127- if not age_limit :
128- return ret_error ( "Bad Form Data" )
127+
128+ if age_limit is None :
129+ age_limit = 0
129130
130131 if not media_type in get_media_types ():
131132 return ret_error ("Media Type doesnt exsist" )
@@ -226,26 +227,6 @@ def ret_error(error: str):
226227 except KeyError :
227228 return ret_error ("Bad Form Data" )
228229
229- filename = None
230- if "image" in request .files or "url" in request .form :
231- file = request .files ["image" ]
232- url = request .form ["url" ]
233- filename = uuid .uuid1 ().hex + ".jpg"
234- save_path = Path (current_app .config ['UPLOAD_FOLDER' ]).joinpath (filename ).__str__ ()
235-
236- if file .filename != '' and url != '' :
237- return ret_error ("Can't upload Image and use Scraper Image" )
238- elif not file .filename == '' and allowed_file (file .filename ):
239- file .save (save_path )
240- process_cover_image (save_path )
241- elif not url == '' :
242- if download_image (url , save_path ) != 1 :
243- filename = None
244- else :
245- process_cover_image (save_path )
246- else :
247- filename = None
248-
249230 if isbn :
250231 try :
251232 isbn = int (isbn )
@@ -261,18 +242,44 @@ def ret_error(error: str):
261242 if not media_type in get_media_types ():
262243 return ret_error ("Media Type doesnt exsist" )
263244
264- media_type = get_media_type_id (media_type )
245+ media_type_id = get_media_type_id (media_type )
265246
266247 if not author_exsists (author ):
267248 return ret_error ("Author does not exsist" )
268249
269- author = get_author_id (author )
250+ author_id = get_author_id (author )
251+
252+ filename = None
253+ if "image" in request .files or "url" in request .form :
254+ file = request .files ["image" ]
255+ url = request .form ["url" ]
256+ filename = uuid .uuid1 ().hex + ".jpg"
257+ save_path = Path (current_app .config ['UPLOAD_FOLDER' ]).joinpath (filename ).__str__ ()
258+
259+ if file .filename != '' and url != '' :
260+ return ret_error ("Can't upload Image and use Scraper Image" )
261+ elif not file .filename == '' and allowed_file (file .filename ):
262+ file .save (save_path )
263+ if media_type == "CD" :
264+ process_cd_cover (save_path )
265+ else :
266+ process_cover_image (save_path )
267+ elif not url == '' :
268+ if download_image (url , save_path ) != 1 :
269+ filename = None
270+ else :
271+ if media_type == "CD" :
272+ process_cd_cover (save_path )
273+ else :
274+ process_cover_image (save_path )
275+ else :
276+ filename = None
270277
271278 new_id = add_media_item (
272279 title = title ,
273- author_id = author ,
280+ author_id = author_id ,
274281 age_limit = age_limit ,
275- media_type_id = media_type ,
282+ media_type_id = media_type_id ,
276283 isbn = isbn ,
277284 image = filename
278285 )
0 commit comments