improve error handling
This commit is contained in:
parent
2128660c0b
commit
3aa96b32f0
@ -86,7 +86,7 @@ Header =
|
||||
# Wait for #boardNavMobile instead of #boardNavDesktop,
|
||||
# it might be incomplete otherwise.
|
||||
$.asap (-> $.id('boardNavMobile') or d.readyState isnt 'loading'), Header.setBoardList
|
||||
$.prepend d.body, @bar
|
||||
$.prepend d.body, [@bar, @noticesRoot]
|
||||
$.add d.body, Header.hover
|
||||
@setBarPosition Conf['Bottom Header']
|
||||
@
|
||||
@ -142,7 +142,7 @@ Header =
|
||||
|
||||
$.rm $ '#navtopright', fullBoardList
|
||||
$.add boardList, fullBoardList
|
||||
$.add Header.bar, [Header.boardList, Header.shortcuts, Header.noticesRoot, Header.toggle]
|
||||
$.add Header.bar, [Header.boardList, Header.shortcuts, Header.toggle]
|
||||
|
||||
Header.setCustomNav Conf['Custom Board Navigation']
|
||||
Header.generateBoardList Conf['boardnav'].replace /(\r\n|\n|\r)/g, ' '
|
||||
@ -308,18 +308,15 @@ Header =
|
||||
'bottom-header'
|
||||
'top-header'
|
||||
'bottom'
|
||||
'after'
|
||||
] else [
|
||||
'top-header'
|
||||
'bottom-header'
|
||||
'top'
|
||||
'add'
|
||||
]
|
||||
|
||||
$.addClass doc, args[0]
|
||||
$.rmClass doc, args[1]
|
||||
Header.bar.parentNode.className = args[2]
|
||||
$[args[3]] Header.bar, Header.noticesRoot
|
||||
|
||||
toggleBarPosition: ->
|
||||
$.cb.checked.call @
|
||||
|
||||
@ -181,7 +181,9 @@ Gallery =
|
||||
Gallery.build @
|
||||
|
||||
error: (file, thumb) ->
|
||||
ImageCommon.error file, g.posts[file.dataset.post], ->
|
||||
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, ->
|
||||
thumb.href = URL
|
||||
file.src = URL if Gallery.nodes.current is file
|
||||
|
||||
|
||||
@ -1,34 +1,25 @@
|
||||
ImageCommon =
|
||||
error: (file, post, redirect, reload) ->
|
||||
if file.error and file.error.code isnt file.error.MEDIA_ERR_NETWORK # video
|
||||
error = switch file.error.code
|
||||
when 1 then 'MEDIA_ERR_ABORTED'
|
||||
when 3 then 'MEDIA_ERR_DECODE'
|
||||
when 4 then 'MEDIA_ERR_SRC_NOT_SUPPORTED'
|
||||
when 5 then 'MEDIA_ERR_ENCRYPTED'
|
||||
unless message = $ '.warning', post.file.thumb.parentNode
|
||||
message = $.el 'div', className: 'warning'
|
||||
$.after post.file.thumb, message
|
||||
message.textContent = "Playback error: #{error}"
|
||||
return
|
||||
decodeError: (file, post) ->
|
||||
return false unless file.error?.code is MediaError.MEDIA_ERR_DECODE
|
||||
unless message = $ '.warning', post.file.thumb.parentNode
|
||||
message = $.el 'div', className: 'warning'
|
||||
$.after post.file.thumb, message
|
||||
message.textContent = 'Error: Corrupt or unplayable video'
|
||||
return true
|
||||
|
||||
src = file.src.split '/'
|
||||
if src[2] is 'i.4cdn.org'
|
||||
URL = Redirect.to 'file',
|
||||
boardID: src[3]
|
||||
filename: src[src.length - 1].replace /\?.+$/, ''
|
||||
if URL and (/^https:\/\//.test(URL) or location.protocol is 'http:')
|
||||
return redirect URL
|
||||
if g.DEAD or post.isDead or post.file.isDead
|
||||
return
|
||||
error: (post, delay, cb) ->
|
||||
timeoutID = setTimeout ImageCommon.retry, delay, post, cb if delay?
|
||||
return if post.isDead or post.file.isDead
|
||||
kill = (fileOnly) ->
|
||||
clearTimeout timeoutID
|
||||
post.kill fileOnly
|
||||
ImageCommon.retry post, cb
|
||||
|
||||
timeoutID = reload?()
|
||||
<% if (type === 'crx') { %>
|
||||
$.ajax post.file.URL,
|
||||
onloadend: ->
|
||||
return if @status isnt 404
|
||||
clearTimeout timeoutID
|
||||
post.kill true
|
||||
kill true
|
||||
,
|
||||
type: 'head'
|
||||
<% } else { %>
|
||||
@ -38,9 +29,16 @@ ImageCommon =
|
||||
for postObj in @response.posts
|
||||
break if postObj.no is post.ID
|
||||
if postObj.no isnt post.ID
|
||||
clearTimeout timeoutID
|
||||
post.kill()
|
||||
kill()
|
||||
else if postObj.filedeleted
|
||||
clearTimeout timeoutID
|
||||
post.kill true
|
||||
kill true
|
||||
<% } %>
|
||||
|
||||
retry: (post, cb) ->
|
||||
unless post.isDead or post.file.isDead
|
||||
return cb post.file.URL + '?' + Date.now()
|
||||
URL = Redirect.to 'file',
|
||||
boardID: post.board.ID
|
||||
filename: post.file.URL
|
||||
if URL and (/^https:\/\//.test(URL) or location.protocol is 'http:')
|
||||
return cb URL
|
||||
|
||||
@ -125,8 +125,9 @@ ImageExpand =
|
||||
thumb.parentNode.target = '_blank'
|
||||
for eventName, cb of ImageExpand.videoCB
|
||||
$.off el, eventName, cb
|
||||
$.rm post.file.videoControls
|
||||
delete post.file.videoControls
|
||||
if post.file.videoControls
|
||||
$.rm post.file.videoControls
|
||||
delete post.file.videoControls
|
||||
$.rmClass post.nodes.root, 'expanded-image'
|
||||
$.rmClass thumb, 'expanding'
|
||||
delete post.file.isExpanded
|
||||
@ -223,9 +224,8 @@ ImageExpand =
|
||||
# Don't try to re-expand if it was already contracted.
|
||||
return
|
||||
ImageExpand.contract post
|
||||
ImageCommon.error @, post,
|
||||
((URL) -> setTimeout ImageExpand.expand, 10 * $.SECOND, post, URL),
|
||||
(-> setTimeout ImageExpand.expand, 10 * $.SECOND, post)
|
||||
return if ImageCommon.decodeError @, post
|
||||
ImageCommon.error post, 10 * $.SECOND, (URL) -> ImageExpand.expand post, URL
|
||||
|
||||
menu:
|
||||
init: ->
|
||||
|
||||
@ -43,6 +43,5 @@ ImageHover =
|
||||
error: ->
|
||||
return unless doc.contains @
|
||||
post = g.posts[@dataset.fullID]
|
||||
ImageCommon.error @, post,
|
||||
((URL) => @src = URL),
|
||||
(=> setTimeout (=> @src = post.file.URL + '?' + Date.now()), 3 * $.SECOND)
|
||||
return if ImageCommon.decodeError @, post
|
||||
ImageCommon.error post, 3 * $.SECOND, @src = URL
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user