From 3136f428d387e12b3bb10be84928fc52bf3197d6 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 19 Jul 2021 20:58:06 +0100 Subject: [PATCH] Only show libretranslate options to admin account --- daemon.py | 8 +++++--- epicyon.py | 15 +++++++++++++++ webapp_profile.py | 21 ++++++++++++--------- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/daemon.py b/daemon.py index f724ef4a1..a331289f3 100644 --- a/daemon.py +++ b/daemon.py @@ -4438,9 +4438,11 @@ class PubServer(BaseHTTPRequestHandler): if fields['libretranslateUrl'] != \ currLibretranslateUrl: ltUrl = fields['libretranslateUrl'] - setConfigParam(baseDir, - 'libretranslateUrl', - ltUrl) + if '://' in ltUrl and \ + '.' in ltUrl: + setConfigParam(baseDir, + 'libretranslateUrl', + ltUrl) else: if currLibretranslateUrl: setConfigParam(baseDir, diff --git a/epicyon.py b/epicyon.py index 59364581f..7ce570793 100644 --- a/epicyon.py +++ b/epicyon.py @@ -110,6 +110,13 @@ parser = argparse.ArgumentParser(description='ActivityPub Server') parser.add_argument('--userAgentBlocks', type=str, default=None, help='List of blocked user agents, separated by commas') +parser.add_argument('--libretranslate', dest='libretranslateUrl', type=str, + default=None, + help='URL for LibreTranslate service') +parser.add_argument('--libretranslateApiKey', + dest='libretranslateApiKey', type=str, + default=None, + help='API key for LibreTranslate service') parser.add_argument('-n', '--nickname', dest='nickname', type=str, default=None, help='Nickname of the account to use') @@ -606,6 +613,14 @@ if baseDir.endswith('/'): print("--path option should not end with '/'") sys.exit() +# automatic translations +if args.libretranslateUrl: + if '://' in args.libretranslateUrl and \ + '.' in args.libretranslateUrl: + setConfigParam(baseDir, 'libretranslateUrl', args.libretranslateUrl) +if args.libretranslateApiKey: + setConfigParam(baseDir, 'libretranslateApiKey', args.libretranslateApiKey) + if args.posts: if '@' not in args.posts: if '/users/' in args.posts: diff --git a/webapp_profile.py b/webapp_profile.py index 4e76e9259..e43d7ea4d 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -1088,7 +1088,7 @@ def _htmlEditProfileInstance(baseDir: str, translate: {}, peertubeInstances: [], mediaInstanceStr: str, blogsInstanceStr: str, - newsInstanceStr: str) -> (str, str, str): + newsInstanceStr: str) -> (str, str, str, str): """Edit profile instance settings """ imageFormats = getImageFormats() @@ -1324,7 +1324,14 @@ def _htmlEditProfileInstance(baseDir: str, translate: {}, YTReplacementDomain + '">\n' peertubeStr += ' \n' - return instanceStr, roleAssignStr, peertubeStr + libretranslateUrl = getConfigParam(baseDir, 'libretranslateUrl') + libretranslateApiKey = getConfigParam(baseDir, 'libretranslateApiKey') + libretranslateStr = \ + _htmlEditProfileLibreTranslate(translate, + libretranslateUrl, + libretranslateApiKey) + + return instanceStr, roleAssignStr, peertubeStr, libretranslateStr def _htmlEditProfileDangerZone(translate: {}) -> str: @@ -2049,6 +2056,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, instanceStr = '' roleAssignStr = '' peertubeStr = '' + libretranslateStr = '' adminNickname = getConfigParam(baseDir, 'admin') @@ -2058,7 +2066,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, if adminNickname: if path.startswith('/users/' + adminNickname + '/'): - instanceStr, roleAssignStr, peertubeStr = \ + instanceStr, roleAssignStr, peertubeStr, libretranslateStr = \ _htmlEditProfileInstance(baseDir, translate, peertubeInstances, mediaInstanceStr, @@ -2122,12 +2130,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, editProfileForm += _htmlEditProfileChangePassword(translate) # automatic translations - libretranslateUrl = getConfigParam(baseDir, 'libretranslateUrl') - libretranslateApiKey = getConfigParam(baseDir, 'libretranslateApiKey') - editProfileForm += \ - _htmlEditProfileLibreTranslate(translate, - libretranslateUrl, - libretranslateApiKey) + editProfileForm += libretranslateStr # Filtering and blocking section editProfileForm += \