@@ -63,6 +63,18 @@ def upload():
6363 return render_template ('upload.html' )
6464
6565
66+ @app .route ('/decache' , methods = ['GET' , 'POST' ])
67+ def invalidate_cache ():
68+ app .logger .debug (f"Request to invalidate cache on { request .args } " )
69+ if not request .args .get ('viz_id' ):
70+ cache .invalidate_cache ()
71+ return redirect ("/upload" )
72+ viz_id = request .args .get ('viz_id' )
73+ in_mmif = open (cache .get_cache_path () / viz_id / 'file.mmif' , 'rb' ).read ()
74+ cache .invalidate_cache ([viz_id ])
75+ return upload_file (in_mmif )
76+
77+
6678@app .route ('/display/<viz_id>' )
6779def display (viz_id ):
6880 try :
@@ -85,14 +97,14 @@ def render_mmif(mmif_str, viz_id):
8597 mmif = Mmif (mmif_str )
8698 media = documents_to_htmls (mmif , viz_id )
8799 annotations = prep_annotations (mmif , viz_id )
88- app .logger .debug (f"Prepared Annotations: { annotations . keys () } " )
100+ app .logger .debug (f"Prepared Annotations: { [ annotation [ 0 ] for annotation in annotations ] } " )
89101 return render_template ('player.html' ,
90- media = media , annotations = annotations )
102+ media = media , viz_id = viz_id , annotations = annotations )
91103
92104
93105def upload_file (in_mmif ):
94106 # Save file locally
95- in_mmif_bytes = in_mmif .read ()
107+ in_mmif_bytes = in_mmif if isinstance ( in_mmif , bytes ) else in_mmif .read ()
96108 in_mmif_str = in_mmif_bytes .decode ('utf-8' )
97109 viz_id = hashlib .sha1 (in_mmif_bytes ).hexdigest ()
98110 app .logger .debug (f"Visualization ID: { viz_id } " )
0 commit comments