Consolidate code to test whether image has been redirected to archive yet.

This commit is contained in:
ccd0 2016-11-05 12:42:05 -07:00
parent 9ff30e39a7
commit 645301f263
3 changed files with 7 additions and 4 deletions

View File

@ -194,7 +194,7 @@ Gallery =
error: ->
if @error?.code is MediaError.MEDIA_ERR_DECODE
return new Notice 'error', 'Corrupt or unplayable video', 30
return unless @src.split('/')[2] is 'i.4cdn.org'
return if ImageCommon.isFromArchive @
ImageCommon.error @, g.posts[@dataset.post], null, (url) =>
return unless url
Gallery.images[@dataset.id].href = url

View File

@ -33,6 +33,9 @@ ImageCommon =
message.textContent = 'Error: Corrupt or unplayable video'
return true
isFromArchive: (file) ->
file.src.split('/')[2] isnt 'i.4cdn.org'
error: (file, post, delay, cb) ->
src = post.file.url.split '/'
URL = Redirect.to 'file', {
@ -42,12 +45,12 @@ ImageCommon =
unless Conf['404 Redirect'] and URL and Redirect.securityCheck URL
URL = null
return cb URL if (post.isDead or post.file.isDead) and file.src.split('/')[2] is 'i.4cdn.org'
return cb URL if (post.isDead or post.file.isDead) and not ImageCommon.isFromArchive file
timeoutID = setTimeout (-> cb URL), delay if delay?
return if post.isDead or post.file.isDead
redirect = ->
if file.src.split('/')[2] is 'i.4cdn.org'
unless ImageCommon.isFromArchive file
clearTimeout timeoutID if delay?
cb URL

View File

@ -268,7 +268,7 @@ ImageExpand =
if ImageCommon.decodeError @, post
return ImageExpand.contract post
# Don't autoretry images from the archive.
unless @src.split('/')[2] is 'i.4cdn.org'
if ImageCommon.isFromArchive @
return ImageExpand.contract post
ImageCommon.error @, post, 10 * $.SECOND, (URL) ->
if post.file.isExpanding or post.file.isExpanded