Allow fetching posts for archives that require credentials.

This commit is contained in:
Mayhem 2013-08-09 12:41:59 +02:00
parent 2cbf3d909d
commit 0b55e34361
4 changed files with 24 additions and 15 deletions

View File

@ -103,6 +103,7 @@
"domain": "beta.foolz.us",
"http": true,
"https": true,
"withCredentials": true,
"software": "foolfuuka",
"boards": ["a", "co", "gd", "h", "jp", "m", "mlp", "q", "sp", "tg", "tv", "u", "v", "vg", "vp", "vr", "wsg"],
"files": ["a", "gd", "h", "jp", "m", "q", "tg", "u", "vg", "vp", "vr", "wsg"]

View File

@ -49,7 +49,7 @@ $.ajax = (url, options, extra={}) ->
r
$.cache = do ->
reqs = {}
(url, cb) ->
(url, cb, options) ->
if req = reqs[url]
if req.readyState is 4
cb.call req, req.evt
@ -57,13 +57,13 @@ $.cache = do ->
req.callbacks.push cb
return
rm = -> delete reqs[url]
req = $.ajax url,
onload: (e) ->
cb.call @, e for cb in @callbacks
@evt = e
delete @callbacks
onabort: rm
onerror: rm
req = $.ajax url, options
$.on req, 'load', (e) ->
cb.call @, e for cb in @callbacks
@evt = e
delete @callbacks
$.on req, 'abort', rm
$.on req, 'error', rm
req.callbacks = [cb]
reqs[url] = req
$.cb =

View File

@ -74,7 +74,9 @@ Redirect =
# Remove necessary HTTPS procotol in September 2013.
if archive.name in ['Foolz', 'NSFW Foolz']
protocol = 'https://'
"#{protocol}#{archive.domain}/_/api/chan/post/?board=#{boardID}&num=#{postID}"
URL = new String "#{protocol}#{archive.domain}/_/api/chan/post/?board=#{boardID}&num=#{postID}"
URL.archive = archive
URL
file: (archive, {boardID, filename}) ->
"#{Redirect.protocol archive}#{archive.domain}/#{boardID}/full_image/#{filename}"

View File

@ -71,8 +71,10 @@ Get =
$.cache "//api.4chan.org/#{boardID}/res/#{threadID}.json", ->
Get.fetchedPost @, boardID, threadID, postID, root, context
else if url = Redirect.to 'post', {boardID, postID}
$.cache url, ->
Get.archivedPost @, boardID, postID, root, context
$.cache url,
-> Get.archivedPost @, boardID, postID, root, context
,
withCredentials: url.archive.withCredentials
insert: (post, root, context) ->
# Stop here if the container has been removed while loading.
return unless root.parentNode
@ -97,8 +99,10 @@ Get =
if status not in [200, 304]
# The thread can die by the time we check a quote.
if url = Redirect.to 'post', {boardID, postID}
$.cache url, ->
Get.archivedPost @, boardID, postID, root, context
$.cache url,
-> Get.archivedPost @, boardID, postID, root, context
,
withCredentials: url.archive.withCredentials
else
$.addClass root, 'warning'
root.textContent =
@ -115,8 +119,10 @@ Get =
if post.no > postID
# The post can be deleted by the time we check a quote.
if url = Redirect.to 'post', {boardID, postID}
$.cache url, ->
Get.archivedPost @, boardID, postID, root, context
$.cache url,
-> Get.archivedPost @, boardID, postID, root, context
,
withCredentials: url.archive.withCredentials
else
$.addClass root, 'warning'
root.textContent = "Post No.#{postID} was not found."