Remove unused font upload code

main
Bob Mottram 2020-05-28 09:52:25 +01:00
parent 8d3d8ba03e
commit 3e9948374c
2 changed files with 8 additions and 93 deletions

View File

@ -664,74 +664,6 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
return filename, attachmentMediaType
def saveFontInFormPOST(fontBytes, debug: bool,
filenameBase=None) -> (str, str):
"""Saves the given font bytes extracted from http form POST
Returns the filename and attachment type
"""
if not fontBytes:
if debug:
print('DEBUG: No font found within POST')
return None, None
fontLocation = -1
searchStr = ''
filename = None
# directly search the binary array for the beginning
# of a font file
extensionList = {
'wOFF': 'font/woff',
'wOF2': 'font/woff2',
'ttf': 'font/ttf',
'OTTO': 'font/otf'
}
detectedExtension = None
for extension, contentType in extensionList.items():
# font binaries
searchStr = extension.encode('utf8', 'ignore')
fontLocation = fontBytes.find(searchStr)
if fontLocation > -1:
if extension == 'wOFF':
detectedExtension = 'woff'
elif extension == 'wOF2':
detectedExtension = 'woff2'
elif extension == 'OTTO':
detectedExtension = 'otf'
if detectedExtension:
filename = filenameBase + '.' + detectedExtension
attachmentMediaType = contentType
break
if not filename:
# default to ttf if file type not explicitly detected
detectedExtension = 'ttf'
filename = filenameBase + '.' + detectedExtension
attachmentMediaType = 'ttf'
fontLocation = 0
startPos = fontLocation
# remove any existing image files with a different format
extensionTypes = ('woff', 'woff2', 'ttf', 'otf')
for ex in extensionTypes:
if ex == detectedExtension:
continue
possibleOtherFormat = \
filename.replace('.temp', '').replace('.' +
detectedExtension, '.' +
ex)
if os.path.isfile(possibleOtherFormat):
os.remove(possibleOtherFormat)
fd = open(filename, 'wb')
fd.write(fontBytes[startPos:])
fd.close()
return filename, attachmentMediaType
def extractTextFieldsInPOST(postBytes, boundary, debug: bool) -> {}:
"""Returns a dictionary containing the text fields of a http form POST
The boundary argument comes from the http header

View File

@ -162,7 +162,6 @@ from content import replaceEmojiFromTags
from content import addHtmlTags
from content import extractMediaInFormPOST
from content import saveMediaInFormPOST
from content import saveFontInFormPOST
from content import extractTextFieldsInPOST
from media import removeMetaData
from cache import storePersonInCache
@ -170,7 +169,6 @@ from cache import getPersonFromCache
from httpsig import verifyPostHeaders
from theme import setTheme
from theme import getTheme
from theme import setCustomFont
from schedule import runPostSchedule
from schedule import runPostScheduleWatchdog
from schedule import removeScheduledPosts
@ -5444,21 +5442,12 @@ class PubServer(BaseHTTPRequestHandler):
if mType == 'instanceLogo':
filenameBase = \
self.server.baseDir + '/accounts/login.temp'
elif mType == 'customFont':
filenameBase = \
self.server.baseDir + '/fonts/' + \
'custom.temp'
else:
filenameBase = \
self.server.baseDir + '/accounts/' + \
nickname + '@' + self.server.domain + \
'/' + mType + '.temp'
if mType == 'customFont':
filename, attachmentMediaType = \
saveFontInFormPOST(mediaBytes, self.server.debug,
filenameBase)
else:
filename, attachmentMediaType = \
saveMediaInFormPOST(mediaBytes, self.server.debug,
filenameBase)
@ -5471,12 +5460,6 @@ class PubServer(BaseHTTPRequestHandler):
continue
postImageFilename = filename.replace('.temp', '')
if mType == 'customFont':
os.rename(filename, postImageFilename)
setCustomFont(self.server.baseDir)
print('profile POST ' + mType +
' image or font filename ' + postImageFilename)
else:
if self.server.debug:
print('DEBUG: POST ' + mType +
' media removing metadata')
@ -5484,7 +5467,7 @@ class PubServer(BaseHTTPRequestHandler):
if os.path.isfile(postImageFilename):
print('profile update POST ' + mType +
' image or font saved to ' + postImageFilename)
if mType != 'instanceLogo' and mType != 'customFont':
if mType != 'instanceLogo':
lastPartOfImageFilename = \
postImageFilename.split('/')[-1]
profileMediaTypesUploaded[mType] = \