Add "Show in folder" button to photos, albums.
This commit is contained in:
		
							parent
							
								
									361795237c
								
							
						
					
					
						commit
						400c255aea
					
				
					 5 changed files with 83 additions and 1 deletions
				
			
		|  | @ -1,4 +1,5 @@ | ||||||
| import flask; from flask import request | import flask; from flask import request | ||||||
|  | import os | ||||||
| import time | import time | ||||||
| import urllib.parse | import urllib.parse | ||||||
| 
 | 
 | ||||||
|  | @ -173,6 +174,24 @@ def post_album_edit(album_id): | ||||||
|     response = album.jsonify(minimal=True) |     response = album.jsonify(minimal=True) | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
| 
 | 
 | ||||||
|  | @site.route('/album/<album_id>/show_in_folder', methods=['POST']) | ||||||
|  | def post_album_show_in_folder(album_id): | ||||||
|  |     if not request.is_localhost: | ||||||
|  |         flask.abort(403) | ||||||
|  | 
 | ||||||
|  |     album = common.P_album(album_id, response_type='json') | ||||||
|  |     directories = album.get_associated_directories() | ||||||
|  |     if len(directories) != 1: | ||||||
|  |         flask.abort(400) | ||||||
|  |     directory = directories.pop() | ||||||
|  | 
 | ||||||
|  |     if os.name == 'nt': | ||||||
|  |         command = f'start explorer.exe "{directory.absolute_path}"' | ||||||
|  |         os.system(command) | ||||||
|  |         return jsonify.make_json_response({}) | ||||||
|  | 
 | ||||||
|  |     flask.abort(501) | ||||||
|  | 
 | ||||||
| # Album listings ################################################################################### | # Album listings ################################################################################### | ||||||
| 
 | 
 | ||||||
| @site.route('/all_albums.json') | @site.route('/all_albums.json') | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| import flask; from flask import request | import flask; from flask import request | ||||||
|  | import os | ||||||
| import traceback | import traceback | ||||||
| import urllib.parse | import urllib.parse | ||||||
| 
 | 
 | ||||||
|  | @ -211,6 +212,19 @@ def post_batch_photos_searchhidden_core(photo_ids, searchhidden): | ||||||
| 
 | 
 | ||||||
|     return jsonify.make_json_response({}) |     return jsonify.make_json_response({}) | ||||||
| 
 | 
 | ||||||
|  | @site.route('/photo/<photo_id>/show_in_folder', methods=['POST']) | ||||||
|  | def post_photo_show_in_folder(photo_id): | ||||||
|  |     if not request.is_localhost: | ||||||
|  |         flask.abort(403) | ||||||
|  | 
 | ||||||
|  |     photo = common.P_photo(photo_id, response_type='json') | ||||||
|  |     if os.name == 'nt': | ||||||
|  |         command = f'start explorer.exe /select,"{photo.real_path.absolute_path}"' | ||||||
|  |         os.system(command) | ||||||
|  |         return jsonify.make_json_response({}) | ||||||
|  | 
 | ||||||
|  |     flask.abort(501) | ||||||
|  | 
 | ||||||
