From dd347d7c173e0385ce35cc51452ec6d38fd3b086 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 27 May 2021 23:08:49 +0100 Subject: [PATCH 1/4] Custom emoji endpoint --- daemon.py | 19 +++++++++++++++---- metadata.py | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/daemon.py b/daemon.py index b939ab283..6c4b31b3e 100644 --- a/daemon.py +++ b/daemon.py @@ -29,6 +29,7 @@ from mastoapiv1 import getMastApiV1Id from mastoapiv1 import getNicknameFromMastoApiV1Id from metadata import metaDataInstance from metadata import metaDataNodeInfo +from metadata import metadataCustomEmoji from pgp import getEmailAddress from pgp import setEmailAddress from pgp import getPGPpubKey @@ -867,7 +868,8 @@ class PubServer(BaseHTTPRequestHandler): translate: {}, registration: bool, systemLanguage: str, - projectVersion: str) -> bool: + projectVersion: str, + customEmoji: []) -> bool: """This is a vestigil mastodon API for the purpose of returning an empty result to sites like https://mastopeek.app-dist.eu @@ -944,6 +946,9 @@ class PubServer(BaseHTTPRequestHandler): elif path.startswith('/api/v1/timelines'): sendJson = [] sendJsonStr = 'masto API timelines sent' + elif path.startswith('/api/v1/custom_emojis'): + sendJson = customEmoji + sendJsonStr = 'masto API custom emojis sent' adminNickname = getConfigParam(baseDir, 'admin') if adminNickname and path == '/api/v1/instance': @@ -1019,12 +1024,13 @@ class PubServer(BaseHTTPRequestHandler): translate: {}, registration: bool, systemLanguage: str, - projectVersion: str) -> bool: + projectVersion: str, + customEmoji: []) -> bool: return self._mastoApiV1(path, callingDomain, authorized, httpPrefix, baseDir, nickname, domain, domainFull, onionDomain, i2pDomain, translate, registration, systemLanguage, - projectVersion) + projectVersion, customEmoji) def _nodeinfo(self, callingDomain: str) -> bool: if not self.path.startswith('/nodeinfo/2.0'): @@ -10757,7 +10763,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.translate, self.server.registration, self.server.systemLanguage, - self.server.projectVersion): + self.server.projectVersion, + self.server.customEmoji): return self._benchmarkGETtimings(GETstartTime, GETtimings, @@ -15113,6 +15120,10 @@ def runDaemon(city: str, # cache to store css files httpd.cssCache = {} + # get the list of custom emoji, for use by the mastodon api + httpd.customEmoji = \ + metadataCustomEmoji(baseDir, httpPrefix, httpd.domainFull) + # whether to enable broch mode, which locks down the instance setBrochMode(baseDir, httpd.domainFull, brochMode) diff --git a/metadata.py b/metadata.py index c8bee73c1..2c20778ae 100644 --- a/metadata.py +++ b/metadata.py @@ -128,3 +128,28 @@ def metaDataInstance(instanceTitle: str, } return instance + + +def metadataCustomEmoji(baseDir: str, + httpPrefix: str, domainFull: str) -> {}: + """Returns the custom emoji + Endpoint /api/v1/custom_emojis + See https://docs.joinmastodon.org/methods/instance/custom_emojis + """ + result = [] + emojisUrl = httpPrefix + '://' + domainFull + '/emoji' + for subdir, dirs, files in os.walk(baseDir + '/emoji'): + for f in files: + if f.startswith('1F') or f.startswith('00'): + continue + if not f.endswith('.png'): + continue + url = os.path.join(emojisUrl, f) + result.append({ + "shortcode": f.replace('.png', ''), + "url": url, + "static_url": url, + "visible_in_picker": True + }) + break + return result From fab332f780f45aa780b37384712cc071012876b1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 27 May 2021 23:15:25 +0100 Subject: [PATCH 2/4] Exclude E0 --- metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.py b/metadata.py index 2c20778ae..73c38cb8e 100644 --- a/metadata.py +++ b/metadata.py @@ -140,7 +140,7 @@ def metadataCustomEmoji(baseDir: str, emojisUrl = httpPrefix + '://' + domainFull + '/emoji' for subdir, dirs, files in os.walk(baseDir + '/emoji'): for f in files: - if f.startswith('1F') or f.startswith('00'): + if f.startswith('1F') or f.startswith('00') or f.startswith('E0'): continue if not f.endswith('.png'): continue From 10cebf49d9a2bf45128c0acbed93876c5c535a15 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 27 May 2021 23:19:52 +0100 Subject: [PATCH 3/4] Better exclusion of default emoji --- metadata.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/metadata.py b/metadata.py index 73c38cb8e..e073692c3 100644 --- a/metadata.py +++ b/metadata.py @@ -140,7 +140,9 @@ def metadataCustomEmoji(baseDir: str, emojisUrl = httpPrefix + '://' + domainFull + '/emoji' for subdir, dirs, files in os.walk(baseDir + '/emoji'): for f in files: - if f.startswith('1F') or f.startswith('00') or f.startswith('E0'): + if len(f) < 3: + continue + if f[0].isdigit() or f[1].isdigit(): continue if not f.endswith('.png'): continue From acd8aaa50fe568e46df0bd46c5077830a35245b9 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 28 May 2021 10:00:33 +0100 Subject: [PATCH 4/4] Retire organization schemas --- orgs/instance.txt | 21 ---------- orgs/protest.txt | 98 -------------------------------------------- orgs/publication.txt | 58 -------------------------- 3 files changed, 177 deletions(-) delete mode 100644 orgs/instance.txt delete mode 100644 orgs/protest.txt delete mode 100644 orgs/publication.txt diff --git a/orgs/instance.txt b/orgs/instance.txt deleted file mode 100644 index a797b348d..000000000 --- a/orgs/instance.txt +++ /dev/null @@ -1,21 +0,0 @@ -{ - "Administrator": { - description: "Administrator of the instance", - iconUrl: "", - members: [], - team: { - "Moderator": { - description: "Can moderate posts, suspend members and block instances", - pitch: "", - iconUrl: "", - members: [] - }, - "Delegator": { - description: "Can delegate roles", - pitch: "", - iconUrl: "", - members: [] - } - } - } -} diff --git a/orgs/protest.txt b/orgs/protest.txt deleted file mode 100644 index 19efc83e1..000000000 --- a/orgs/protest.txt +++ /dev/null @@ -1,98 +0,0 @@ -{ - "General meeting": { - "Safety": { - "Legal team": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Legal observers": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Jail support": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Medics team": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Recovery team": { - description: "", - pitch: "", - iconUrl: "", - members: [] - } - } - }, - "Organizing": { - "Logistics": { - "Police spokesperson": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Self defense team": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Spotters": { - description: "", - pitch: "", - iconUrl: "", - members: [] - } - }, - "Message": { - "Media spokesperson": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Writer": { - description: "", - pitch: "", - iconUrl: "", - members: [] - } - }, - "Mobilization": { - "Meme artist": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Banner visuals": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Social media": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Video producer": { - description: "", - pitch: "", - iconUrl: "", - members: [] - } - } - } -} diff --git a/orgs/publication.txt b/orgs/publication.txt deleted file mode 100644 index 511400222..000000000 --- a/orgs/publication.txt +++ /dev/null @@ -1,58 +0,0 @@ -{ - "Chief Editor": { - description: "", - pitch: "", - iconUrl: "", - members: [], - team: { - "Creative": { - "Photographer": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Layout editor": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Writers team": { - description: "", - pitch: "", - iconUrl: "", - members: [] - } - }, - "Copy": { - "Proof reader": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Fact checker": { - description: "", - pitch: "", - iconUrl: "", - members: [] - } - }, - "Publicity": { - "Website designer": { - description: "", - pitch: "", - iconUrl: "", - members: [] - }, - "Social media publicist": { - description: "", - pitch: "", - iconUrl: "", - members: [] - } - } - } - } -}