From 048086e600ab8318203645c83c94d97df28b57c7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 19 Jan 2020 23:24:23 +0000 Subject: [PATCH] Randomize avatar image and background on edit --- daemon.py | 2 ++ person.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/daemon.py b/daemon.py index 42e13c53..e0133f2c 100644 --- a/daemon.py +++ b/daemon.py @@ -36,6 +36,7 @@ from matrix import getMatrixAddress from matrix import setMatrixAddress from donate import getDonationUrl from donate import setDonationUrl +from person import randomizeActorImages from person import personUpgradeActor from person import activateAccount from person import deactivateAccount @@ -4295,6 +4296,7 @@ class PubServer(BaseHTTPRequestHandler): os.remove(allowedInstancesFilename) # save actor json file within accounts if actorChanged: + randomizeActorImages(actorJson) saveJson(actorJson,actorFilename) # also copy to the actors cache and personCache in memory storePersonInCache(self.server.baseDir, \ diff --git a/person.py b/person.py index d58ee021..7cc78bc2 100644 --- a/person.py +++ b/person.py @@ -12,6 +12,7 @@ import os import fileinput import subprocess import shutil +from random import randint from pathlib import Path from Crypto.PublicKey import RSA from shutil import copyfile @@ -34,7 +35,7 @@ from utils import loadJson from utils import saveJson from auth import createPassword from config import setConfigParam -from config import getConfigParam +from config import getConfigParam def generateRSAKey() -> (str,str): key = RSA.generate(2048) @@ -131,6 +132,14 @@ def accountExists(baseDir: str,nickname: str,domain: str) -> bool: return os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain) or \ os.path.isdir(baseDir+'/deactivated/'+nickname+'@'+domain) +def randomizeActorImages(personJson: {}) -> None: + """Randomizes the filenames for avatar image and background + This causes other instances to update their cached avatar image + """ + personId=personJson['id'] + personJson['icon']['url']=personId+'/avatar'+str(randint(10000000000000,99999999999999))+'.png' + personJson['image']['url']=personId+'/image'+str(randint(10000000000000,99999999999999))+'.png' + def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ httpPrefix: str, saveToFile: bool,password=None) -> (str,str,{},{}): """Returns the private key, public key, actor and webfinger endpoint @@ -192,11 +201,11 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ 'availability': None, 'icon': {'mediaType': 'image/png', 'type': 'Image', - 'url': personId+'/avatar.png'}, + 'url': personId+'/avatar'+str(randint(10000000000000,99999999999999))+'.png'}, 'id': personId, 'image': {'mediaType': 'image/png', 'type': 'Image', - 'url': personId+'/image.png'}, + 'url': personId+'/image'+str(randint(10000000000000,99999999999999))+'.png'}, 'inbox': inboxStr, 'manuallyApprovesFollowers': approveFollowers, 'name': personName,