Upload custom font

main
Bob Mottram 2020-05-26 15:28:58 +01:00
parent bd0daec672
commit c2fe5c3ade
17 changed files with 58 additions and 29 deletions

View File

@ -15,6 +15,7 @@ from functools import partial
# for saving images # for saving images
from hashlib import sha256 from hashlib import sha256
from hashlib import sha1 from hashlib import sha1
from shutil import copyfile
from session import createSession from session import createSession
from webfinger import parseHandle from webfinger import parseHandle
from webfinger import webfingerMeta from webfinger import webfingerMeta
@ -5413,7 +5414,8 @@ class PubServer(BaseHTTPRequestHandler):
# extract each image type # extract each image type
actorChanged = True actorChanged = True
profileMediaTypes = ('avatar', 'image', profileMediaTypes = ('avatar', 'image',
'banner', 'instanceLogo') 'banner', 'instanceLogo',
'customFont')
profileMediaTypesUploaded = {} profileMediaTypesUploaded = {}
for mType in profileMediaTypes: for mType in profileMediaTypes:
if self.server.debug: if self.server.debug:
@ -5435,36 +5437,41 @@ class PubServer(BaseHTTPRequestHandler):
# Note: a .temp extension is used here so that at no # Note: a .temp extension is used here so that at no
# time is an image with metadata publicly exposed, # time is an image with metadata publicly exposed,
# even for a few mS # even for a few mS
if mType != 'instanceLogo': if mType == 'instanceLogo':
filenameBase = \
self.server.baseDir + '/accounts/login.temp'
elif mType == 'customFont':
filenameBase = \
self.server.baseDir + '/fonts/' + \
'/custom.temp'
else:
filenameBase = \ filenameBase = \
self.server.baseDir + '/accounts/' + \ self.server.baseDir + '/accounts/' + \
nickname + '@' + self.server.domain + \ nickname + '@' + self.server.domain + \
'/' + mType + '.temp' '/' + mType + '.temp'
else:
filenameBase = \
self.server.baseDir + '/accounts/login.temp'
filename, attachmentMediaType = \ filename, attachmentMediaType = \
saveMediaInFormPOST(mediaBytes, self.server.debug, saveMediaInFormPOST(mediaBytes, self.server.debug,
filenameBase) filenameBase)
if filename: if filename:
if self.server.debug: print('Profile update POST ' + mType +
print('DEBUG: profile update POST ' + mType + ' media filename is ' + filename)
' media filename is ' + filename)
else: else:
if self.server.debug: print('Profile update, no ' + mType +
print('DEBUG: profile update, no ' + mType + ' media filename in POST')
' media filename in POST')
continue continue
if self.server.debug: if self.server.debug:
print('DEBUG: POST ' + mType + print('DEBUG: POST ' + mType +
' media removing metadata') ' media removing metadata')
postImageFilename = filename.replace('.temp', '') postImageFilename = filename.replace('.temp', '')
removeMetaData(filename, postImageFilename) if mType == 'customFont':
copyfile(filename, postImageFilename)
else:
removeMetaData(filename, postImageFilename)
if os.path.isfile(postImageFilename): if os.path.isfile(postImageFilename):
print('profile update POST ' + mType + print('profile update POST ' + mType +
' image saved to ' + postImageFilename) ' image or font saved to ' + postImageFilename)
if mType != 'instanceLogo': if mType != 'instanceLogo':
lastPartOfImageFilename = \ lastPartOfImageFilename = \
postImageFilename.split('/')[-1] postImageFilename.split('/')[-1]
@ -5473,7 +5480,7 @@ class PubServer(BaseHTTPRequestHandler):
actorChanged = True actorChanged = True
else: else:
print('ERROR: profile update POST ' + mType + print('ERROR: profile update POST ' + mType +
' image could not be saved to ' + ' image or font could not be saved to ' +
postImageFilename) postImageFilename)
fields = \ fields = \

View File

