def aip_file_download(request, uuid): es_client = es.get_client() # get AIP file properties aipfile = es.get_aipfile_data(es_client, uuid, fields="filePath,FILEUUID,AIPUUID") # get file's AIP's properties sipuuid = aipfile["_source"]["AIPUUID"] aip = es.get_aip_data( es_client, sipuuid, fields="uuid,name,filePath,size,origin,created" ) aip_filepath = aip["_source"]["filePath"] # work out path components aip_archive_filename = os.path.basename(aip_filepath) # splittext doesn't deal with double extensions, so special-case .tar.bz2 if aip_archive_filename.endswith(".tar.bz2"): subdir = aip_archive_filename[:-8] else: subdir = os.path.splitext(aip_archive_filename)[0] file_relative_path = os.path.join(subdir, "data", aipfile["_source"]["filePath"]) redirect_url = storage_service.extract_file_url( aip["_source"]["uuid"], file_relative_path ) return helpers.stream_file_from_storage_service( redirect_url, "Storage service returned {}; check logs?" )
def send_thumbnail(request, fileuuid): # get AIP location to use to find root of AIP storage es_client = es.get_client() aipfile = es.get_aipfile_data(es_client, fileuuid, fields="AIPUUID") sipuuid = aipfile["_source"]["AIPUUID"] thumbnail_path = os.path.join( settings.SHARED_DIRECTORY, "www", "thumbnails", sipuuid, fileuuid + ".jpg" ) # send "blank" thumbnail if one exists: # Because thumbnails aren't kept in ElasticSearch they can be queried for, # during searches, from multiple dashboard servers. # Because ElasticSearch don't know if a thumbnail exists or not, this is # a way of not causing visual disruption if a thumbnail doesn't exist. if not os.path.exists(thumbnail_path): thumbnail_path = os.path.join(settings.BASE_PATH, "media/images/1x1-pixel.png") return helpers.send_file(request, thumbnail_path)