Support webp format share images

main
Bob Mottram 2020-09-22 16:55:21 +01:00
parent 17aeb32565
commit ee216a805b
1 changed files with 18 additions and 3 deletions

View File

@ -63,6 +63,9 @@ def removeShare(baseDir: str, nickname: str, domain: str,
if sharesJson[itemID]['imageUrl'].endswith('.gif'): if sharesJson[itemID]['imageUrl'].endswith('.gif'):
if os.path.isfile(itemIDfile + '.gif'): if os.path.isfile(itemIDfile + '.gif'):
os.remove(itemIDfile + '.gif') os.remove(itemIDfile + '.gif')
if sharesJson[itemID]['imageUrl'].endswith('.webp'):
if os.path.isfile(itemIDfile + '.webp'):
os.remove(itemIDfile + '.webp')
# remove the item itself # remove the item itself
del sharesJson[itemID] del sharesJson[itemID]
saveJson(sharesJson, sharesFilename) saveJson(sharesJson, sharesFilename)
@ -76,7 +79,7 @@ def addShare(baseDir: str,
displayName: str, summary: str, imageFilename: str, displayName: str, summary: str, imageFilename: str,
itemType: str, itemCategory: str, location: str, itemType: str, itemCategory: str, location: str,
duration: str, debug: bool) -> None: duration: str, debug: bool) -> None:
"""Updates the likes collection within a post """Adds a new share
""" """
sharesFilename = baseDir + '/accounts/' + \ sharesFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/shares.json' nickname + '@' + domain + '/shares.json'
@ -121,6 +124,9 @@ def addShare(baseDir: str,
elif os.path.isfile(sharesImageFilename + '.gif'): elif os.path.isfile(sharesImageFilename + '.gif'):
imageFilename = sharesImageFilename + '.gif' imageFilename = sharesImageFilename + '.gif'
moveImage = True moveImage = True
elif os.path.isfile(sharesImageFilename + '.webp'):
imageFilename = sharesImageFilename + '.webp'
moveImage = True
domainFull = domain domainFull = domain
if port: if port:
@ -143,20 +149,27 @@ def addShare(baseDir: str,
imageUrl = \ imageUrl = \
httpPrefix + '://' + domainFull + \ httpPrefix + '://' + domainFull + \
'/sharefiles/' + nickname + '/' + itemID + '.png' '/sharefiles/' + nickname + '/' + itemID + '.png'
if imageFilename.endswith('.jpg'): elif imageFilename.endswith('.jpg'):
removeMetaData(imageFilename, itemIDfile + '.jpg') removeMetaData(imageFilename, itemIDfile + '.jpg')
if moveImage: if moveImage:
os.remove(imageFilename) os.remove(imageFilename)
imageUrl = \ imageUrl = \
httpPrefix + '://' + domainFull + \ httpPrefix + '://' + domainFull + \
'/sharefiles/' + nickname + '/' + itemID + '.jpg' '/sharefiles/' + nickname + '/' + itemID + '.jpg'
if imageFilename.endswith('.gif'): elif imageFilename.endswith('.gif'):
removeMetaData(imageFilename, itemIDfile + '.gif') removeMetaData(imageFilename, itemIDfile + '.gif')
if moveImage: if moveImage:
os.remove(imageFilename) os.remove(imageFilename)
imageUrl = \ imageUrl = \
httpPrefix + '://' + domainFull + \ httpPrefix + '://' + domainFull + \
'/sharefiles/' + nickname + '/' + itemID + '.gif' '/sharefiles/' + nickname + '/' + itemID + '.gif'
elif imageFilename.endswith('.webp'):
removeMetaData(imageFilename, itemIDfile + '.webp')
if moveImage:
os.remove(imageFilename)
imageUrl = \
httpPrefix + '://' + domainFull + \
'/sharefiles/' + nickname + '/' + itemID + '.webp'
sharesJson[itemID] = { sharesJson[itemID] = {
"displayName": displayName, "displayName": displayName,
@ -228,6 +241,8 @@ def expireSharesForAccount(baseDir: str, nickname: str, domain: str) -> None:
os.remove(itemIDfile + '.jpg') os.remove(itemIDfile + '.jpg')
if os.path.isfile(itemIDfile + '.gif'): if os.path.isfile(itemIDfile + '.gif'):
os.remove(itemIDfile + '.gif') os.remove(itemIDfile + '.gif')
if os.path.isfile(itemIDfile + '.webp'):
os.remove(itemIDfile + '.webp')
saveJson(sharesJson, sharesFilename) saveJson(sharesJson, sharesFilename)