image error handling fixes
This commit is contained in:
parent
61ebff6d6b
commit
5e2ccfee2d
@ -8,8 +8,7 @@ ImageCommon =
|
||||
return true
|
||||
|
||||
error: (file, post, delay, cb) ->
|
||||
return cb null unless file.src.split('/')[2] is 'i.4cdn.org'
|
||||
return ImageCommon.retry post, cb if post.isDead or post.file.isDead
|
||||
return ImageCommon.retry post, cb if (post.isDead or post.file.isDead) and file.src.split('/')[2] is 'i.4cdn.org'
|
||||
|
||||
timeoutID = setTimeout ImageCommon.retry, delay, post, cb if delay?
|
||||
return if post.isDead or post.file.isDead
|
||||
@ -40,7 +39,7 @@ ImageCommon =
|
||||
|
||||
retry: (post, cb) ->
|
||||
unless post.isDead or post.file.isDead
|
||||
return cb post.file.URL + '?' + Date.now()
|
||||
return cb post.file.URL
|
||||
src = post.file.URL.split '/'
|
||||
URL = Redirect.to 'file',
|
||||
boardID: post.board.ID
|
||||
|
||||
@ -245,18 +245,20 @@ ImageExpand =
|
||||
post = Get.postFromNode @
|
||||
$.rm @
|
||||
delete post.file.fullImage
|
||||
if ImageCommon.decodeError @, post
|
||||
ImageExpand.contract post
|
||||
return
|
||||
# Images can error:
|
||||
# - before the image started loading.
|
||||
# - 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) ->
|
||||
if post.file.isExpanding or post.file.isExpanded
|
||||
ImageExpand.contract post
|
||||
ImageExpand.expand post, URL if URL
|
||||
return unless post.file.isExpanding or post.file.isExpanded
|
||||
if ImageCommon.decodeError @, post
|
||||
return ImageExpand.contract post
|
||||
# Don't autoretry images from the archive.
|
||||
unless @src.split('/')[2] is 'i.4cdn.org'
|
||||
return ImageExpand.contract post
|
||||
ImageCommon.error @, post, 10 * $.SECOND, (URL) ->
|
||||
if post.file.isExpanding or post.file.isExpanded
|
||||
ImageExpand.contract post
|
||||
ImageExpand.expand post, URL if URL
|
||||
|
||||
menu:
|
||||
init: ->
|
||||
|
||||
@ -12,6 +12,7 @@ ImageHover =
|
||||
post = Get.postFromNode @
|
||||
{file} = post
|
||||
{isVideo} = file
|
||||
return if post.file.isExpanding or post.file.isExpanded
|
||||
if el = file.fullImage
|
||||
el.id = 'ihover'
|
||||
TrashQueue.remove el
|
||||
@ -19,7 +20,6 @@ ImageHover =
|
||||
file.fullImage = el = $.el (if isVideo then 'video' else 'img'),
|
||||
className: 'full-image'
|
||||
id: 'ihover'
|
||||
el.dataset.fullID = post.fullID
|
||||
$.on el, 'error', ImageHover.error
|
||||
el.src = file.URL
|
||||
$.after file.thumb, el
|
||||
@ -35,13 +35,19 @@ ImageHover =
|
||||
asapTest: -> (if isVideo then el.readyState >= el.HAVE_CURRENT_DATA else el.naturalHeight)
|
||||
noRemove: true
|
||||
cb: ->
|
||||
$.off el, 'error', ImageHover.error
|
||||
if isVideo
|
||||
el.pause()
|
||||
TrashQueue.add el, post
|
||||
el.removeAttribute 'id'
|
||||
error: ->
|
||||
return unless doc.contains @
|
||||
post = g.posts[@dataset.fullID]
|
||||
return if ImageCommon.decodeError @, post
|
||||
ImageCommon.error @, post, 3 * $.SECOND, (URL) => @src = URL if URL
|
||||
post = Get.postFromNode @
|
||||
return if post.file.isExpanding or post.file.isExpanded
|
||||
if @id is 'ihover' # still hovering
|
||||
return if ImageCommon.decodeError @, post
|
||||
ImageCommon.error @, post, 3 * $.SECOND, (URL) =>
|
||||
if URL
|
||||
@src = URL + if @src is URL then '?' + Date.now() else ''
|
||||
else
|
||||
$.off @, 'error', ImageHover.error
|
||||
$.rm @
|
||||
delete post.file.fullImage
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user