Add endpoint /batch/photos/generate_thumbnail.
This commit is contained in:
parent
b384f2895a
commit
ef668c5d3b
3 changed files with 77 additions and 8 deletions
|
@ -67,7 +67,7 @@ def get_file(photo_id, basename=None):
|
|||
@site.route('/photo/<photo_id>/thumbnail')
|
||||
@site.route('/photo/<photo_id>/thumbnail/<basename>')
|
||||
@common.permission_manager.basic_decorator
|
||||
@flasktools.cached_endpoint(max_age=common.BROWSER_CACHE_DURATION)
|
||||
@flasktools.cached_endpoint(max_age=common.BROWSER_CACHE_DURATION, etag_function=lambda: common.P.last_commit_id)
|
||||
def get_thumbnail(photo_id, basename=None):
|
||||
photo_id = photo_id.split('.')[0]
|
||||
photo = common.P_photo(photo_id, response_type='html')
|
||||
|
@ -186,16 +186,35 @@ def post_batch_photos_remove_tag():
|
|||
|
||||
# Photo metadata operations ########################################################################
|
||||
|
||||
def post_photo_generate_thumbnail_core(photo_ids, special={}):
|
||||
if isinstance(photo_ids, str):
|
||||
photo_ids = stringtools.comma_space_split(photo_ids)
|
||||
|
||||
with common.P.transaction:
|
||||
photos = list(common.P_photos(photo_ids, response_type='json'))
|
||||
|
||||
for photo in photos:
|
||||
photo._uncache()
|
||||
photo = common.P_photo(photo.id, response_type='json')
|
||||
try:
|
||||
photo.generate_thumbnail()
|
||||
except Exception:
|
||||
log.warning(traceback.format_exc())
|
||||
|
||||
return flasktools.json_response({})
|
||||
|
||||
@site.route('/photo/<photo_id>/generate_thumbnail', methods=['POST'])
|
||||
def post_photo_generate_thumbnail(photo_id):
|
||||
common.permission_manager.basic()
|
||||
special = request.form.to_dict()
|
||||
response = post_photo_generate_thumbnail_core(photo_ids=photo_id, special=special)
|
||||
return response
|
||||
|
||||
with common.P.transaction:
|
||||
photo = common.P_photo(photo_id, response_type='json')
|
||||
photo.generate_thumbnail(**special)
|
||||
|
||||
response = flasktools.json_response({})
|
||||
@site.route('/batch/photos/generate_thumbnail', methods=['POST'])
|
||||
def post_batch_photos_generate_thumbnail():
|
||||
common.permission_manager.basic()
|
||||
special = request.form.to_dict()
|
||||
response = post_photo_generate_thumbnail_core(photo_ids=request.form['photo_ids'], special=special)
|
||||
return response
|
||||
|
||||
def post_photo_refresh_metadata_core(photo_ids):
|
||||
|
|
|
@ -236,7 +236,17 @@ function batch_add_tag(photo_ids, tagname, callback)
|
|||
return http.post({
|
||||
url: "/batch/photos/add_tag",
|
||||
data: {"photo_ids": photo_ids.join(","), "tagname": tagname},
|
||||
add_remove_tag_callback: callback,
|
||||
callback: callback,
|
||||
});
|
||||
}
|
||||
|
||||
api.photos.batch_generate_thumbnail =
|
||||
function batch_generate_thumbnail(photo_ids, callback)
|
||||
{
|
||||
return http.post({
|
||||
url: "/batch/photos/generate_thumbnail",
|
||||
data: {"photo_ids": photo_ids.join(",")},
|
||||
callback: callback,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -256,7 +266,7 @@ function batch_remove_tag(photo_ids, tagname, callback)
|
|||
return http.post({
|
||||
url: "/batch/photos/remove_tag",
|
||||
data: {"photo_ids": photo_ids.join(","), "tagname": tagname},
|
||||
add_remove_tag_callback: callback,
|
||||
callback: callback,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -122,6 +122,10 @@
|
|||
<button class="green_button button_with_spinner" id="refresh_metadata_button" data-spinner-delay="500" onclick="return refresh_metadata_form();">Refresh metadata</button>
|
||||
</div>
|
||||
|
||||
<div id="generate_thumbnail_area">
|
||||
<button class="green_button button_with_spinner" id="generate_thumbnail_button" data-spinner-delay="500" onclick="return generate_thumbnail_form();">Generate thumbnail</button>
|
||||
</div>
|
||||
|
||||
<div id="searchhidden_area">
|
||||
<button class="yellow_button" id="set_searchhidden_button" onclick="return set_searchhidden_form();">Searchhide</button>
|
||||
<button class="yellow_button" id="unset_searchhidden_button" onclick="return unset_searchhidden_form();">Unhide</button>
|
||||
|
@ -369,6 +373,42 @@ function refresh_metadata_form()
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const generate_thumbnail_button = document.getElementById("generate_thumbnail_button");
|
||||
|
||||
function generate_thumbnail_callback(response)
|
||||
{
|
||||
window[generate_thumbnail_button.dataset.spinnerCloser]();
|
||||
if (! response.meta.json_ok)
|
||||
{
|
||||
alert(JSON.stringify(response));
|
||||
return;
|
||||
}
|
||||
if ("error_type" in response.data)
|
||||
{
|
||||
const message_area = document.getElementById("message_area");
|
||||
const message_positivity = "message_negative";
|
||||
const message_text = response.data.error_message;
|
||||
common.create_message_bubble(message_area, message_positivity, message_text, 8000);
|
||||
}
|
||||
else
|
||||
{
|
||||
common.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
function generate_thumbnail_form()
|
||||
{
|
||||
if (photo_clipboard.clipboard.size == 0)
|
||||
{
|
||||
return spinners.BAIL;
|
||||
}
|
||||
|
||||
const photo_ids = Array.from(photo_clipboard.clipboard);
|
||||
api.photos.batch_generate_thumbnail(photo_ids, generate_thumbnail_callback);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function set_unset_searchhidden_callback(response)
|
||||
{
|
||||
if (! response.meta.json_ok)
|
||||
|
|
Loading…
Reference in a new issue