Use POST endpoint for reporting to archives; report to multiple archives. #1260
This commit is contained in:
parent
b765933737
commit
237ca18709
@ -18,20 +18,18 @@ Redirect =
|
|||||||
thread: {}
|
thread: {}
|
||||||
post: {}
|
post: {}
|
||||||
file: {}
|
file: {}
|
||||||
report: {}
|
|
||||||
|
|
||||||
archives = {}
|
archives = {}
|
||||||
for data in Conf['archives']
|
for data in Conf['archives']
|
||||||
for key in ['boards', 'files']
|
for key in ['boards', 'files']
|
||||||
data[key] = [] unless data[key] instanceof Array
|
data[key] = [] unless data[key] instanceof Array
|
||||||
{uid, name, boards, files, software, report} = data
|
{uid, name, boards, files, software} = data
|
||||||
continue unless software in ['fuuka', 'foolfuuka']
|
continue unless software in ['fuuka', 'foolfuuka']
|
||||||
archives[JSON.stringify(uid ? name)] = data
|
archives[JSON.stringify(uid ? name)] = data
|
||||||
for boardID in boards
|
for boardID in boards
|
||||||
o.thread[boardID] = data unless boardID of o.thread
|
o.thread[boardID] = data unless boardID of o.thread
|
||||||
o.post[boardID] = data unless boardID of o.post or software isnt 'foolfuuka'
|
o.post[boardID] = data unless boardID of o.post or software isnt 'foolfuuka'
|
||||||
o.file[boardID] = data unless boardID of o.file or boardID not in files
|
o.file[boardID] = data unless boardID of o.file or boardID not in files
|
||||||
o.report[boardID] = data unless boardID of o.report or not report
|
|
||||||
|
|
||||||
for boardID, record of Conf['selectedArchives']
|
for boardID, record of Conf['selectedArchives']
|
||||||
for type, id of record when (archive = archives[JSON.stringify id])
|
for type, id of record when (archive = archives[JSON.stringify id])
|
||||||
@ -154,10 +152,13 @@ Redirect =
|
|||||||
"#{boardID}/?task=search2&search_#{type}=#{value}"
|
"#{boardID}/?task=search2&search_#{type}=#{value}"
|
||||||
"#{Redirect.protocol archive}#{archive.domain}/#{path}"
|
"#{Redirect.protocol archive}#{archive.domain}/#{path}"
|
||||||
|
|
||||||
report: (archive, {boardID, postID}) ->
|
report: (boardID) ->
|
||||||
{report} = archive
|
urls = []
|
||||||
return '' unless /^https?:\/\//.test(report)
|
for archive in Conf['archives']
|
||||||
report.replace(/%board/g, boardID).replace(/%post/g, postID)
|
{software, https, reports, boards, name, domain} = archive
|
||||||
|
if software is 'foolfuuka' and https and reports and boards instanceof Array and boardID in boards
|
||||||
|
urls.push [name, "https://#{domain}/_/api/chan/offsite_report/"]
|
||||||
|
urls
|
||||||
|
|
||||||
securityCheck: (url) ->
|
securityCheck: (url) ->
|
||||||
/^https:\/\//.test(url) or
|
/^https:\/\//.test(url) or
|
||||||
|
|||||||
@ -5,27 +5,20 @@ ReportLink =
|
|||||||
a = $.el 'a',
|
a = $.el 'a',
|
||||||
className: 'report-link'
|
className: 'report-link'
|
||||||
href: 'javascript:;'
|
href: 'javascript:;'
|
||||||
|
textContent: 'Report'
|
||||||
$.on a, 'click', ReportLink.report
|
$.on a, 'click', ReportLink.report
|
||||||
|
|
||||||
Menu.menu.addEntry
|
Menu.menu.addEntry
|
||||||
el: a
|
el: a
|
||||||
order: 10
|
order: 10
|
||||||
open: (post) ->
|
open: (post) ->
|
||||||
unless post.isDead or (post.thread.isDead and not post.thread.isArchived)
|
ReportLink.url = "//sys.4chan.org/#{post.board}/imgboard.php?mode=report&no=#{post}"
|
||||||
a.textContent = 'Report'
|
if (Conf['Use Recaptcha v1 in Reports'] and Main.jsEnabled) or d.cookie.indexOf('pass_enabled=1') >= 0
|
||||||
ReportLink.url = "//sys.4chan.org/#{post.board}/imgboard.php?mode=report&no=#{post}"
|
ReportLink.url += '&altc=1'
|
||||||
if (Conf['Use Recaptcha v1 in Reports'] and Main.jsEnabled) or d.cookie.indexOf('pass_enabled=1') >= 0
|
ReportLink.dims = 'width=350,height=275'
|
||||||
ReportLink.url += '&altc=1'
|
|
||||||
ReportLink.dims = 'width=350,height=275'
|
|
||||||
else
|
|
||||||
ReportLink.dims = 'width=400,height=550'
|
|
||||||
else if Conf['Archive Report']
|
|
||||||
a.textContent = 'Report to archive'
|
|
||||||
ReportLink.url = Redirect.to 'report', {boardID: post.board.ID, postID: post.ID}
|
|
||||||
ReportLink.dims = 'width=700,height=475'
|
|
||||||
else
|
else
|
||||||
ReportLink.url = ''
|
ReportLink.dims = 'width=400,height=550'
|
||||||
!!ReportLink.url
|
true
|
||||||
|
|
||||||
report: ->
|
report: ->
|
||||||
{url, dims} = ReportLink
|
{url, dims} = ReportLink
|
||||||
|
|||||||
@ -10,16 +10,14 @@ Report =
|
|||||||
|
|
||||||
Report.archive() if Conf['Archive Report']
|
Report.archive() if Conf['Archive Report']
|
||||||
|
|
||||||
if not Conf['Use Recaptcha v1 in Reports'] and not Conf['Force Noscript Captcha'] and Main.jsEnabled
|
new MutationObserver(->
|
||||||
new MutationObserver(->
|
Report.fit 'iframe[src^="https://www.google.com/recaptcha/api2/frame"]'
|
||||||
Report.fit 'iframe[src^="https://www.google.com/recaptcha/api2/frame"]'
|
|
||||||
Report.fit 'body'
|
|
||||||
).observe d.body,
|
|
||||||
childList: true
|
|
||||||
attributes: true
|
|
||||||
subtree: true
|
|
||||||
else
|
|
||||||
Report.fit 'body'
|
Report.fit 'body'
|
||||||
|
).observe d.body,
|
||||||
|
childList: true
|
||||||
|
attributes: true
|
||||||
|
subtree: true
|
||||||
|
Report.fit 'body'
|
||||||
|
|
||||||
fit: (selector) ->
|
fit: (selector) ->
|
||||||
return if not ((el = $ selector, doc) and getComputedStyle(el).visibility isnt 'hidden')
|
return if not ((el = $ selector, doc) and getComputedStyle(el).visibility isnt 'hidden')
|
||||||
@ -27,24 +25,78 @@ Report =
|
|||||||
window.resizeBy 0, dy if dy > 0
|
window.resizeBy 0, dy if dy > 0
|
||||||
|
|
||||||
archive: ->
|
archive: ->
|
||||||
Redirect.init()
|
return unless (urls = Redirect.report g.BOARD.ID).length
|
||||||
return unless (url = Redirect.to 'report', {boardID: g.BOARD.ID, postID: Report.postID})
|
|
||||||
|
|
||||||
if (message = $ 'h3') and /Report submitted!/.test(message.textContent)
|
form = $ 'form'
|
||||||
if location.hash is '#redirect'
|
types = $.id 'reportTypes'
|
||||||
$.globalEval 'self.close = function(){};'
|
message = $ 'h3'
|
||||||
window.resizeTo 700, 475
|
|
||||||
Redirect.navigate 'report', {boardID: g.BOARD.ID, postID: Report.postID}
|
|
||||||
return
|
|
||||||
|
|
||||||
link = $.el 'a',
|
fieldset = $.el 'fieldset',
|
||||||
href: url
|
id: 'archive-report'
|
||||||
textContent: 'Report to archive'
|
hidden: true
|
||||||
$.on link, 'click', (e) ->
|
,
|
||||||
unless e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
|
<%= readHTML('ArchiveReport.html') %>
|
||||||
window.resizeTo 700, 475
|
enabled = $ '#archive-report-enabled', fieldset
|
||||||
$.add d.body, [$.tn(' ['), link, $.tn(']')]
|
reason = $ '#archive-report-reason', fieldset
|
||||||
|
submit = $ '#archive-report-submit', fieldset
|
||||||
|
|
||||||
if types = $.id('reportTypes')
|
if form and types
|
||||||
|
fieldset.hidden = !$('[value=illegal]', types).checked
|
||||||
$.on types, 'change', (e) ->
|
$.on types, 'change', (e) ->
|
||||||
$('form').action = if e.target.value is 'illegal' then '#redirect' else ''
|
fieldset.hidden = (e.target.value isnt 'illegal')
|
||||||
|
Report.fit 'body'
|
||||||
|
$.after types, fieldset
|
||||||
|
Report.fit 'body'
|
||||||
|
$.one form, 'submit', (e) ->
|
||||||
|
if !fieldset.hidden and enabled.checked
|
||||||
|
e.preventDefault()
|
||||||
|
Report.archiveSubmit urls, reason.value, (results) =>
|
||||||
|
@action = '#archiveresults=' + encodeURIComponent JSON.stringify results
|
||||||
|
@submit()
|
||||||
|
else if message
|
||||||
|
enabled.checked = false
|
||||||
|
fieldset.hidden = false
|
||||||
|
$.on enabled, 'change', ->
|
||||||
|
submit.hidden = !@checked
|
||||||
|
$.after message, fieldset
|
||||||
|
$.on submit, 'click', ->
|
||||||
|
Report.archiveSubmit urls, reason.value, Report.archiveResults
|
||||||
|
|
||||||
|
if (match = location.hash.match /^#archiveresults=(.*)$/)
|
||||||
|
try
|
||||||
|
Report.archiveResults JSON.parse decodeURIComponent match[1]
|
||||||
|
|
||||||
|
archiveSubmit: (urls, reason, cb) ->
|
||||||
|
form = $.formData
|
||||||
|
board: g.BOARD.ID
|
||||||
|
num: Report.postID
|
||||||
|
reason: reason
|
||||||
|
results = []
|
||||||
|
for [name, url] in urls
|
||||||
|
do (name, url) ->
|
||||||
|
$.ajax url,
|
||||||
|
responseType: 'json'
|
||||||
|
onloadend: ->
|
||||||
|
results.push [name, @response or {error: ''}]
|
||||||
|
if results.length is urls.length
|
||||||
|
cb results
|
||||||
|
,
|
||||||
|
{form}
|
||||||
|
return
|
||||||
|
|
||||||
|
archiveResults: (results) ->
|
||||||
|
fieldset = $.id 'archive-report'
|
||||||
|
for [name, response] in results
|
||||||
|
line = $.el 'h3',
|
||||||
|
className: 'archive-report-response'
|
||||||
|
if 'success' of response
|
||||||
|
$.addClass line, 'archive-report-success'
|
||||||
|
line.textContent = "#{name}: #{response.success}"
|
||||||
|
else
|
||||||
|
$.addClass line, 'archive-report-error'
|
||||||
|
line.textContent = "#{name}: #{response.error or 'Error reporting post.'}"
|
||||||
|
if fieldset
|
||||||
|
$.before fieldset, line
|
||||||
|
else
|
||||||
|
$.add d.body, line
|
||||||
|
return
|
||||||
|
|||||||
4
src/Miscellaneous/Report/ArchiveReport.html
Normal file
4
src/Miscellaneous/Report/ArchiveReport.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<legend><label><input id="archive-report-enabled" type="checkbox" checked>Report illegal content to archives</label></legend>
|
||||||
|
<label for="archive-report-reason">Details</label>
|
||||||
|
<textarea id="archive-report-reason">Illegal content</textarea>
|
||||||
|
<button id="archive-report-submit" hidden>Submit</button>
|
||||||
@ -5,3 +5,24 @@
|
|||||||
#captchaContainerAlt td:nth-child(2) {
|
#captchaContainerAlt td:nth-child(2) {
|
||||||
display: table-cell !important;
|
display: table-cell !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Archive reports */
|
||||||
|
#archive-report {
|
||||||
|
padding: 3px;
|
||||||
|
}
|
||||||
|
#archive-report-enabled {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
#archive-report > label {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
#archive-report-reason {
|
||||||
|
display: block;
|
||||||
|
width: 98%;
|
||||||
|
}
|
||||||
|
.archive-report-success {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
.archive-report-error {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user