diff --git a/frontends/etiquette_flask/backend/endpoints/album_endpoints.py b/frontends/etiquette_flask/backend/endpoints/album_endpoints.py index 0d5fe43..d8e54e4 100644 --- a/frontends/etiquette_flask/backend/endpoints/album_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/album_endpoints.py @@ -1,4 +1,5 @@ import flask; from flask import request +import os import time import urllib.parse @@ -173,6 +174,24 @@ def post_album_edit(album_id): response = album.jsonify(minimal=True) return jsonify.make_json_response(response) +@site.route('/album//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 ################################################################################### @site.route('/all_albums.json') diff --git a/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py b/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py index 978bf9f..9215c5d 100644 --- a/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py @@ -1,4 +1,5 @@ import flask; from flask import request +import os import traceback import urllib.parse @@ -211,6 +212,19 @@ def post_batch_photos_searchhidden_core(photo_ids, searchhidden): return jsonify.make_json_response({}) +@site.route('/photo//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']) @decorators.required_fields(['photo_ids'], forbid_whitespace=True) def post_batch_photos_set_searchhidden(): diff --git a/frontends/etiquette_flask/static/js/api.js b/frontends/etiquette_flask/static/js/api.js index 5070cc5..600c3e4 100644 --- a/frontends/etiquette_flask/static/js/api.js +++ b/frontends/etiquette_flask/static/js/api.js @@ -117,6 +117,13 @@ function set_thumbnail_photo(album_id, photo_id, 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 = function callback_follow(response) { @@ -306,6 +313,13 @@ function unset_searchhidden(photo_id, 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 = function callback_go_to_search(response) { diff --git a/frontends/etiquette_flask/templates/album.html b/frontends/etiquette_flask/templates/album.html index 6d33ae6..09022d5 100644 --- a/frontends/etiquette_flask/templates/album.html +++ b/frontends/etiquette_flask/templates/album.html @@ -226,6 +226,10 @@ const ALBUM_ID = undefined; > Refresh directories + + {% if request.is_localhost and associated_directories|length == 1 %} + + {% endif %}
@@ -408,6 +412,20 @@ const rename_ed = new editor.Editor( 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) { /* diff --git a/frontends/etiquette_flask/templates/photo.html b/frontends/etiquette_flask/templates/photo.html index 0bec57a..398f0f6 100644 --- a/frontends/etiquette_flask/templates/photo.html +++ b/frontends/etiquette_flask/templates/photo.html @@ -189,7 +189,10 @@
  • Duration: {{photo.duration_string}}
  • Overall Bitrate: {{photo.bitrate|int}} kbps
  • {% endif %} -
  • +
  • + {% if request.is_localhost %} +
  • + {% endif %}
  • Download as original filename
  • Download as {{photo.id}}.{{photo.extension}}
  • @@ -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 ////////////////////////////////////////////////////////////////////////////////////////////// function sort_tag_cards()