Use item ID as share index

main2
Bob Mottram 2019-11-03 09:48:01 +00:00
parent ee73e5866c
commit 655b3f2163
2 changed files with 10 additions and 8 deletions

View File

@ -22,7 +22,7 @@ from utils import loadJson
from utils import saveJson from utils import saveJson
from media import removeMetaData from media import removeMetaData
def getValidItemID(displayName: str) -> str: def getValidSharedItemID(displayName: str) -> str:
"""Removes any invalid characters from the display name to """Removes any invalid characters from the display name to
produce an item ID produce an item ID
""" """
@ -36,7 +36,7 @@ def removeShare(baseDir: str,nickname: str,domain: str, \
if os.path.isfile(sharesFilename): if os.path.isfile(sharesFilename):
sharesJson=loadJson(sharesFilename) sharesJson=loadJson(sharesFilename)
itemID=getValidItemID(displayName) itemID=getValidSharedItemID(displayName)
if sharesJson.get(itemID): if sharesJson.get(itemID):
# remove any image for the item # remove any image for the item
itemIDfile=baseDir+'/sharefiles/'+itemID itemIDfile=baseDir+'/sharefiles/'+itemID
@ -85,7 +85,7 @@ def addShare(baseDir: str, \
if 'year' in durationList[1]: if 'year' in durationList[1]:
durationSec=published+(int(durationList[0])*60*60*24*365) durationSec=published+(int(durationList[0])*60*60*24*365)
itemID=getValidItemID(displayName) itemID=getValidSharedItemID(displayName)
# has an image for this share been uploaded? # has an image for this share been uploaded?
imageUrl=None imageUrl=None

View File

@ -51,6 +51,7 @@ from config import getConfigParam
from skills import getSkills from skills import getSkills
from cache import getPersonFromCache from cache import getPersonFromCache
from cache import storePersonInCache from cache import storePersonInCache
from shares import getValidSharedItemID
def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avatarUrl: str,personCache: {},force=False) -> str: def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avatarUrl: str,personCache: {},force=False) -> str:
"""Updates the cached avatar for the given actor """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: def htmlRemoveSharedItem(translate: {},baseDir: str,actor: str,shareName: str) -> str:
"""Shows a screen asking to confirm the removal of a shared item """Shows a screen asking to confirm the removal of a shared item
""" """
itemID=getValidSharedItemID(shareName)
nickname=getNicknameFromActor(actor) nickname=getNicknameFromActor(actor)
domain,port=getDomainFromActor(actor) domain,port=getDomainFromActor(actor)
sharesFile=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json' sharesFile=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json'
@ -2643,13 +2645,13 @@ def htmlRemoveSharedItem(translate: {},baseDir: str,actor: str,shareName: str) -
if not sharesJson: if not sharesJson:
print('ERROR: unable to load shares.json') print('ERROR: unable to load shares.json')
return None return None
if not sharesJson.get(shareName): if not sharesJson.get(itemID):
print('ERROR: share named "'+shareName+'" is not in '+sharesFile) print('ERROR: share named "'+itemID+'" is not in '+sharesFile)
return None return None
sharedItemDisplayName=sharesJson[shareName]['displayName'] sharedItemDisplayName=sharesJson[itemID]['displayName']
sharedItemImageUrl=None sharedItemImageUrl=None
if sharesJson[shareName].get('imageUrl'): if sharesJson[itemID].get('imageUrl'):
sharedItemImageUrl=sharesJson[shareName]['imageUrl'] sharedItemImageUrl=sharesJson[itemID]['imageUrl']
if os.path.isfile(baseDir+'/img/shares-background.png'): if os.path.isfile(baseDir+'/img/shares-background.png'):
if not os.path.isfile(baseDir+'/accounts/shares-background.png'): if not os.path.isfile(baseDir+'/accounts/shares-background.png'):