Only show libretranslate options to admin account

main
Bob Mottram 2021-07-19 20:58:06 +01:00
parent 79b356a374
commit 3136f428d3
3 changed files with 32 additions and 12 deletions

View File

@ -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,

View File

@ -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:

View File

@ -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 += ' </div></details>\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 += \