From dccb22c393fb32170d59a15a72ced60d61927455 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 12 Oct 2021 19:20:40 +0100 Subject: [PATCH] Media path same as mastodon --- daemon.py | 6 +++++- media.py | 2 ++ outbox.py | 4 ++++ tests.py | 4 +++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/daemon.py b/daemon.py index 1eff7d625..45959391b 100644 --- a/daemon.py +++ b/daemon.py @@ -11387,7 +11387,7 @@ class PubServer(BaseHTTPRequestHandler): '/system/accounts/headers/' not in path and \ '/accounts/avatars/' not in path and \ '/accounts/headers/' not in path: - return False + return False if not isImageFile(path): return False if '/system/accounts/avatars/' in path: @@ -13229,6 +13229,10 @@ class PubServer(BaseHTTPRequestHandler): # show media # Note that this comes before the busy flag to avoid conflicts + # replace mastoson-style media path + if '/system/media_attachments/files/' in self.path: + self.path = self.path.replace('/system/media_attachments/files/', + '/media/') if '/media/' in self.path: self._showMedia(callingDomain, self.path, self.server.baseDir, diff --git a/media.py b/media.py index cd4e5fc87..4b2b9d187 100644 --- a/media.py +++ b/media.py @@ -325,6 +325,8 @@ def attachMedia(baseDir: str, httpPrefix: str, createMediaDirs(baseDir, mPath) mediaFilename = baseDir + '/' + mediaPath + mediaPath = \ + mediaPath.replace('media/', 'system/media_attachments/files/', 1) attachmentJson = { 'mediaType': mediaType, 'name': description, diff --git a/outbox.py b/outbox.py index fee962c06..2a596ecee 100644 --- a/outbox.py +++ b/outbox.py @@ -337,6 +337,10 @@ def postMessageToOutbox(session, translate: {}, # change the url of the attachment attach['url'] = \ httpPrefix + '://' + domainFull + '/' + mediaPath + attach['url'] = \ + attach['url'].replace('/media/', + '/system/' + + 'media_attachments/files/') permittedOutboxTypes = ('Create', 'Announce', 'Like', 'Follow', 'Undo', 'Update', 'Add', 'Remove', 'Block', 'Delete', diff --git a/tests.py b/tests.py index 1f796dc0d..0afae44c2 100644 --- a/tests.py +++ b/tests.py @@ -1299,7 +1299,9 @@ def testPostMessageBetweenServers(baseDir: str) -> None: assert attached.get('type') assert attached.get('url') assert attached['mediaType'] == 'image/png' - assert '/media/' in attached['url'] + if not '/system/media_attachments/files/' in attached['url']: + print(attached['url']) + assert '/system/media_attachments/files/' in attached['url'] assert attached['url'].endswith('.png') assert attached.get('width') assert attached.get('height')