From 3d16d93d869da20a18c13960c5cddeddcad019ee Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 24 Dec 2020 11:42:23 +0000 Subject: [PATCH] Show list of peertube instances on admin profile --- daemon.py | 25 ++++++++++++++++++++++++- translations/ar.json | 4 +++- translations/ca.json | 4 +++- translations/cy.json | 4 +++- translations/de.json | 4 +++- translations/en.json | 4 +++- translations/es.json | 4 +++- translations/fr.json | 4 +++- translations/ga.json | 4 +++- translations/hi.json | 4 +++- translations/it.json | 4 +++- translations/ja.json | 4 +++- translations/oc.json | 4 +++- translations/pt.json | 4 +++- translations/ru.json | 4 +++- translations/zh.json | 4 +++- webapp_media.py | 23 ++++++++++++++++++----- webapp_profile.py | 17 ++++++++++++++++- 18 files changed, 103 insertions(+), 22 deletions(-) diff --git a/daemon.py b/daemon.py index 35d59565..17572f92 100644 --- a/daemon.py +++ b/daemon.py @@ -4565,6 +4565,27 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(allowedInstancesFilename): os.remove(allowedInstancesFilename) + # save peertube instances list + peertubeInstancesFilename = \ + baseDir + '/accounts/peertube.txt' + if fields.get('ptInstances'): + self.server.peertubeInstances.clear() + with open(peertubeInstancesFilename, 'w+') as aFile: + aFile.write(fields['ptInstances']) + ptInstancesList = fields['ptInstances'].split('\n') + if ptInstancesList: + for url in ptInstancesList: + url = url.strip() + if not url: + continue + if url in self.server.peertubeInstances: + continue + self.server.peertubeInstances.append(url) + else: + if os.path.isfile(peertubeInstancesFilename): + os.remove(peertubeInstancesFilename) + self.server.peertubeInstances.clear() + # save git project names list gitProjectsFilename = \ baseDir + '/accounts/' + \ @@ -9381,6 +9402,7 @@ class PubServer(BaseHTTPRequestHandler): """Show the edit profile screen """ if '/users/' in path and path.endswith('/editprofile'): + peertubeInstances = self.server.peertubeInstances msg = htmlEditProfile(self.server.cssCache, translate, baseDir, @@ -9388,7 +9410,8 @@ class PubServer(BaseHTTPRequestHandler): port, httpPrefix, self.server.defaultTimeline, - self.server.themeName).encode('utf-8') + self.server.themeName, + peertubeInstances).encode('utf-8') if msg: msglen = len(msg) self._set_headers('text/html', msglen, diff --git a/translations/ar.json b/translations/ar.json index 63006762..c0288c1e 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -347,5 +347,7 @@ "Filter out words": "تصفية الكلمات", "Unfilter": "غير مرشح", "Unfilter words": "الكلمات غير المصفاة", - "Show Accounts": "إظهار الحسابات" + "Show Accounts": "إظهار الحسابات", + "Peertube Instances": "مثيلات Peertube", + "Show video previews for the following Peertube sites.": "إظهار معاينات الفيديو لمواقع Peertube التالية." } diff --git a/translations/ca.json b/translations/ca.json index 853f9491..ffc4725d 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -347,5 +347,7 @@ "Filter out words": "Filtra les paraules", "Unfilter": "Sense filtre", "Unfilter words": "Paraules sense filtre", - "Show Accounts": "Mostra comptes" + "Show Accounts": "Mostra comptes", + "Peertube Instances": "Instàncies de Peertube", + "Show video previews for the following Peertube sites.": "Mostra les previsualitzacions de vídeo dels següents llocs de Peertube." } diff --git a/translations/cy.json b/translations/cy.json index eafc25d6..cd659af7 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -347,5 +347,7 @@ "Filter out words": "Hidlo geiriau", "Unfilter": "Di-hid", "Unfilter words": "Geiriau di-hid", - "Show Accounts": "Dangos Cyfrifon" + "Show Accounts": "Dangos Cyfrifon", + "Peertube Instances": "Camau Peertube", + "Show video previews for the following Peertube sites.": "Dangos rhagolygon fideo ar gyfer y safleoedd Peertube canlynol." } diff --git a/translations/de.json b/translations/de.json index 6749671f..e0e757b7 100644 --- a/translations/de.json +++ b/translations/de.json @@ -347,5 +347,7 @@ "Filter out words": "Wörter herausfiltern", "Unfilter": "Filter entfernen", "Unfilter words": "Wörter herausfiltern", - "Show Accounts": "Konten anzeigen" + "Show Accounts": "Konten anzeigen", + "Peertube Instances": "Peertube-Instanzen", + "Show video previews for the following Peertube sites.": "Zeigen Sie eine Videovorschau für die folgenden Peertube-Websites an." } diff --git a/translations/en.json b/translations/en.json index 6f3c3344..6ea42b2c 100644 --- a/translations/en.json +++ b/translations/en.json @@ -347,5 +347,7 @@ "Filter out words": "Filter out words", "Unfilter": "Unfilter", "Unfilter words": "Unfilter words", - "Show Accounts": "Show Accounts" + "Show Accounts": "Show Accounts", + "Peertube Instances": "Peertube Instances", + "Show video previews for the following Peertube sites.": "Show video previews for the following Peertube sites." } diff --git a/translations/es.json b/translations/es.json index dcf167a9..49293f2e 100644 --- a/translations/es.json +++ b/translations/es.json @@ -347,5 +347,7 @@ "Filter out words": "Filtrar palabras", "Unfilter": "Unfilter", "Unfilter words": "Palabras sin filtrar", - "Show Accounts": "Mostrar cuentas" + "Show Accounts": "Mostrar cuentas", + "Peertube Instances": "Instancias de Peertube", + "Show video previews for the following Peertube sites.": "Muestre vistas previas de video para los siguientes sitios de Peertube." } diff --git a/translations/fr.json b/translations/fr.json index 3d8dc2b5..ede3e55f 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -347,5 +347,7 @@ "Filter out words": "Filtrer les mots", "Unfilter": "Non filtrer", "Unfilter words": "Mots non filtrés", - "Show Accounts": "Afficher les comptes" + "Show Accounts": "Afficher les comptes", + "Peertube Instances": "Instances Peertube", + "Show video previews for the following Peertube sites.": "Afficher des aperçus vidéo pour les sites Peertube suivants." } diff --git a/translations/ga.json b/translations/ga.json index a4e46b1f..af58fe18 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -347,5 +347,7 @@ "Filter out words": "Scag focail amach", "Unfilter": "Neamhleithleach", "Unfilter words": "Focail neamhleithleacha", - "Show Accounts": "Taispeáin Cuntais" + "Show Accounts": "Taispeáin Cuntais", + "Peertube Instances": "Imeachtaí Peertube", + "Show video previews for the following Peertube sites.": "Taispeáin réamhamharcanna físe do na suíomhanna Peertube seo a leanas." } diff --git a/translations/hi.json b/translations/hi.json index 49f6d60e..9c0f78c5 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -347,5 +347,7 @@ "Filter out words": "शब्दों को फ़िल्टर करें", "Unfilter": "Unfilter", "Unfilter words": "अनफ़िल्टर शब्द", - "Show Accounts": "खाते दिखाएं" + "Show Accounts": "खाते दिखाएं", + "Peertube Instances": "Peertube उदाहरण", + "Show video previews for the following Peertube sites.": "निम्नलिखित Peertube साइटों के लिए वीडियो पूर्वावलोकन दिखाएं।" } diff --git a/translations/it.json b/translations/it.json index bd4b3db9..36b2fdc1 100644 --- a/translations/it.json +++ b/translations/it.json @@ -347,5 +347,7 @@ "Filter out words": "Filtra le parole", "Unfilter": "Unfilter", "Unfilter words": "Parole non filtrate", - "Show Accounts": "Mostra account" + "Show Accounts": "Mostra account", + "Peertube Instances": "Istanze di Peertube", + "Show video previews for the following Peertube sites.": "Mostra le anteprime dei video per i seguenti siti Peertube." } diff --git a/translations/ja.json b/translations/ja.json index e2029f18..079f7bd0 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -347,5 +347,7 @@ "Filter out words": "単語を除外する", "Unfilter": "フィルタリング解除", "Unfilter words": "単語のフィルタリングを解除する", - "Show Accounts": "アカウントを表示する" + "Show Accounts": "アカウントを表示する", + "Peertube Instances": "Peertubeインスタンス", + "Show video previews for the following Peertube sites.": "次のPeertubeサイトのビデオプレビューを表示します。" } diff --git a/translations/oc.json b/translations/oc.json index 0468223b..2b7e26f7 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -343,5 +343,7 @@ "Filter out words": "Filter out words", "Unfilter": "Unfilter", "Unfilter words": "Unfilter words", - "Show Accounts": "Show Accounts" + "Show Accounts": "Show Accounts", + "Peertube Instances": "Peertube Instances", + "Show video previews for the following Peertube sites.": "Show video previews for the following Peertube sites." } diff --git a/translations/pt.json b/translations/pt.json index b4cb1996..67b1f389 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -347,5 +347,7 @@ "Filter out words": "Filtrar palavras", "Unfilter": "Unfilter", "Unfilter words": "Palavras sem filtro", - "Show Accounts": "Mostrar contas" + "Show Accounts": "Mostrar contas", + "Peertube Instances": "Instâncias Peertube", + "Show video previews for the following Peertube sites.": "Mostrar visualizações de vídeo para os seguintes sites Peertube." } diff --git a/translations/ru.json b/translations/ru.json index a9508339..3236b46f 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -347,5 +347,7 @@ "Filter out words": "Отфильтровать слова", "Unfilter": "Нефильтровать", "Unfilter words": "Не фильтровать слова", - "Show Accounts": "Показать счета" + "Show Accounts": "Показать счета", + "Peertube Instances": "Экземпляры Peertube", + "Show video previews for the following Peertube sites.": "Показать превью видео для следующих сайтов Peertube." } diff --git a/translations/zh.json b/translations/zh.json index 36ea2b05..fe7a8e92 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -347,5 +347,7 @@ "Filter out words": "过滤掉单词", "Unfilter": "取消过滤", "Unfilter words": "未过滤字词", - "Show Accounts": "显示帐户" + "Show Accounts": "显示帐户", + "Peertube Instances": "Peertube实例", + "Show video previews for the following Peertube sites.": "显示以下Peertube网站的视频预览。" } diff --git a/webapp_media.py b/webapp_media.py index dac29749..73ba89ec 100644 --- a/webapp_media.py +++ b/webapp_media.py @@ -20,11 +20,24 @@ def loadPeertubeInstances(baseDir: str, peertubeInstances: []) -> None: if peertubeStr: peertubeStr = peertubeStr.replace('\r', '') peertubeList = peertubeStr.split('\n') - if peertubeList: - for url in peertubeList: - if url in peertubeInstances: - continue - peertubeInstances.append(url) + if not peertubeList: + return + for url in peertubeList: + if url in peertubeInstances: + continue + peertubeInstances.append(url) + + +def savePeertubeInstances(baseDir: str, peertubeInstances: []) -> None: + """Saves peertube instances to file from the given list + """ + peertubeStr = '' + for url in peertubeInstances: + peertubeStr += url.strip() + '\n' + + peertubeInstancesFilename = baseDir + '/accounts/peertube.txt' + with open(peertubeInstancesFilename, 'w+') as fp: + fp.write(peertubeStr) def _addEmbeddedVideoFromSites(translate: {}, content: str, diff --git a/webapp_profile.py b/webapp_profile.py index 3f3ed27d..74f80e42 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -836,7 +836,8 @@ def _htmlProfileShares(actor: str, translate: {}, def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, domain: str, port: int, httpPrefix: str, - defaultTimeline: str, theme: str) -> str: + defaultTimeline: str, theme: str, + peertubeInstances: []) -> str: """Shows the edit profile screen """ imageFormats = getImageFormats() @@ -1427,6 +1428,20 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, ' \n' + editProfileForm += \ + '
\n' + idx = 'Show video previews for the following Peertube sites.' + editProfileForm += \ + '
\n' + peertubeInstancesStr = '' + for url in peertubeInstances: + peertubeInstancesStr += url + '\n' + editProfileForm += \ + ' \n' + editProfileForm += ' \n' editProfileForm += '
\n' editProfileForm += \