Add endpoint /batch/photos/refresh_metadata.

This commit is contained in:
voussoir 2018-02-24 12:52:36 -08:00
parent 30c9148092
commit 5add26d8fb

View file

@ -133,23 +133,38 @@ def post_batch_photos_remove_tag():
# Photo metadata operations ######################################################################## # Photo metadata operations ########################################################################
@site.route('/photo/<photo_id>/refresh_metadata', methods=['POST'])
@decorators.catch_etiquette_exception @decorators.catch_etiquette_exception
def post_photo_refresh_metadata(photo_id): def post_photo_refresh_metadata_core(photo_ids):
''' if isinstance(photo_ids, str):
Refresh the file metadata. photo_ids = etiquette.helpers.comma_space_split(photo_ids)
'''
common.P.caches['photo'].remove(photo_id) photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids]
photo = common.P_photo(photo_id, response_type='json')
photo.reload_metadata() for photo in photos:
if photo.thumbnail is None: common.P.caches['photo'].remove(photo.id)
try: photo = common.P_photo(photo.id, response_type='json')
photo.generate_thumbnail() photo.reload_metadata(commit=False)
except Exception: if photo.thumbnail is None:
traceback.print_exc() try:
photo.generate_thumbnail(commit=False)
except Exception:
traceback.print_exc()
common.P.commit()
return jsonify.make_json_response({}) return jsonify.make_json_response({})
@site.route('/photo/<photo_id>/refresh_metadata', methods=['POST'])
def post_photo_refresh_metadata(photo_id):
response = post_photo_refresh_metadata_core(photo_ids=photo_id)
return response
@site.route('/batch/photos/refresh_metadata', methods=['POST'])
@decorators.required_fields(['photo_ids'], forbid_whitespace=True)
def post_batch_photos_refresh_metadata():
response = post_photo_refresh_metadata_core(photo_ids=request.form['photo_ids'])
return response
# Clipboard ######################################################################################## # Clipboard ########################################################################################
@site.route('/clipboard') @site.route('/clipboard')