@ -222,5 +222,6 @@
"Your Posts": "منشوراتك", "Your Posts": "منشوراتك",
"Git Projects": "مشاريع Git", "Git Projects": "مشاريع Git",
"List of project names that you wish to receive git patches for": "قائمة بأسماء المشاريع التي ترغب في تلقي تصحيحات git لها", "List of project names that you wish to receive git patches for": "قائمة بأسماء المشاريع التي ترغب في تلقي تصحيحات git لها",
"Show/Hide Buttons": "إظهار / إخفاء الأزرار" "Show/Hide Buttons": "إظهار / إخفاء الأزرار",
"Custom Font": "خط مخصص"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "Les teves publicacions", "Your Posts": "Les teves publicacions",
"Git Projects": "Git Projectes", "Git Projects": "Git Projectes",
"List of project names that you wish to receive git patches for": "Llista de noms de projectes dels quals voleu rebre els pedaços de git", "List of project names that you wish to receive git patches for": "Llista de noms de projectes dels quals voleu rebre els pedaços de git",
"Show/Hide Buttons": "Mostra / Oculta els botons" "Show/Hide Buttons": "Mostra / Oculta els botons",
"Custom Font": "Tipus de lletra personalitzats"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "Eich Swyddi", "Your Posts": "Eich Swyddi",
"Git Projects": "Prosiectau Git", "Git Projects": "Prosiectau Git",
"List of project names that you wish to receive git patches for": "Rhestr o enwau prosiectau yr ydych yn dymuno derbyn darnau git ar eu cyfer", "List of project names that you wish to receive git patches for": "Rhestr o enwau prosiectau yr ydych yn dymuno derbyn darnau git ar eu cyfer",
"Show/Hide Buttons": "Dangos / Cuddio Botymau" "Show/Hide Buttons": "Dangos / Cuddio Botymau",
"Custom Font": "Ffont Custom"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "Deine Posts", "Your Posts": "Deine Posts",
"Git Projects": "Git-Projekte", "Git Projects": "Git-Projekte",
"List of project names that you wish to receive git patches for": "Liste der Projektnamen, für die Sie Git-Patches erhalten möchten", "List of project names that you wish to receive git patches for": "Liste der Projektnamen, für die Sie Git-Patches erhalten möchten",
"Show/Hide Buttons": "Schaltflächen ein- / ausblenden" "Show/Hide Buttons": "Schaltflächen ein- / ausblenden",
"Custom Font": "Benutzerdefinierte Schriftart"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "Your Posts", "Your Posts": "Your Posts",
"Git Projects": "Git Projects", "Git Projects": "Git Projects",
"List of project names that you wish to receive git patches for": "List of project names that you wish to receive git patches for", "List of project names that you wish to receive git patches for": "List of project names that you wish to receive git patches for",
"Show/Hide Buttons": "Show/Hide Buttons" "Show/Hide Buttons": "Show/Hide Buttons",
"Custom Font": "Custom Font"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "Tus publicaciones", "Your Posts": "Tus publicaciones",
"Git Projects": "Proyectos Git", "Git Projects": "Proyectos Git",
"List of project names that you wish to receive git patches for": "Lista de nombres de proyectos para los que desea recibir parches git", "List of project names that you wish to receive git patches for": "Lista de nombres de proyectos para los que desea recibir parches git",
"Show/Hide Buttons": "Botones Mostrar / Ocultar" "Show/Hide Buttons": "Botones Mostrar / Ocultar",
"Custom Font": "Fuente personalizada"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "Vos publications", "Your Posts": "Vos publications",
"Git Projects": "Projets Git", "Git Projects": "Projets Git",
"List of project names that you wish to receive git patches for": "Liste des noms de projets pour lesquels vous souhaitez recevoir des correctifs git", "List of project names that you wish to receive git patches for": "Liste des noms de projets pour lesquels vous souhaitez recevoir des correctifs git",
"Show/Hide Buttons": "Afficher / masquer les boutons" "Show/Hide Buttons": "Afficher / masquer les boutons",
"Custom Font": "Police personnalisée"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "Do Phoist", "Your Posts": "Do Phoist",
"Git Projects": "Tionscadail Git", "Git Projects": "Tionscadail Git",
"List of project names that you wish to receive git patches for": "Liosta dainmneacha tionscadail ar mhaith leat paistí git a fháil dóibh", "List of project names that you wish to receive git patches for": "Liosta dainmneacha tionscadail ar mhaith leat paistí git a fháil dóibh",
"Show/Hide Buttons": "Taispeáin / Folaigh Cnaipí" "Show/Hide Buttons": "Taispeáin / Folaigh Cnaipí",
"Custom Font": "Cló Saincheaptha"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "आपके पोस्ट", "Your Posts": "आपके पोस्ट",
"Git Projects": "गिट परियोजनाओं", "Git Projects": "गिट परियोजनाओं",
"List of project names that you wish to receive git patches for": "उन प्रोजेक्ट नामों की सूची, जिनके लिए आप git पैच प्राप्त करना चाहते हैं", "List of project names that you wish to receive git patches for": "उन प्रोजेक्ट नामों की सूची, जिनके लिए आप git पैच प्राप्त करना चाहते हैं",
"Show/Hide Buttons": "बटन दिखाएँ / छिपाएँ" "Show/Hide Buttons": "बटन दिखाएँ / छिपाएँ",
"Custom Font": "कस्टम फ़ॉन्ट"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "I tuoi post", "Your Posts": "I tuoi post",
"Git Projects": "Git Projects", "Git Projects": "Git Projects",
"List of project names that you wish to receive git patches for": "Elenco di nomi di progetti per i quali si desidera ricevere patch git", "List of project names that you wish to receive git patches for": "Elenco di nomi di progetti per i quali si desidera ricevere patch git",
"Show/Hide Buttons": "Mostra / Nascondi pulsanti" "Show/Hide Buttons": "Mostra / Nascondi pulsanti",
"Custom Font": "Carattere personalizzato"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "あなたの投稿", "Your Posts": "あなたの投稿",
"Git Projects": "Gitプロジェクト", "Git Projects": "Gitプロジェクト",
"List of project names that you wish to receive git patches for": "gitパッチを受け取りたいプロジェクト名のリスト", "List of project names that you wish to receive git patches for": "gitパッチを受け取りたいプロジェクト名のリスト",
"Show/Hide Buttons": "ボタンの表示/非表示" "Show/Hide Buttons": "ボタンの表示/非表示",
"Custom Font": "カスタムフォント"
} }

