@@ -245,9 +245,10 @@ def _startup_once():
245245 _run_startup_tasks ()
246246
247247
248- # ========== ROUTES ==========
248+ # ========== ROUTES ==========
249249
250250#########################################################
251+
251252# Admin only rescanning for duplicates and re-importing
252253
253254@app .route ('/admin/rescan_uploads' )
@@ -278,7 +279,9 @@ def rescan_uploads():
278279 })
279280 except Exception as e :
280281 return jsonify ({"status" : f"auto_log_material_files failed: { e } " }), 500
282+
281283#########################################################
284+
282285# -- Admin login/logout --
283286@app .route ('/login' , methods = ['GET' , 'POST' ])
284287def login ():
@@ -296,7 +299,9 @@ def logout():
296299 session .pop ('admin' , None )
297300 flash ("Logged out." )
298301 return redirect (url_for ('public_home' ))
302+
299303#########################################################
304+
300305# -- Admin-only home page (upload/import/query) --
301306@app .route ('/admin' , methods = ['GET' , 'POST' ])
302307def admin_home ():
@@ -329,7 +334,9 @@ def admin_home():
329334 uploads = uploads ,
330335 music_clips = music_clips
331336 )
337+
332338#########################################################
339+
333340# -- View and import (admin only) --
334341@app .route ('/materials/<property_name>/<tab>' , methods = ['GET' , 'POST' ])
335342def property_detail (property_name , tab ):
@@ -447,7 +454,9 @@ def property_detail(property_name, tab):
447454 edit_message = edit_message ,
448455 admin = is_admin ,
449456 )
457+
450458#########################################################
459+
451460@app .route ('/uploads/<path:filename>' )
452461def uploaded_file (filename ):
453462 full_path = os .path .join (app .config ['UPLOAD_FOLDER' ], filename )
@@ -456,7 +465,9 @@ def uploaded_file(filename):
456465 print ('File not found:' , full_path )
457466 abort (404 )
458467 return send_from_directory (app .config ['UPLOAD_FOLDER' ], filename )
468+
459469#########################################################
470+
460471@app .route ('/view_result/<property_name>/<tab>/<path:filename>' )
461472def view_result_file (property_name , tab , filename ):
462473 filepath = os .path .join (app .config ['UPLOAD_FOLDER' ], property_name , tab , filename )
@@ -475,7 +486,9 @@ def extract_drive_id(link):
475486 if match :
476487 return match .group (1 )
477488 raise ValueError ("Invalid Drive link" )
489+
478490#########################################################
491+
479492@app .route ('/clips' )
480493def public_clips ():
481494 import os
@@ -508,7 +521,9 @@ def public_clips():
508521 pass
509522
510523 return render_template ('clips.html' , clips = clips , admin = admin )
524+
511525#########################################################
526+
512527@app .route ('/dataset/<table>' )
513528def public_view (table ):
514529 # Anyone can view any table
@@ -520,15 +535,19 @@ def public_view(table):
520535 filename = table ,
521536 imported_table = table ,
522537 admin = False )
538+
523539#########################################################
540+
524541@app .route ('/download/<table>' )
525542def download (table ):
526543 with sqlite3 .connect (DB_NAME ) as conn :
527544 df = pd .read_sql_query (f"SELECT * FROM { table } " , conn )
528545 csv_path = os .path .join (UPLOAD_FOLDER , f"{ table } .csv" )
529546 df .to_csv (csv_path , index = False )
530547 return send_from_directory (UPLOAD_FOLDER , f"{ table } .csv" , as_attachment = True )
548+
531549#########################################################
550+
532551@app .route ('/migrate_csv_to_db' )
533552def migrate_csv_to_db ():
534553 if not session .get ('admin' ):
@@ -571,7 +590,9 @@ def migrate_csv_to_db():
571590 return "✅ Table recreated and data loaded from CSV!"
572591 except Exception as e :
573592 return f"❌ Error: { e } "
593+
574594#########################################################
595+
575596# SEARCH ROUTE
576597@app .route ('/search' )
577598def search ():
@@ -606,7 +627,9 @@ def search():
606627 except Exception :
607628 clips = []
608629 return render_template ('search_results.html' , query = query , materials = materials , clips = clips )
630+
609631#########################################################
632+
610633# DELETE CLIP
611634@app .route ('/delete_clip/<int:clip_id>' , methods = ['POST' ])
612635def delete_clip (clip_id ):
@@ -625,7 +648,9 @@ def delete_clip(clip_id):
625648 c .execute ("DELETE FROM music_clips WHERE id = ?" , (clip_id ,))
626649 conn .commit ()
627650 return redirect (url_for ('public_clips' ))
651+
628652#########################################################
653+
629654# DELETE DATASET/RESULT FILE
630655from urllib .parse import unquote
631656
@@ -660,7 +685,9 @@ def delete_dataset_file(property_name, tab, filename):
660685 conn .commit ()
661686
662687 return redirect (url_for ('property_detail' , property_name = property_name , tab = tab ))
688+
663689#########################################################
690+
664691@app .route ('/add_drive_clip' , methods = ['GET' , 'POST' ])
665692def add_drive_clip ():
666693 if not session .get ('admin' ):
0 commit comments