main
Bob Mottram 2020-09-22 16:59:47 +01:00
parent ee216a805b
commit cc6e1e2cfc
1 changed files with 23 additions and 60 deletions

View File

@ -54,18 +54,11 @@ def removeShare(baseDir: str, nickname: str, domain: str,
# remove any image for the item # remove any image for the item
itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID
if sharesJson[itemID]['imageUrl']: if sharesJson[itemID]['imageUrl']:
if sharesJson[itemID]['imageUrl'].endswith('.png'): formats = ('png', 'jpg', 'gif', 'webp')
if os.path.isfile(itemIDfile + '.png'): for ext in formats:
os.remove(itemIDfile + '.png') if sharesJson[itemID]['imageUrl'].endswith('.' + ext):
if sharesJson[itemID]['imageUrl'].endswith('.jpg'): if os.path.isfile(itemIDfile + '.' + ext):
if os.path.isfile(itemIDfile + '.jpg'): os.remove(itemIDfile + '.' + ext)
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')
# remove the item itself # remove the item itself
del sharesJson[itemID] del sharesJson[itemID]
saveJson(sharesJson, sharesFilename) saveJson(sharesJson, sharesFilename)
@ -115,18 +108,11 @@ def addShare(baseDir: str,
if not imageFilename: if not imageFilename:
sharesImageFilename = \ sharesImageFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + '/upload' baseDir + '/accounts/' + nickname + '@' + domain + '/upload'
if os.path.isfile(sharesImageFilename + '.png'): formats = ('png', 'jpg', 'gif', 'webp')
imageFilename = sharesImageFilename + '.png' for ext in formats:
moveImage = True if os.path.isfile(sharesImageFilename + '.' + ext):
elif os.path.isfile(sharesImageFilename + '.jpg'): imageFilename = sharesImageFilename + '.' + ext
imageFilename = sharesImageFilename + '.jpg' moveImage = True
moveImage = True
elif os.path.isfile(sharesImageFilename + '.gif'):
imageFilename = sharesImageFilename + '.gif'
moveImage = True
elif os.path.isfile(sharesImageFilename + '.webp'):
imageFilename = sharesImageFilename + '.webp'
moveImage = True
domainFull = domain domainFull = domain
if port: if port:
@ -142,34 +128,15 @@ def addShare(baseDir: str,
if not os.path.isdir(baseDir + '/sharefiles/' + nickname): if not os.path.isdir(baseDir + '/sharefiles/' + nickname):
os.mkdir(baseDir + '/sharefiles/' + nickname) os.mkdir(baseDir + '/sharefiles/' + nickname)
itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID
if imageFilename.endswith('.png'): formats = ('png', 'jpg', 'gif', 'webp')
removeMetaData(imageFilename, itemIDfile + '.png') for ext in formats:
if moveImage: if imageFilename.endswith('.' + ext):
os.remove(imageFilename) removeMetaData(imageFilename, itemIDfile + '.' + ext)
imageUrl = \ if moveImage:
httpPrefix + '://' + domainFull + \ os.remove(imageFilename)
'/sharefiles/' + nickname + '/' + itemID + '.png' imageUrl = \
elif imageFilename.endswith('.jpg'): httpPrefix + '://' + domainFull + \
removeMetaData(imageFilename, itemIDfile + '.jpg') '/sharefiles/' + nickname + '/' + itemID + '.' + ext
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'
sharesJson[itemID] = { sharesJson[itemID] = {
"displayName": displayName, "displayName": displayName,
@ -235,14 +202,10 @@ def expireSharesForAccount(baseDir: str, nickname: str, domain: str) -> None:
# remove any associated images # remove any associated images
itemIDfile = \ itemIDfile = \
baseDir + '/sharefiles/' + nickname + '/' + itemID baseDir + '/sharefiles/' + nickname + '/' + itemID
if os.path.isfile(itemIDfile + '.png'): formats = ('png', 'jpg', 'gif', 'webp')
os.remove(itemIDfile + '.png') for ext in formats:
if os.path.isfile(itemIDfile + '.jpg'): if os.path.isfile(itemIDfile + '.' + ext):
os.remove(itemIDfile + '.jpg') os.remove(itemIDfile + '.' + ext)
if os.path.isfile(itemIDfile + '.gif'):
os.remove(itemIDfile + '.gif')
if os.path.isfile(itemIDfile + '.webp'):
os.remove(itemIDfile + '.webp')
saveJson(sharesJson, sharesFilename) saveJson(sharesJson, sharesFilename)