Multifile support in site.Build.parseJSON, and account for some differences in vichan JSON. #2171
This commit is contained in:
parent
829ef77159
commit
b154a4a79e
@ -663,7 +663,7 @@ Index =
|
||||
for data, i in Index.liveThreadData
|
||||
Index.liveThreadDict[data.no] = data
|
||||
Index.threadPosition[data.no] = i
|
||||
Index.parsedThreads[data.no] = obj = g.SITE.Build.parseJSON data, g.BOARD.ID
|
||||
Index.parsedThreads[data.no] = obj = g.SITE.Build.parseJSON data, g.BOARD
|
||||
obj.filterResults = results = Filter.test obj
|
||||
obj.isOnTop = results.top
|
||||
obj.isHidden = results.hide or ThreadHiding.isHidden(obj.boardID, obj.threadID)
|
||||
@ -685,7 +685,7 @@ Index =
|
||||
Index.parsedThreads[threadID].isHidden
|
||||
|
||||
isHiddenReply: (threadID, replyData) ->
|
||||
PostHiding.isHidden(g.BOARD.ID, threadID, replyData.no) or Filter.isHidden(g.SITE.Build.parseJSON replyData, g.BOARD.ID)
|
||||
PostHiding.isHidden(g.BOARD.ID, threadID, replyData.no) or Filter.isHidden(g.SITE.Build.parseJSON replyData, g.BOARD)
|
||||
|
||||
buildThreads: (threadIDs, isCatalog, withReplies) ->
|
||||
threads = []
|
||||
|
||||
@ -72,7 +72,7 @@ Test =
|
||||
for postData in posts
|
||||
if postData.no is post.ID
|
||||
t1 = new Date().getTime()
|
||||
obj = g.SITE.Build.parseJSON postData, post.board.ID
|
||||
obj = g.SITE.Build.parseJSON postData, post.board
|
||||
root = g.SITE.Build.post obj
|
||||
t2 = new Date().getTime()
|
||||
Test.time += t2 - t1
|
||||
|
||||
@ -355,7 +355,7 @@ ThreadWatcher =
|
||||
for postObj in @response.posts
|
||||
continue unless postObj.no > (data.last or 0) and postObj.no > lastReadPost
|
||||
continue if QuoteYou.db?.get {siteID, boardID, threadID, postID: postObj.no}
|
||||
continue if Filter.isHidden(site.Build.parseJSON postObj, boardID, siteID)
|
||||
continue if Filter.isHidden(site.Build.parseJSON postObj, {siteID, boardID})
|
||||
|
||||
unread++
|
||||
quotingYou = postObj.no if !Conf['Require OP Quote Link'] and youOP
|
||||
|
||||
@ -56,6 +56,10 @@ SW.tinyboard =
|
||||
catalogJSON: ({siteID, boardID}) ->
|
||||
root = Conf['siteProperties'][siteID]?.root
|
||||
if root then "#{root}#{boardID}/catalog.json" else ''
|
||||
file: ({siteID, boardID}, filename) ->
|
||||
"#{Conf['siteProperties'][siteID]?.root or "http://#{siteID}/"}#{boardID}/#{filename}"
|
||||
thumb: (board, filename) ->
|
||||
SW.tinyboard.urls.file board, filename
|
||||
|
||||
selectors:
|
||||
board: 'form[name="postcontrols"]'
|
||||
@ -117,8 +121,25 @@ SW.tinyboard =
|
||||
/<a [^>]*\bhref="[^"]*\/([^\/]+)\/res\/(\d+)\.\w+#(\d+)"/g
|
||||
|
||||
Build:
|
||||
parseJSON: ->
|
||||
SW.yotsuba.Build.parseJSON.apply SW.yotsuba.Build, arguments
|
||||
parseJSON: (data, board) ->
|
||||
o = SW.yotsuba.Build.parseJSON(data, board)
|
||||
if data.ext is 'deleted'
|
||||
delete o.file
|
||||
$.extend o,
|
||||
files: []
|
||||
fileDeleted: true
|
||||
filesDeleted: [0]
|
||||
if data.extra_files
|
||||
for extra_file, i in data.extra_files
|
||||
if extra_file.ext is 'deleted'
|
||||
o.filesDeleted.push i
|
||||
else
|
||||
file = SW.yotsuba.Build.parseJSONFile(data, board)
|
||||
o.files.push file
|
||||
if o.files.length
|
||||
o.file = o.files[0]
|
||||
o
|
||||
|
||||
parseComment: (html) ->
|
||||
html = html
|
||||
.replace(/<br\b[^<]*>/gi, '\n')
|
||||
|
||||
@ -31,13 +31,14 @@ Build =
|
||||
postURL: (boardID, threadID, postID) ->
|
||||
"#{Build.threadURL(boardID, threadID)}#p#{postID}"
|
||||
|
||||
parseJSON: (data, boardID, siteID) ->
|
||||
parseJSON: (data, {siteID, boardID}) ->
|
||||
o =
|
||||
# id
|
||||
ID: data.no
|
||||
postID: data.no
|
||||
threadID: data.resto or data.no
|
||||
boardID: boardID
|
||||
siteID: siteID or g.SITE.ID
|
||||
siteID: siteID
|
||||
isReply: !!data.resto
|
||||
# thread status
|
||||
isSticky: !!data.sticky
|
||||
@ -45,6 +46,7 @@ Build =
|
||||
isArchived: !!data.archived
|
||||
# file status
|
||||
fileDeleted: !!data.filedeleted
|
||||
filesDeleted: if data.filedeleted then [0] else []
|
||||
o.info =
|
||||
subject: $.unescape data.sub
|
||||
email: $.unescape data.email
|
||||
@ -62,29 +64,37 @@ Build =
|
||||
o.info.capcode = data.capcode.replace(/_highlight$/, '').replace(/_/g, ' ').replace(/\b\w/g, (c) -> c.toUpperCase())
|
||||
o.capcodeHighlight = /_highlight$/.test data.capcode
|
||||
delete o.info.uniqueID
|
||||
o.files = []
|
||||
if data.ext
|
||||
o.file =
|
||||
name: ($.unescape data.filename) + data.ext
|
||||
url: if boardID is 'f'
|
||||
"#{location.protocol}//#{ImageHost.flashHost()}/#{boardID}/#{encodeURIComponent data.filename}#{data.ext}"
|
||||
else
|
||||
"#{location.protocol}//#{ImageHost.host()}/#{boardID}/#{data.tim}#{data.ext}"
|
||||
height: data.h
|
||||
width: data.w
|
||||
MD5: data.md5
|
||||
size: $.bytesToString data.fsize
|
||||
thumbURL: "#{location.protocol}//#{ImageHost.thumbHost()}/#{boardID}/#{data.tim}s.jpg"
|
||||
theight: data.tn_h
|
||||
twidth: data.tn_w
|
||||
isSpoiler: !!data.spoiler
|
||||
tag: data.tag
|
||||
hasDownscale: !!data.m_img
|
||||
o.file.dimensions = "#{o.file.width}x#{o.file.height}" unless /\.pdf$/.test o.file.url
|
||||
o.file = SW.yotsuba.Build.parseJSONFile(data, {siteID, boardID})
|
||||
o.files.push o.file
|
||||
# Temporary JSON properties for events such as April 1 / Halloween
|
||||
for key of data when key[0] is 'x'
|
||||
o[key] = data[key]
|
||||
o
|
||||
|
||||
parseJSONFile: (data, {siteID, boardID}) ->
|
||||
site = g.sites[siteID]
|
||||
filename = if site.software is 'yotsuba' and boardID is 'f'
|
||||
"#{encodeURIComponent data.filename}#{data.ext}"
|
||||
else
|
||||
"#{data.tim}#{data.ext}"
|
||||
o =
|
||||
name: ($.unescape data.filename) + data.ext
|
||||
url: site.urls.file({siteID, boardID}, filename)
|
||||
height: data.h
|
||||
width: data.w
|
||||
MD5: data.md5
|
||||
size: $.bytesToString data.fsize
|
||||
thumbURL: site.urls.thumb({siteID, boardID}, "#{data.tim}s.jpg")
|
||||
theight: data.tn_h
|
||||
twidth: data.tn_w
|
||||
isSpoiler: !!data.spoiler
|
||||
tag: data.tag
|
||||
hasDownscale: !!data.m_img
|
||||
o.dimensions = "#{o.width}x#{o.height}" if data.h? and !/\.pdf$/.test(o.url)
|
||||
o
|
||||
|
||||
parseComment: (html) ->
|
||||
html = html
|
||||
.replace(/<br\b[^<]*>/gi, '\n')
|
||||
@ -104,7 +114,7 @@ Build =
|
||||
Build.parseComment(html).trim().replace(/\s+$/gm, '')
|
||||
|
||||
postFromObject: (data, boardID) ->
|
||||
o = Build.parseJSON data, boardID
|
||||
o = Build.parseJSON data, {boardID, siteID: g.SITE.ID}
|
||||
Build.post o
|
||||
|
||||
post: (o) ->
|
||||
|
||||
@ -8,6 +8,11 @@ SW.yotsuba =
|
||||
threadsListJSON: ({boardID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/threads.json"
|
||||
archiveListJSON: ({boardID}) -> if BoardConfig.isArchived(boardID) then "#{location.protocol}//a.4cdn.org/#{boardID}/archive.json" else ''
|
||||
catalogJSON: ({boardID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/catalog.json"
|
||||
file: ({boardID}, filename) ->
|
||||
hostname = if boardID is 'f' then ImageHost.flashHost() else ImageHost.host()
|
||||
"#{location.protocol}//#{hostname}/#{boardID}/#{filename}"
|
||||
thumb: ({boardID}, filename) ->
|
||||
"#{location.protocol}//#{ImageHost.thumbHost()}/#{boardID}/#{filename}"
|
||||
|
||||
isPrunedByAge: ({boardID}) -> boardID is 'f'
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user