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 ########################################################################
@site.route('/photo/<photo_id>/refresh_metadata', methods=['POST'])
@decorators.catch_etiquette_exception
def post_photo_refresh_metadata(photo_id):
'''
Refresh the file metadata.
'''
common.P.caches['photo'].remove(photo_id)
photo = common.P_photo(photo_id, response_type='json')
photo.reload_metadata()
def post_photo_refresh_metadata_core(photo_ids):
if isinstance(photo_ids, str):
photo_ids = etiquette.helpers.comma_space_split(photo_ids)
photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids]
for photo in photos:
common.P.caches['photo'].remove(photo.id)
photo = common.P_photo(photo.id, response_type='json')
photo.reload_metadata(commit=False)
if photo.thumbnail is None:
try:
photo.generate_thumbnail()
photo.generate_thumbnail(commit=False)
except Exception:
traceback.print_exc()
common.P.commit()
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 ########################################################################################
@site.route('/clipboard')