Randomize Filename: Keep original extension as it will be overwritten anyway.

This commit is contained in:
ccd0 2015-08-14 02:08:57 -07:00
parent b829bde742
commit d8f001c2c9
2 changed files with 7 additions and 13 deletions

View File

@ -1,6 +1,8 @@
QR =
mimeTypes: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/vnd.adobe.flash.movie', 'application/x-shockwave-flash', 'video/webm']
validExtension: /\.(jpe?g|png|gif|pdf|swf|webm)$/i
typeFromExtension:
'jpg': 'image/jpeg'
'jpeg': 'image/jpeg'
@ -10,15 +12,6 @@ QR =
'swf': 'application/vnd.adobe.flash.movie'
'webm': 'video/webm'
extensionFromType:
'image/jpeg': 'jpg'
'image/png': 'png'
'image/gif': 'gif'
'application/pdf': 'pdf'
'application/vnd.adobe.flash.movie': 'swf'
'application/x-shockwave-flash': 'swf'
'video/webm': 'webm'
init: ->
return unless Conf['Quick Reply']

View File

@ -179,10 +179,11 @@ QR.post = class
return
setFile: (@file) ->
@filename = if Conf['Randomize Filename'] and g.BOARD.ID isnt 'f'
"#{Date.now() - Math.floor(Math.random() * 365 * $.DAY)}.#{QR.extensionFromType[@file.type] or 'jpg'}"
if Conf['Randomize Filename'] and g.BOARD.ID isnt 'f'
@filename = "#{Date.now() - Math.floor(Math.random() * 365 * $.DAY)}"
@filename += ext[0] if ext = @file.name.match QR.validExtension
else
@file.name
@filename = @file.name
@filesize = $.bytesToString @file.size
@checkSize()
@nodes.label.hidden = false if QR.spoiler
@ -299,7 +300,7 @@ QR.post = class
saveFilename: ->
@file.newName = (@filename or '').replace /[/\\]/g, '-'
unless /\.(jpe?g|png|gif|pdf|swf|webm)$/i.test @filename
unless QR.validExtension.test @filename
# 4chan will truncate the filename if it has no extension,
# but it will always replace the extension by the correct one,
# so we suffix it with '.jpg' when needed.