| @site.route('/batch/photos/set_searchhidden', methods=['POST']) | @site.route('/batch/photos/set_searchhidden', methods=['POST']) | ||||||
| @decorators.required_fields(['photo_ids'], forbid_whitespace=True) | @decorators.required_fields(['photo_ids'], forbid_whitespace=True) | ||||||
| def post_batch_photos_set_searchhidden(): | def post_batch_photos_set_searchhidden(): | ||||||
|  |  | ||||||
|  | @ -117,6 +117,13 @@ function set_thumbnail_photo(album_id, photo_id, callback) | ||||||
|     common.post(url, data, callback); |     common.post(url, data, callback); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | api.albums.show_in_folder = | ||||||
|  | function show_in_folder(album_id, callback) | ||||||
|  | { | ||||||
|  |     const url = `/album/${album_id}/show_in_folder`; | ||||||
|  |     common.post(url, null, callback); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| api.albums.callback_follow = | api.albums.callback_follow = | ||||||
| function callback_follow(response) | function callback_follow(response) | ||||||
| { | { | ||||||
|  | @ -306,6 +313,13 @@ function unset_searchhidden(photo_id, callback) | ||||||
|     common.post(url, null, callback); |     common.post(url, null, callback); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | api.photos.show_in_folder = | ||||||
|  | function show_in_folder(photo_id, callback) | ||||||
|  | { | ||||||
|  |     const url = `/photo/${photo_id}/show_in_folder`; | ||||||
|  |     common.post(url, null, callback); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| api.photos.callback_go_to_search = | api.photos.callback_go_to_search = | ||||||
| function callback_go_to_search(response) | function callback_go_to_search(response) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -226,6 +226,10 @@ const ALBUM_ID = undefined; | ||||||
|         > |         > | ||||||
|             Refresh directories |             Refresh directories | ||||||
|         </button> |         </button> | ||||||
|  | 
 | ||||||
|  |         {% if request.is_localhost and associated_directories|length == 1 %} | ||||||
|  |         <button id="show_in_folder_button" onclick="return show_in_folder_form();">Show in folder</button> | ||||||
|  |         {% endif %} | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|     <div id="left"> |     <div id="left"> | ||||||
|  | @ -408,6 +412,20 @@ const rename_ed = new editor.Editor( | ||||||
|     rename_ed_on_save, |     rename_ed_on_save, | ||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
|  | function show_in_folder_form() | ||||||
|  | { | ||||||
|  |     api.albums.show_in_folder(ALBUM_ID, show_in_folder_callback); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function show_in_folder_callback(response) | ||||||
|  | { | ||||||
|  |     if (response.meta.status !== 200) | ||||||
|  |     { | ||||||
|  |         alert(JSON.stringify(response)); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function add_album_datalist_on_load(datalist) | function add_album_datalist_on_load(datalist) | ||||||
| { | { | ||||||
|     /* |     /* | ||||||
|  |  | ||||||
|  | @ -189,7 +189,10 @@ | ||||||
|                 <li>Duration: {{photo.duration_string}}</li> |                 <li>Duration: {{photo.duration_string}}</li> | ||||||
|                 <li>Overall Bitrate: {{photo.bitrate|int}} kbps</li> |                 <li>Overall Bitrate: {{photo.bitrate|int}} kbps</li> | ||||||
|             {% endif %} |             {% endif %} | ||||||
|             <li><button id="refresh_metadata_button" class="green_button button_with_spinner" onclick="return refresh_metadata_form();">refresh metadata</button></li> |             <li><button id="refresh_metadata_button" class="green_button button_with_spinner" onclick="return refresh_metadata_form();">Refresh metadata</button></li> | ||||||
|  |             {% if request.is_localhost %} | ||||||
|  |             <li><button id="show_in_folder_button" onclick="return show_in_folder_form();">Show in folder</button></li> | ||||||
|  |             {% endif %} | ||||||
|             <li><a href="{{photo|file_link}}?download=true&original_filename=true">Download as original filename</a></li> |             <li><a href="{{photo|file_link}}?download=true&original_filename=true">Download as original filename</a></li> | ||||||
|             <li><a href="{{photo|file_link}}?download=true">Download as {{photo.id}}.{{photo.extension}}</a></li> |             <li><a href="{{photo|file_link}}?download=true">Download as {{photo.id}}.{{photo.extension}}</a></li> | ||||||
|             <li> |             <li> | ||||||
|  | @ -455,6 +458,20 @@ function set_searchhidden_callback(response) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function show_in_folder_form() | ||||||
|  | { | ||||||
|  |     api.photos.show_in_folder(PHOTO_ID, show_in_folder_callback); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function show_in_folder_callback(response) | ||||||
|  | { | ||||||
|  |     if (response.meta.status !== 200) | ||||||
|  |     { | ||||||
|  |         alert(JSON.stringify(response)); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // UI ////////////////////////////////////////////////////////////////////////////////////////////// | // UI ////////////////////////////////////////////////////////////////////////////////////////////// | ||||||
| 
 | 
 | ||||||
| function sort_tag_cards() | function sort_tag_cards() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue