diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 7743ed5f7..04ef8a8af 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -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'] diff --git a/src/Posting/QR.post.coffee b/src/Posting/QR.post.coffee index 79ebc7632..a94f2dd42 100644 --- a/src/Posting/QR.post.coffee +++ b/src/Posting/QR.post.coffee @@ -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.