From 655b3f21636ad237b6418427f797bdf09fef99a3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 3 Nov 2019 09:48:01 +0000 Subject: [PATCH] Use item ID as share index --- shares.py | 6 +++--- webinterface.py | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/shares.py b/shares.py index cacff618b..6163fbd68 100644 --- a/shares.py +++ b/shares.py @@ -22,7 +22,7 @@ from utils import loadJson from utils import saveJson from media import removeMetaData -def getValidItemID(displayName: str) -> str: +def getValidSharedItemID(displayName: str) -> str: """Removes any invalid characters from the display name to produce an item ID """ @@ -36,7 +36,7 @@ def removeShare(baseDir: str,nickname: str,domain: str, \ if os.path.isfile(sharesFilename): sharesJson=loadJson(sharesFilename) - itemID=getValidItemID(displayName) + itemID=getValidSharedItemID(displayName) if sharesJson.get(itemID): # remove any image for the item itemIDfile=baseDir+'/sharefiles/'+itemID @@ -85,7 +85,7 @@ def addShare(baseDir: str, \ if 'year' in durationList[1]: durationSec=published+(int(durationList[0])*60*60*24*365) - itemID=getValidItemID(displayName) + itemID=getValidSharedItemID(displayName) # has an image for this share been uploaded? imageUrl=None diff --git a/webinterface.py b/webinterface.py index a22d1a82e..48a9469bf 100644 --- a/webinterface.py +++ b/webinterface.py @@ -51,6 +51,7 @@ from config import getConfigParam from skills import getSkills from cache import getPersonFromCache from cache import storePersonInCache +from shares import getValidSharedItemID def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avatarUrl: str,personCache: {},force=False) -> str: """Updates the cached avatar for the given actor @@ -2633,6 +2634,7 @@ def htmlPostReplies(translate: {},baseDir: str, \ def htmlRemoveSharedItem(translate: {},baseDir: str,actor: str,shareName: str) -> str: """Shows a screen asking to confirm the removal of a shared item """ + itemID=getValidSharedItemID(shareName) nickname=getNicknameFromActor(actor) domain,port=getDomainFromActor(actor) sharesFile=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json' @@ -2643,13 +2645,13 @@ def htmlRemoveSharedItem(translate: {},baseDir: str,actor: str,shareName: str) - if not sharesJson: print('ERROR: unable to load shares.json') return None - if not sharesJson.get(shareName): - print('ERROR: share named "'+shareName+'" is not in '+sharesFile) + if not sharesJson.get(itemID): + print('ERROR: share named "'+itemID+'" is not in '+sharesFile) return None - sharedItemDisplayName=sharesJson[shareName]['displayName'] + sharedItemDisplayName=sharesJson[itemID]['displayName'] sharedItemImageUrl=None - if sharesJson[shareName].get('imageUrl'): - sharedItemImageUrl=sharesJson[shareName]['imageUrl'] + if sharesJson[itemID].get('imageUrl'): + sharedItemImageUrl=sharesJson[itemID]['imageUrl'] if os.path.isfile(baseDir+'/img/shares-background.png'): if not os.path.isfile(baseDir+'/accounts/shares-background.png'):