Implement pruning of data for dead threads on vichan sites with JSON API. #2171 (also work on #525)

This commit is contained in:
ccd0 2019-03-08 23:38:11 -08:00
parent 44feaf4eb7
commit e43d91c9d3
4 changed files with 22 additions and 10 deletions

View File

@ -48,6 +48,11 @@ BoardConfig =
domain: (board) ->
"boards.#{if BoardConfig.isSFW(board) then '4channel' else '4chan'}.org"
isArchived: (board) ->
# assume archive exists if no data available to prevent cleaning of archived threads
data = (@boards or Conf['boardConfig'].boards)[board]
!data or data.is_archived
noAudio: (boardID) ->
return false unless Site.software is 'yotsuba'
boards = @boards or Conf['boardConfig'].boards

View File

@ -116,13 +116,9 @@ class DataBoard
val or defaultValue
clean: ->
# XXX not yet multisite ready
return unless Site.software is 'yotsuba'
siteID = Site.hostname
for boardID, val of @data[siteID].boards
@deleteIfEmpty {siteID, boardID}
now = Date.now()
unless now - 2 * $.HOUR < (@data[siteID].lastChecked or 0) <= now
@data[siteID].lastChecked = now
@ -131,12 +127,18 @@ class DataBoard
return
ajaxClean: (boardID) ->
$.cache "#{location.protocol}//a.4cdn.org/#{boardID}/threads.json", (e1) =>
return unless e1.target.status is 200
response1 = e1.target.response
$.cache "#{location.protocol}//a.4cdn.org/#{boardID}/archive.json", (e2) =>
return unless e2.target.status is 200 or boardID in ['b', 'f', 'trash', 'bant']
@ajaxCleanParse boardID, response1, e2.target.response
that = @
siteID = Site.hostname
threadsList = Site.urls.threadsListJSON?({siteID, boardID})
return unless threadsList
$.cache threadsList, ->
return unless @status is 200
archiveList = Site.urls.archiveListJSON?({siteID, boardID})
return that.ajaxCleanParse(boardID, @response) unless archiveList
response1 = @response
$.cache archiveList, ->
return unless @status is 200
that.ajaxCleanParse(boardID, response1, @response)
ajaxCleanParse: (boardID, response1, response2) ->
siteID = Site.hostname

View File

@ -60,6 +60,9 @@ SW.tinyboard =
threadJSON: ({siteID, boardID, threadID}) ->
root = Conf['siteProperties'][siteID]?.root
if root then "#{root}#{boardID}/res/#{threadID}.json" else ''
threadsListJSON: ({siteID, boardID}) ->
root = Conf['siteProperties'][siteID]?.root
if root then "#{root}#{boardID}/threads.json" else ''
selectors:
board: 'form[name="postcontrols"]'

View File

@ -4,6 +4,8 @@ SW.yotsuba =
urls:
thread: ({boardID, threadID}) -> "#{location.protocol}//#{BoardConfig.domain(boardID)}/#{boardID}/thread/#{threadID}"
threadJSON: ({boardID, threadID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/thread/#{threadID}.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 ''
selectors:
board: '.board'