From b829bde74280d224570b3ec3a2eb75d9e113976c Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 14 Aug 2015 00:47:17 -0700 Subject: [PATCH 1/4] Add 'Randomize Filename' option. #452 --- src/General/Config.coffee | 5 +++++ src/Posting/QR.coffee | 9 +++++++++ src/Posting/QR.post.coffee | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index e3e1962e0..685aeefdb 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -431,6 +431,11 @@ Config = 'Remember the spoiler state, instead of resetting after posting.' 1 ] + 'Randomize Filename': [ + false + 'Set the filename to a random timestamp within the past year. Disabled on /f/.' + 1 + ] 'Show New Thread Option in Threads': [ false 'Show the option to post a new / different thread from inside a thread.' diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 7ebc6d92d..7743ed5f7 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -10,6 +10,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 5636ba648..79ebc7632 100644 --- a/src/Posting/QR.post.coffee +++ b/src/Posting/QR.post.coffee @@ -179,7 +179,10 @@ QR.post = class return setFile: (@file) -> - @filename = @file.name + @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'}" + else + @file.name @filesize = $.bytesToString @file.size @checkSize() @nodes.label.hidden = false if QR.spoiler From d8f001c2c9347c66b0b4ddb50981fe4e02b33a67 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 14 Aug 2015 02:08:57 -0700 Subject: [PATCH 2/4] Randomize Filename: Keep original extension as it will be overwritten anyway. --- src/Posting/QR.coffee | 11 ++--------- src/Posting/QR.post.coffee | 9 +++++---- 2 files changed, 7 insertions(+), 13 deletions(-) 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. From cd720e7f291006f5a04427c513c62a022f86a0b2 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 14 Aug 2015 02:26:17 -0700 Subject: [PATCH 3/4] Use file.png for pasted images in both FF and Chromium. --- src/Posting/QR.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 04ef8a8af..f6858cfb7 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -365,7 +365,7 @@ QR = for i in [0...bstr.length] arr[i] = bstr.charCodeAt(i) blob = new Blob [arr], {type: m[1]} - blob.name = "image.#{m[2]}" + blob.name = "file.#{m[2]}" QR.handleFiles [blob] else if /^https?:\/\//.test src QR.handleUrl src From 9407af1f6539f432ba5ef7364999be7174445e2a Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 14 Aug 2015 12:17:21 -0700 Subject: [PATCH 4/4] Fix cached captchas causing errors when we switch between captcha types. --- src/Posting/Captcha.noscript.coffee | 12 +++++++----- src/Posting/Captcha.v1.coffee | 9 +++++---- src/Posting/Captcha.v2.coffee | 2 +- src/Posting/QR.coffee | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Posting/Captcha.noscript.coffee b/src/Posting/Captcha.noscript.coffee index 9a2361331..359181acc 100644 --- a/src/Posting/Captcha.noscript.coffee +++ b/src/Posting/Captcha.noscript.coffee @@ -133,7 +133,7 @@ Captcha.noscript = if captcha = @captchas.shift() @count() $.set 'captchas', @captchas - {challenge: captcha.response, response: 'manual_challenge'} + captcha else if /\S/.test @nodes.input.value (cb) => @submitCB = cb @@ -149,15 +149,17 @@ Captcha.noscript = save: (token) -> delete @occupied @nodes.input.value = '' + captcha = + challenge: token + response: 'manual_challenge' + timeout: @timeout if @submitCB - @submitCB {challenge: token, response: 'manual_challenge'} + @submitCB captcha delete @submitCB if @needed() then @reload() else @destroy() else $.forceSync 'captchas' - @captchas.push - response: token - timeout: @timeout + @captchas.push captcha @count() $.set 'captchas', @captchas @reload() diff --git a/src/Posting/Captcha.v1.coffee b/src/Posting/Captcha.v1.coffee index c93ad3c84..904b0f5d0 100644 --- a/src/Posting/Captcha.v1.coffee +++ b/src/Posting/Captcha.v1.coffee @@ -135,16 +135,17 @@ Captcha.v1 = getOne: -> @clear() if captcha = @captchas.shift() - {challenge, response} = captcha @count() $.set 'captchas', @captchas + captcha else - challenge = @nodes.img.alt + challenge = @nodes.img.alt + timeout = @timeout if /\S/.test(response = @nodes.input.value) @destroy() + {challenge, response, timeout} else - return null - {challenge, response} + null save: -> return unless /\S/.test(response = @nodes.input.value) diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index 10161b56e..86cbfbfcf 100644 --- a/src/Posting/Captcha.v2.coffee +++ b/src/Posting/Captcha.v2.coffee @@ -169,7 +169,7 @@ Captcha.v2 = if captcha = @captchas.shift() $.set 'captchas', @captchas @count() - captcha.response + captcha else null diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index f6858cfb7..2dbaf5d4f 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -680,7 +680,7 @@ QR = extra.form.append 'recaptcha_challenge_field', response.challenge extra.form.append 'recaptcha_response_field', response.response else - extra.form.append 'g-recaptcha-response', response + extra.form.append 'g-recaptcha-response', response.response QR.req = $.ajax "https://sys.4chan.org/#{g.BOARD}/post", options, extra QR.req.progress = '...'