From f80fe44aeade932be9c23d9d338e409ed31ed4be Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 28 Jul 2014 00:12:21 -0700 Subject: [PATCH] fix image 404 redirect --- src/Images/Gallery.coffee | 2 +- src/Images/ImageCommon.coffee | 9 +++++++-- src/Images/ImageExpand.coffee | 2 +- src/Images/ImageHover.coffee | 3 +-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 1d121e071..014a17923 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -183,7 +183,7 @@ Gallery = error: (file, thumb) -> if file.error?.code is MediaError.MEDIA_ERR_DECODE return new Notice 'error', 'Corrupt or unplayable video', 30 - ImageCommon.error g.posts[file.dataset.post], null, -> + ImageCommon.error file, g.posts[file.dataset.post], null, (URL) -> return unless URL thumb.href = URL file.src = URL if Gallery.nodes.current is file diff --git a/src/Images/ImageCommon.coffee b/src/Images/ImageCommon.coffee index 231b82e4a..b0124a9ce 100644 --- a/src/Images/ImageCommon.coffee +++ b/src/Images/ImageCommon.coffee @@ -7,7 +7,10 @@ ImageCommon = message.textContent = 'Error: Corrupt or unplayable video' return true - error: (post, delay, cb) -> + error: (file, post, delay, cb) -> + if (post.isDead or post.file.isDead) and file.src.split('/')[2] is 'i.4cdn.org' + ImageCommon.retry post, cb + timeoutID = setTimeout ImageCommon.retry, delay, post, cb if delay? return if post.isDead or post.file.isDead kill = (fileOnly) -> @@ -25,6 +28,7 @@ ImageCommon = <% } else { %> # XXX CORS for i.4cdn.org WHEN? $.ajax "//a.4cdn.org/#{post.board}/thread/#{post.thread}.json", onload: -> + return kill() if @status is 404 return if @status isnt 200 for postObj in @response.posts break if postObj.no is post.ID @@ -37,9 +41,10 @@ ImageCommon = retry: (post, cb) -> unless post.isDead or post.file.isDead return cb post.file.URL + '?' + Date.now() + src = post.file.URL.split '/' URL = Redirect.to 'file', boardID: post.board.ID - filename: post.file.URL + filename: src[src.length - 1] if URL and (/^https:\/\//.test(URL) or location.protocol is 'http:') return cb URL cb null # report nothing to retry diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index e0a91bdbe..32ae6e79c 100755 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -253,7 +253,7 @@ ImageExpand = # - after the image started loading. # Don't try to re-expand if it was already contracted. if post.file.isExpanding or post.file.isExpanded - ImageCommon.error post, 10 * $.SECOND, (URL) -> + ImageCommon.error @, post, 10 * $.SECOND, (URL) -> if post.file.isExpanding or post.file.isExpanded ImageExpand.contract post ImageExpand.expand post, URL if URL diff --git a/src/Images/ImageHover.coffee b/src/Images/ImageHover.coffee index 4c5e0cff5..428c53198 100755 --- a/src/Images/ImageHover.coffee +++ b/src/Images/ImageHover.coffee @@ -44,5 +44,4 @@ ImageHover = return unless doc.contains @ post = g.posts[@dataset.fullID] return if ImageCommon.decodeError @, post - ImageCommon.error post, 3 * $.SECOND, -> - @src = URL if URL + ImageCommon.error @, post, 3 * $.SECOND, (URL) => @src = URL if URL