def details(): # Get parameters src = request.args.get('src', '') reset = request.args.get('reset', None) src_path = '' try: # Check parameters if src == '': raise ValueError('No filename was specified.') if reset is not None: reset = parse_boolean(reset) file_disk_info = None file_image_info = None file_geo_info = None db_img = None db_history = None db_image_stats = None (src_path, src_filename) = os.path.split(src) # Require view permission or file admin permissions_engine.ensure_folder_permitted( src_path, FolderPermission.ACCESS_VIEW, get_session_user() ) # Get file info from disk file_disk_info = get_file_info(src) if file_disk_info: # Get EXIF info file_image_info = image_engine.get_image_properties(src, True) # Get geo location if we have the relevant profile fields file_geo_info = get_exif_geo_position(file_image_info) # Reset image if requested, then remove the reset from the URL if reset and file_disk_info: image_engine.reset_image(ImageAttrs(src)) return redirect(internal_url_for('details', src=src)) # Get database info db_session = data_engine.db_get_session() db_commit = False try: db_img = auto_sync_file(src, data_engine, task_engine, _db_session=db_session) if db_img: # Trigger lazy load of history db_history = db_img.history # Get stats stats_day = data_engine.summarise_image_stats( datetime.utcnow() - timedelta(days=1), datetime.utcnow(), db_img.id, _db_session=db_session ) stats_month = data_engine.summarise_image_stats( datetime.utcnow() - timedelta(days=30), datetime.utcnow(), db_img.id, _db_session=db_session ) stats_day = stats_day[0] if len(stats_day) > 0 else \ (0, 0, 0, 0, 0, 0, 0, 0) stats_month = stats_month[0] if len(stats_month) > 0 else \ (0, 0, 0, 0, 0, 0, 0, 0) db_image_stats = { 'day': { 'requests': stats_day[1], 'views': stats_day[2], 'cached_views': stats_day[3], 'downloads': stats_day[4], 'bytes': stats_day[5], 'seconds': stats_day[6], 'max_seconds': stats_day[7] }, 'month': { 'requests': stats_month[1], 'views': stats_month[2], 'cached_views': stats_month[3], 'downloads': stats_month[4], 'bytes': stats_month[5], 'seconds': stats_month[6], 'max_seconds': stats_month[7] } } db_commit = True finally: try: if db_commit: db_session.commit() else: db_session.rollback() finally: db_session.close() return render_template( 'details.html', src=src, path=src_path, filename=src_filename, file_info=file_disk_info, image_info=file_image_info, geo_info=file_geo_info, db_info=db_img, db_history=db_history, db_stats=db_image_stats, STATUS_ACTIVE=Image.STATUS_ACTIVE, ACTION_DELETED=ImageHistory.ACTION_DELETED, ACTION_CREATED=ImageHistory.ACTION_CREATED, ACTION_REPLACED=ImageHistory.ACTION_REPLACED, ACTION_EDITED=ImageHistory.ACTION_EDITED, ACTION_MOVED=ImageHistory.ACTION_MOVED, pathsep=os.path.sep, timezone=get_timezone_code() ) except Exception as e: log_security_error(e, request) if app.config['DEBUG']: raise return render_template( 'details.html', src=src, path=src_path, err_msg='This file cannot be viewed: ' + str(e) )
def folder_browse(): from_path = request.args.get('path', '') show_files = request.args.get('show_files', '') embed = request.args.get('embed', '') msg = request.args.get('msg', '') if from_path == '': from_path = os.path.sep db_session = data_engine.db_get_session() db_committed = False try: # This also checks for path existence folder_list = get_directory_listing(from_path, True) # Auto-populate the folders database db_folder = auto_sync_folder( from_path, data_engine, task_engine, _db_session=db_session ) db_session.commit() db_committed = True # Should never happen if db_folder is None: raise DoesNotExistError(from_path) # Require view permission or file admin permissions_engine.ensure_folder_permitted( db_folder, FolderPermission.ACCESS_VIEW, get_session_user() ) return render_template( 'folder_list.html', formats=image_engine.get_image_formats(), embed=embed, msg=msg, name=filepath_filename(from_path), path=from_path, pathsep=os.path.sep, parent_path=filepath_parent(from_path), folder_list=folder_list, show_files=show_files, db_info=db_folder, db_parent_info=db_folder.parent, STATUS_ACTIVE=Folder.STATUS_ACTIVE ) except Exception as e: log_security_error(e, request) if app.config['DEBUG']: raise return render_template( 'folder_list.html', embed=embed, msg=msg, name=filepath_filename(from_path), path=from_path, err_msg='This folder cannot be viewed: ' + str(e) ) finally: try: if not db_committed: db_session.rollback() finally: db_session.close()
def browse(): from_path = request.args.get('path', '') if from_path == '': from_path = os.path.sep # #2475 Default this in case of error in get_directory_listing() directory_info = DirectoryInfo(from_path) db_session = data_engine.db_get_session() db_committed = False try: directory_info = get_directory_listing(from_path, True) # Auto-populate the folders database db_folder = auto_sync_folder( from_path, data_engine, task_engine, _db_session=db_session ) db_session.commit() db_committed = True if db_folder is not None: # Require view permission or file admin permissions_engine.ensure_folder_permitted( db_folder, FolderPermission.ACCESS_VIEW, get_session_user() ) # Remember last path for the Browse and Upload menus if directory_info.exists() and db_folder: session['last_browse_path'] = from_path return render_template( 'list.html', formats=image_engine.get_image_formats(), pathsep=os.path.sep, timezone=get_timezone_code(), directory_info=directory_info, folder_name=filepath_filename(from_path), db_info=db_folder, db_parent_info=db_folder.parent if db_folder else None, STATUS_ACTIVE=Folder.STATUS_ACTIVE ) except Exception as e: log_security_error(e, request) if app.config['DEBUG']: raise return render_template( 'list.html', directory_info=directory_info, err_msg='This folder cannot be viewed: ' + str(e) ) finally: try: if not db_committed: db_session.rollback() finally: db_session.close()