fix image 404 redirect

This commit is contained in:
ccd0 2014-07-28 00:12:21 -07:00
parent 758a36d2f6
commit f80fe44aea
4 changed files with 10 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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