From ee216a805b0db7ac34829e496f67abc9ec91aca7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 22 Sep 2020 16:55:21 +0100 Subject: [PATCH 1/4] Support webp format share images --- shares.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/shares.py b/shares.py index af300d223..407e69738 100644 --- a/shares.py +++ b/shares.py @@ -63,6 +63,9 @@ def removeShare(baseDir: str, nickname: str, domain: str, if sharesJson[itemID]['imageUrl'].endswith('.gif'): if os.path.isfile(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 del sharesJson[itemID] saveJson(sharesJson, sharesFilename) @@ -76,7 +79,7 @@ def addShare(baseDir: str, displayName: str, summary: str, imageFilename: str, itemType: str, itemCategory: str, location: str, duration: str, debug: bool) -> None: - """Updates the likes collection within a post + """Adds a new share """ sharesFilename = baseDir + '/accounts/' + \ nickname + '@' + domain + '/shares.json' @@ -121,6 +124,9 @@ def addShare(baseDir: str, elif os.path.isfile(sharesImageFilename + '.gif'): imageFilename = sharesImageFilename + '.gif' moveImage = True + elif os.path.isfile(sharesImageFilename + '.webp'): + imageFilename = sharesImageFilename + '.webp' + moveImage = True domainFull = domain if port: @@ -143,20 +149,27 @@ def addShare(baseDir: str, imageUrl = \ httpPrefix + '://' + domainFull + \ '/sharefiles/' + nickname + '/' + itemID + '.png' - if imageFilename.endswith('.jpg'): + elif imageFilename.endswith('.jpg'): removeMetaData(imageFilename, itemIDfile + '.jpg') if moveImage: os.remove(imageFilename) imageUrl = \ httpPrefix + '://' + domainFull + \ '/sharefiles/' + nickname + '/' + itemID + '.jpg' - if imageFilename.endswith('.gif'): + elif imageFilename.endswith('.gif'): removeMetaData(imageFilename, itemIDfile + '.gif') if moveImage: os.remove(imageFilename) imageUrl = \ httpPrefix + '://' + domainFull + \ '/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] = { "displayName": displayName, @@ -228,6 +241,8 @@ def expireSharesForAccount(baseDir: str, nickname: str, domain: str) -> None: os.remove(itemIDfile + '.jpg') if os.path.isfile(itemIDfile + '.gif'): os.remove(itemIDfile + '.gif') + if os.path.isfile(itemIDfile + '.webp'): + os.remove(itemIDfile + '.webp') saveJson(sharesJson, sharesFilename) From cc6e1e2cfc333ecd19cb8148583c11b77bdd6a35 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 22 Sep 2020 16:59:47 +0100 Subject: [PATCH 2/4] Tidying --- shares.py | 83 +++++++++++++++---------------------------------------- 1 file changed, 23 insertions(+), 60 deletions(-) diff --git a/shares.py b/shares.py index 407e69738..70138b6dc 100644 --- a/shares.py +++ b/shares.py @@ -54,18 +54,11 @@ def removeShare(baseDir: str, nickname: str, domain: str, # remove any image for the item itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID if sharesJson[itemID]['imageUrl']: - if sharesJson[itemID]['imageUrl'].endswith('.png'): - if os.path.isfile(itemIDfile + '.png'): - os.remove(itemIDfile + '.png') - if sharesJson[itemID]['imageUrl'].endswith('.jpg'): - if os.path.isfile(itemIDfile + '.jpg'): - os.remove(itemIDfile + '.jpg') - if sharesJson[itemID]['imageUrl'].endswith('.gif'): - if os.path.isfile(itemIDfile + '.gif'): - os.remove(itemIDfile + '.gif') - if sharesJson[itemID]['imageUrl'].endswith('.webp'): - if os.path.isfile(itemIDfile + '.webp'): - os.remove(itemIDfile + '.webp') + formats = ('png', 'jpg', 'gif', 'webp') + for ext in formats: + if sharesJson[itemID]['imageUrl'].endswith('.' + ext): + if os.path.isfile(itemIDfile + '.' + ext): + os.remove(itemIDfile + '.' + ext) # remove the item itself del sharesJson[itemID] saveJson(sharesJson, sharesFilename) @@ -115,18 +108,11 @@ def addShare(baseDir: str, if not imageFilename: sharesImageFilename = \ baseDir + '/accounts/' + nickname + '@' + domain + '/upload' - if os.path.isfile(sharesImageFilename + '.png'): - imageFilename = sharesImageFilename + '.png' - moveImage = True - elif os.path.isfile(sharesImageFilename + '.jpg'): - imageFilename = sharesImageFilename + '.jpg' - moveImage = True - elif os.path.isfile(sharesImageFilename + '.gif'): - imageFilename = sharesImageFilename + '.gif' - moveImage = True - elif os.path.isfile(sharesImageFilename + '.webp'): - imageFilename = sharesImageFilename + '.webp' - moveImage = True + formats = ('png', 'jpg', 'gif', 'webp') + for ext in formats: + if os.path.isfile(sharesImageFilename + '.' + ext): + imageFilename = sharesImageFilename + '.' + ext + moveImage = True domainFull = domain if port: @@ -142,34 +128,15 @@ def addShare(baseDir: str, if not os.path.isdir(baseDir + '/sharefiles/' + nickname): os.mkdir(baseDir + '/sharefiles/' + nickname) itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID - if imageFilename.endswith('.png'): - removeMetaData(imageFilename, itemIDfile + '.png') - if moveImage: - os.remove(imageFilename) - imageUrl = \ - httpPrefix + '://' + domainFull + \ - '/sharefiles/' + nickname + '/' + itemID + '.png' - elif imageFilename.endswith('.jpg'): - removeMetaData(imageFilename, itemIDfile + '.jpg') - if moveImage: - os.remove(imageFilename) - imageUrl = \ - httpPrefix + '://' + domainFull + \ - '/sharefiles/' + nickname + '/' + itemID + '.jpg' - elif imageFilename.endswith('.gif'): - removeMetaData(imageFilename, itemIDfile + '.gif') - if moveImage: - os.remove(imageFilename) - imageUrl = \ - httpPrefix + '://' + domainFull + \ - '/sharefiles/' + nickname + '/' + itemID + '.gif' - elif imageFilename.endswith('.webp'): - removeMetaData(imageFilename, itemIDfile + '.webp') - if moveImage: - os.remove(imageFilename) - imageUrl = \ - httpPrefix + '://' + domainFull + \ - '/sharefiles/' + nickname + '/' + itemID + '.webp' + formats = ('png', 'jpg', 'gif', 'webp') + for ext in formats: + if imageFilename.endswith('.' + ext): + removeMetaData(imageFilename, itemIDfile + '.' + ext) + if moveImage: + os.remove(imageFilename) + imageUrl = \ + httpPrefix + '://' + domainFull + \ + '/sharefiles/' + nickname + '/' + itemID + '.' + ext sharesJson[itemID] = { "displayName": displayName, @@ -235,14 +202,10 @@ def expireSharesForAccount(baseDir: str, nickname: str, domain: str) -> None: # remove any associated images itemIDfile = \ baseDir + '/sharefiles/' + nickname + '/' + itemID - if os.path.isfile(itemIDfile + '.png'): - os.remove(itemIDfile + '.png') - if os.path.isfile(itemIDfile + '.jpg'): - os.remove(itemIDfile + '.jpg') - if os.path.isfile(itemIDfile + '.gif'): - os.remove(itemIDfile + '.gif') - if os.path.isfile(itemIDfile + '.webp'): - os.remove(itemIDfile + '.webp') + formats = ('png', 'jpg', 'gif', 'webp') + for ext in formats: + if os.path.isfile(itemIDfile + '.' + ext): + os.remove(itemIDfile + '.' + ext) saveJson(sharesJson, sharesFilename) From cb8afbe716594108866f6b1a90434a48c6273c31 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 22 Sep 2020 17:03:31 +0100 Subject: [PATCH 3/4] Comment --- shares.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shares.py b/shares.py index 70138b6dc..7e68306a7 100644 --- a/shares.py +++ b/shares.py @@ -181,7 +181,7 @@ def expireShares(baseDir: str) -> None: def expireSharesForAccount(baseDir: str, nickname: str, domain: str) -> None: - """Removes expired items from shares + """Removes expired items from shares for a particular account """ handleDomain = domain if ':' in handleDomain: From 640fc95ad032620ccc20472187c80d9811a0755a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 22 Sep 2020 17:05:00 +0100 Subject: [PATCH 4/4] Extra supported image format --- shares.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shares.py b/shares.py index 7e68306a7..be5ca8c32 100644 --- a/shares.py +++ b/shares.py @@ -54,7 +54,7 @@ def removeShare(baseDir: str, nickname: str, domain: str, # remove any image for the item itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID if sharesJson[itemID]['imageUrl']: - formats = ('png', 'jpg', 'gif', 'webp') + formats = ('png', 'jpg', 'gif', 'webp', 'avif') for ext in formats: if sharesJson[itemID]['imageUrl'].endswith('.' + ext): if os.path.isfile(itemIDfile + '.' + ext): @@ -108,7 +108,7 @@ def addShare(baseDir: str, if not imageFilename: sharesImageFilename = \ baseDir + '/accounts/' + nickname + '@' + domain + '/upload' - formats = ('png', 'jpg', 'gif', 'webp') + formats = ('png', 'jpg', 'gif', 'webp', 'avif') for ext in formats: if os.path.isfile(sharesImageFilename + '.' + ext): imageFilename = sharesImageFilename + '.' + ext @@ -128,7 +128,7 @@ def addShare(baseDir: str, if not os.path.isdir(baseDir + '/sharefiles/' + nickname): os.mkdir(baseDir + '/sharefiles/' + nickname) itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID - formats = ('png', 'jpg', 'gif', 'webp') + formats = ('png', 'jpg', 'gif', 'webp', 'avif') for ext in formats: if imageFilename.endswith('.' + ext): removeMetaData(imageFilename, itemIDfile + '.' + ext) @@ -202,7 +202,7 @@ def expireSharesForAccount(baseDir: str, nickname: str, domain: str) -> None: # remove any associated images itemIDfile = \ baseDir + '/sharefiles/' + nickname + '/' + itemID - formats = ('png', 'jpg', 'gif', 'webp') + formats = ('png', 'jpg', 'gif', 'webp', 'avif') for ext in formats: if os.path.isfile(itemIDfile + '.' + ext): os.remove(itemIDfile + '.' + ext)