mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Improve mass delete from Cloudinary
This commit is contained in:
parent
231de3a7a5
commit
b1516e9963
2 changed files with 15 additions and 6 deletions
|
@ -1259,6 +1259,9 @@ class DataFactory(object):
|
||||||
'GROUP BY rating_key' % where
|
'GROUP BY rating_key' % where
|
||||||
results = monitor_db.select(query, args=args)
|
results = monitor_db.select(query, args=args)
|
||||||
|
|
||||||
|
if delete_all:
|
||||||
|
helpers.delete_from_cloudinary(delete_all=delete_all)
|
||||||
|
else:
|
||||||
for cloudinary_info in results:
|
for cloudinary_info in results:
|
||||||
helpers.delete_from_cloudinary(rating_key=cloudinary_info['rating_key'])
|
helpers.delete_from_cloudinary(rating_key=cloudinary_info['rating_key'])
|
||||||
|
|
||||||
|
|
|
@ -818,7 +818,7 @@ def upload_to_cloudinary(img_data, img_title='', rating_key='', fallback=''):
|
||||||
try:
|
try:
|
||||||
response = upload('data:image/png;base64,{}'.format(base64.b64encode(img_data)),
|
response = upload('data:image/png;base64,{}'.format(base64.b64encode(img_data)),
|
||||||
public_id='{}_{}'.format(fallback, rating_key),
|
public_id='{}_{}'.format(fallback, rating_key),
|
||||||
tags=[fallback, str(rating_key)],
|
tags=['tautulli', fallback, str(rating_key)],
|
||||||
context={'title': img_title.encode('utf-8'), 'rating_key': str(rating_key), 'fallback': fallback})
|
context={'title': img_title.encode('utf-8'), 'rating_key': str(rating_key), 'fallback': fallback})
|
||||||
logger.debug(u"Tautulli Helpers :: Image '{}' ({}) uploaded to Cloudinary.".format(img_title, fallback))
|
logger.debug(u"Tautulli Helpers :: Image '{}' ({}) uploaded to Cloudinary.".format(img_title, fallback))
|
||||||
img_url = response.get('url', '')
|
img_url = response.get('url', '')
|
||||||
|
@ -828,7 +828,7 @@ def upload_to_cloudinary(img_data, img_title='', rating_key='', fallback=''):
|
||||||
return img_url
|
return img_url
|
||||||
|
|
||||||
|
|
||||||
def delete_from_cloudinary(rating_key):
|
def delete_from_cloudinary(rating_key=None, delete_all=False):
|
||||||
""" Deletes an image from Cloudinary """
|
""" Deletes an image from Cloudinary """
|
||||||
if not plexpy.CONFIG.CLOUDINARY_CLOUD_NAME or not plexpy.CONFIG.CLOUDINARY_API_KEY or not plexpy.CONFIG.CLOUDINARY_API_SECRET:
|
if not plexpy.CONFIG.CLOUDINARY_CLOUD_NAME or not plexpy.CONFIG.CLOUDINARY_API_KEY or not plexpy.CONFIG.CLOUDINARY_API_SECRET:
|
||||||
logger.error(u"Tautulli Helpers :: Cannot delete image from Cloudinary. Cloudinary settings not specified in the settings.")
|
logger.error(u"Tautulli Helpers :: Cannot delete image from Cloudinary. Cloudinary settings not specified in the settings.")
|
||||||
|
@ -840,9 +840,15 @@ def delete_from_cloudinary(rating_key):
|
||||||
api_secret=plexpy.CONFIG.CLOUDINARY_API_SECRET
|
api_secret=plexpy.CONFIG.CLOUDINARY_API_SECRET
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if delete_all:
|
||||||
|
delete_resources_by_tag('tautulli')
|
||||||
|
logger.debug(u"Tautulli Helpers :: Deleted all images from Cloudinary.")
|
||||||
|
elif rating_key:
|
||||||
delete_resources_by_tag(str(rating_key))
|
delete_resources_by_tag(str(rating_key))
|
||||||
|
|
||||||
logger.debug(u"Tautulli Helpers :: Deleted images from Cloudinary with rating_key {}.".format(rating_key))
|
logger.debug(u"Tautulli Helpers :: Deleted images from Cloudinary with rating_key {}.".format(rating_key))
|
||||||
|
else:
|
||||||
|
logger.debug(u"Tautulli Helpers :: Failed to deleted images from Cloudinary: No rating_key provided.")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue