From a265abc01acae22c0de414386babb38e62a475f9 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 24 Oct 2015 10:56:40 -0700 Subject: [PATCH] For missing/invalid extensions, append the correct extension if we know it. 4chan will reject WebMs sent as ".jpg". --- src/Posting/QR.coffee | 9 +++++++++ src/Posting/QR.post.coffee | 6 ++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index dc3be0def..5617bab74 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -12,6 +12,15 @@ 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 a81b0d13e..891e19cee 100644 --- a/src/Posting/QR.post.coffee +++ b/src/Posting/QR.post.coffee @@ -301,10 +301,8 @@ QR.post = class saveFilename: -> @file.newName = (@filename or '').replace /[/\\]/g, '-' 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. - @file.newName += '.jpg' + # 4chan will truncate the filename if it has no extension. + @file.newName += ".#{QR.extensionFromType[@file.type] or 'jpg'}" updateFilename: -> long = "#{@filename} (#{@filesize})"