@@ -797,7 +797,12 @@ async def admin_reset(user: str = Depends(admin_required)):
797797 if users_path .exists ():
798798 users_path .unlink ()
799799
800- # Re-initialize with defaults (this will happen on next load)
800+ # Re-initialize with defaults immediately to prevent lockout
801+ try :
802+ user_manager ._ensure_users_file ()
803+ except Exception as e :
804+ logger .error (f"Failed to recreate default admin during reset: { e } " )
805+
801806 # Force logout
802807 resp = RedirectResponse ("/login" , status_code = 303 )
803808 resp .delete_cookie ("sc_session" )
@@ -854,15 +859,34 @@ async def upload_endpoint(files: list[UploadFile]):
854859 import uuid
855860 clean_name = f"upload_{ uuid .uuid4 ().hex [:8 ]} .bin"
856861
857- # Truncate long filenames
858- if len (clean_name ) > 200 :
859- name_parts = clean_name .rsplit ("." , 1 )
860- if len (name_parts ) > 1 :
861- clean_name = name_parts [0 ][:190 ] + "." + name_parts [1 ]
862+ # Append short UUID and ensure uniqueness
863+ import uuid
864+ uid = uuid .uuid4 ().hex [:8 ]
865+ parts = clean_name .rsplit ("." , 1 )
866+
867+ candidate_name = clean_name
868+ if len (parts ) > 1 :
869+ candidate_name = f"{ parts [0 ]} _{ uid } .{ parts [1 ]} "
870+ else :
871+ candidate_name = f"{ clean_name } _{ uid } "
872+
873+ path = UPLOAD_DIR / candidate_name
874+ # Final collision safety loop (backup in case of rapid concurrent identical uploads)
875+ while path .exists ():
876+ uid = uuid .uuid4 ().hex [:4 ]
877+ parts = candidate_name .rsplit ("_" , 1 ) # Split by our own suffix
878+ if len (parts ) > 1 :
879+ # Re-try with new suffix
880+ base = parts [0 ]
881+ ext_parts = parts [1 ].rsplit ("." , 1 )
882+ if len (ext_parts ) > 1 :
883+ candidate_name = f"{ base } _{ uid } .{ ext_parts [1 ]} "
884+ else :
885+ candidate_name = f"{ base } _{ uid } "
862886 else :
863- clean_name = clean_name [:200 ]
887+ candidate_name = f"{ candidate_name } _{ uid } "
888+ path = UPLOAD_DIR / candidate_name
864889
865- path = UPLOAD_DIR / clean_name
866890 try :
867891 with open (path , "wb" ) as buffer :
868892 shutil .copyfileobj (file .file , buffer )
0 commit comments