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
|
for data, i in Index.liveThreadData
|
||||||
Index.liveThreadDict[data.no] = data
|
Index.liveThreadDict[data.no] = data
|
||||||
Index.threadPosition[data.no] = i
|
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.filterResults = results = Filter.test obj
|
||||||
obj.isOnTop = results.top
|
obj.isOnTop = results.top
|
||||||
obj.isHidden = results.hide or ThreadHiding.isHidden(obj.boardID, obj.threadID)
|
obj.isHidden = results.hide or ThreadHiding.isHidden(obj.boardID, obj.threadID)
|
||||||
@ -685,7 +685,7 @@ Index =
|
|||||||
Index.parsedThreads[threadID].isHidden
|
Index.parsedThreads[threadID].isHidden
|
||||||
|
|
||||||
isHiddenReply: (threadID, replyData) ->
|
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) ->
|
buildThreads: (threadIDs, isCatalog, withReplies) ->
|
||||||
threads = []
|
threads = []
|
||||||
|
|||||||
@ -72,7 +72,7 @@ Test =
|
|||||||
for postData in posts
|
for postData in posts
|
||||||
if postData.no is post.ID
|
if postData.no is post.ID
|
||||||
t1 = new Date().getTime()
|
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
|
root = g.SITE.Build.post obj
|
||||||
t2 = new Date().getTime()
|
t2 = new Date().getTime()
|
||||||
Test.time += t2 - t1
|
Test.time += t2 - t1
|
||||||
|
|||||||
@ -355,7 +355,7 @@ ThreadWatcher =
|
|||||||
for postObj in @response.posts
|
for postObj in @response.posts
|
||||||
continue unless postObj.no > (data.last or 0) and postObj.no > lastReadPost
|
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 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++
|
unread++
|
||||||
quotingYou = postObj.no if !Conf['Require OP Quote Link'] and youOP
|
quotingYou = postObj.no if !Conf['Require OP Quote Link'] and youOP
|
||||||
|
|||||||
@ -56,6 +56,10 @@ SW.tinyboard =
|
|||||||
catalogJSON: ({siteID, boardID}) ->
|
catalogJSON: ({siteID, boardID}) ->
|
||||||
root = Conf['siteProperties'][siteID]?.root
|
root = Conf['siteProperties'][siteID]?.root
|
||||||
if root then "#{root}#{boardID}/catalog.json" else ''
|
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:
|
selectors:
|
||||||
board: 'form[name="postcontrols"]'
|
board: 'form[name="postcontrols"]'
|
||||||
@ -117,8 +121,25 @@ SW.tinyboard =
|
|||||||
/<a [^>]*\bhref="[^"]*\/([^\/]+)\/res\/(\d+)\.\w+#(\d+)"/g
|
/<a [^>]*\bhref="[^"]*\/([^\/]+)\/res\/(\d+)\.\w+#(\d+)"/g
|
||||||
|
|
||||||
Build:
|
Build:
|
||||||
parseJSON: ->
|
parseJSON: (data, board) ->
|
||||||
SW.yotsuba.Build.parseJSON.apply SW.yotsuba.Build, arguments
|
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) ->
|
parseComment: (html) ->
|
||||||
html = html
|
html = html
|
||||||
.replace(/<br\b[^<]*>/gi, '\n')
|
.replace(/<br\b[^<]*>/gi, '\n')
|
||||||
|
|||||||
@ -31,13 +31,14 @@ Build =
|
|||||||
postURL: (boardID, threadID, postID) ->
|
postURL: (boardID, threadID, postID) ->
|
||||||
"#{Build.threadURL(boardID, threadID)}#p#{postID}"
|
"#{Build.threadURL(boardID, threadID)}#p#{postID}"
|
||||||
|
|
||||||
parseJSON: (data, boardID, siteID) ->
|
parseJSON: (data, {siteID, boardID}) ->
|
||||||
o =
|
o =
|
||||||
# id
|
# id
|
||||||
ID: data.no
|
ID: data.no
|
||||||
|
postID: data.no
|
||||||
threadID: data.resto or data.no
|
threadID: data.resto or data.no
|
||||||
boardID: boardID
|
boardID: boardID
|
||||||
siteID: siteID or g.SITE.ID
|
siteID: siteID
|
||||||
isReply: !!data.resto
|
isReply: !!data.resto
|
||||||
# thread status
|
# thread status
|
||||||
isSticky: !!data.sticky
|
isSticky: !!data.sticky
|
||||||
@ -45,6 +46,7 @@ Build =
|
|||||||
isArchived: !!data.archived
|
isArchived: !!data.archived
|
||||||
# file status
|
# file status
|
||||||
fileDeleted: !!data.filedeleted
|
fileDeleted: !!data.filedeleted
|
||||||
|
filesDeleted: if data.filedeleted then [0] else []
|
||||||
o.info =
|
o.info =
|
||||||
subject: $.unescape data.sub
|
subject: $.unescape data.sub
|
||||||
email: $.unescape data.email
|
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.info.capcode = data.capcode.replace(/_highlight$/, '').replace(/_/g, ' ').replace(/\b\w/g, (c) -> c.toUpperCase())
|
||||||
o.capcodeHighlight = /_highlight$/.test data.capcode
|
o.capcodeHighlight = /_highlight$/.test data.capcode
|
||||||
delete o.info.uniqueID
|
delete o.info.uniqueID
|
||||||
|
o.files = []
|
||||||
if data.ext
|
if data.ext
|
||||||
o.file =
|
o.file = SW.yotsuba.Build.parseJSONFile(data, {siteID, boardID})
|
||||||
name: ($.unescape data.filename) + data.ext
|
o.files.push o.file
|
||||||
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
|
|
||||||
# Temporary JSON properties for events such as April 1 / Halloween
|
# Temporary JSON properties for events such as April 1 / Halloween
|
||||||
for key of data when key[0] is 'x'
|
for key of data when key[0] is 'x'
|
||||||
o[key] = data[key]
|
o[key] = data[key]
|
||||||
o
|
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) ->
|
parseComment: (html) ->
|
||||||
html = html
|
html = html
|
||||||
.replace(/<br\b[^<]*>/gi, '\n')
|
.replace(/<br\b[^<]*>/gi, '\n')
|
||||||
@ -104,7 +114,7 @@ Build =
|
|||||||
Build.parseComment(html).trim().replace(/\s+$/gm, '')
|
Build.parseComment(html).trim().replace(/\s+$/gm, '')
|
||||||
|
|
||||||
postFromObject: (data, boardID) ->
|
postFromObject: (data, boardID) ->
|
||||||
o = Build.parseJSON data, boardID
|
o = Build.parseJSON data, {boardID, siteID: g.SITE.ID}
|
||||||
Build.post o
|
Build.post o
|
||||||
|
|
||||||
post: (o) ->
|
post: (o) ->
|
||||||
|
|||||||
@ -8,6 +8,11 @@ SW.yotsuba =
|
|||||||
threadsListJSON: ({boardID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/threads.json"
|
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 ''
|
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"
|
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'
|
isPrunedByAge: ({boardID}) -> boardID is 'f'
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user