View File

@ -218,5 +218,6 @@
"Your Posts": "Your Posts", "Your Posts": "Your Posts",
"Git Projects": "Git Projects", "Git Projects": "Git Projects",
"List of project names that you wish to receive git patches for": "List of project names that you wish to receive git patches for", "List of project names that you wish to receive git patches for": "List of project names that you wish to receive git patches for",
"Show/Hide Buttons": "Show/Hide Buttons" "Show/Hide Buttons": "Show/Hide Buttons",
"Custom Font": "Custom Font"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "Seus posts", "Your Posts": "Seus posts",
"Git Projects": "Projetos Git", "Git Projects": "Projetos Git",
"List of project names that you wish to receive git patches for": "Lista de nomes de projetos para os quais você deseja receber patches git", "List of project names that you wish to receive git patches for": "Lista de nomes de projetos para os quais você deseja receber patches git",
"Show/Hide Buttons": "Botões Mostrar / Ocultar" "Show/Hide Buttons": "Botões Mostrar / Ocultar",
"Custom Font": "Fonte Personalizada"
} }

View File

@ -222,5 +222,6 @@
"Your Posts": "Ваши сообщения", "Your Posts": "Ваши сообщения",
"Git Projects": "Git Projects", "Git Projects": "Git Projects",
"List of project names that you wish to receive git patches for": "Список имен проектов, для которых вы хотите получать git-патчи", "List of project names that you wish to receive git patches for": "Список имен проектов, для которых вы хотите получать git-патчи",
"Show/Hide Buttons": "Показать / Скрыть кнопки" "Show/Hide Buttons": "Показать / Скрыть кнопки",
"Custom Font": "Пользовательский шрифт"
} }

View File

@ -221,5 +221,6 @@
"Your Posts": "您的帖子", "Your Posts": "您的帖子",
"Git Projects": "Git项目", "Git Projects": "Git项目",
"List of project names that you wish to receive git patches for": "您希望收到git补丁的项目名称列表", "List of project names that you wish to receive git patches for": "您希望收到git补丁的项目名称列表",
"Show/Hide Buttons": "显示/隐藏按钮" "Show/Hide Buttons": "显示/隐藏按钮",
"Custom Font": "自定义字体"
} }

View File

@ -938,6 +938,7 @@ def htmlEditProfile(translate: {}, baseDir: str, path: str,
"""Shows the edit profile screen """Shows the edit profile screen
""" """
imageFormats = '.png, .jpg, .jpeg, .gif, .webp' imageFormats = '.png, .jpg, .jpeg, .gif, .webp'
fontFormats = '.woff, .woff2, .ttf, .otf'
pathOriginal = path pathOriginal = path
path = path.replace('/inbox', '').replace('/outbox', '') path = path.replace('/inbox', '').replace('/outbox', '')
path = path.replace('/shares', '') path = path.replace('/shares', '')
@ -1119,6 +1120,12 @@ def htmlEditProfile(translate: {}, baseDir: str, path: str,
instanceStr += \ instanceStr += \
' <input type="file" id="instanceLogo" name="instanceLogo"' ' <input type="file" id="instanceLogo" name="instanceLogo"'
instanceStr += ' accept="' + imageFormats + '">' instanceStr += ' accept="' + imageFormats + '">'
instanceStr += \
' <label class="labels">' + \
translate['Custom Font'] + '</label>'
instanceStr += \
' <input type="file" id="customFont" name="customFont"'
instanceStr += ' accept="' + fontFormats + '">'
instanceStr += '</div>' instanceStr += '</div>'
moderators = '' moderators = ''