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: {}
|
||||
post: {}
|
||||
file: {}
|
||||
report: {}
|
||||
|
||||
archives = {}
|
||||
for data in Conf['archives']
|
||||
for key in ['boards', 'files']
|
||||
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']
|
||||
archives[JSON.stringify(uid ? name)] = data
|
||||
for boardID in boards
|
||||
o.thread[boardID] = data unless boardID of o.thread
|
||||
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.report[boardID] = data unless boardID of o.report or not report
|
||||
|
||||
for boardID, record of Conf['selectedArchives']
|
||||
for type, id of record when (archive = archives[JSON.stringify id])
|
||||
@ -154,10 +152,13 @@ Redirect =
|
||||
"#{boardID}/?task=search2&search_#{type}=#{value}"
|
||||
"#{Redirect.protocol archive}#{archive.domain}/#{path}"
|
||||
|
||||
report: (archive, {boardID, postID}) ->
|
||||
{report} = archive
|
||||
return '' unless /^https?:\/\//.test(report)
|
||||
report.replace(/%board/g, boardID).replace(/%post/g, postID)
|
||||
report: (boardID) ->
|
||||
urls = []
|
||||
for archive in Conf['archives']
|
||||
{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) ->
|
||||
/^https:\/\//.test(url) or
|
||||
|
||||
@ -5,27 +5,20 @@ ReportLink =
|
||||
a = $.el 'a',
|
||||
className: 'report-link'
|
||||
href: 'javascript:;'
|
||||
textContent: 'Report'
|
||||
$.on a, 'click', ReportLink.report
|
||||
|
||||
Menu.menu.addEntry
|
||||
el: a
|
||||
order: 10
|
||||
open: (post) ->
|
||||
unless post.isDead or (post.thread.isDead and not post.thread.isArchived)
|
||||
a.textContent = 'Report'
|
||||
ReportLink.url = "//sys.4chan.org/#{post.board}/imgboard.php?mode=report&no=#{post}"
|
||||
if (Conf['Use Recaptcha v1 in Reports'] and Main.jsEnabled) or d.cookie.indexOf('pass_enabled=1') >= 0
|
||||
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'
|
||||
ReportLink.url = "//sys.4chan.org/#{post.board}/imgboard.php?mode=report&no=#{post}"
|
||||
if (Conf['Use Recaptcha v1 in Reports'] and Main.jsEnabled) or d.cookie.indexOf('pass_enabled=1') >= 0
|
||||
ReportLink.url += '&altc=1'
|
||||
ReportLink.dims = 'width=350,height=275'
|
||||
else
|
||||
ReportLink.url = ''
|
||||
!!ReportLink.url
|
||||
ReportLink.dims = 'width=400,height=550'
|
||||
true
|
||||
|
||||
report: ->
|
||||
{url, dims} = ReportLink
|
||||
|
||||
@ -10,16 +10,14 @@ 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(->
|
||||
Report.fit 'iframe[src^="https://www.google.com/recaptcha/api2/frame"]'
|
||||
Report.fit 'body'
|
||||
).observe d.body,
|
||||
childList: true
|
||||
attributes: true
|
||||
subtree: true
|
||||
else
|
||||
new MutationObserver(->
|
||||
Report.fit 'iframe[src^="https://www.google.com/recaptcha/api2/frame"]'
|
||||
Report.fit 'body'
|
||||
).observe d.body,
|
||||
childList: true
|
||||
attributes: true
|
||||
subtree: true
|
||||
Report.fit 'body'
|
||||
|
||||
fit: (selector) ->
|
||||
return if not ((el = $ selector, doc) and getComputedStyle(el).visibility isnt 'hidden')
|
||||
@ -27,24 +25,78 @@ Report =
|
||||
window.resizeBy 0, dy if dy > 0
|
||||
|
||||
archive: ->
|
||||
Redirect.init()
|
||||
return unless (url = Redirect.to 'report', {boardID: g.BOARD.ID, postID: Report.postID})
|
||||
return unless (urls = Redirect.report g.BOARD.ID).length
|
||||
|
||||
if (message = $ 'h3') and /Report submitted!/.test(message.textContent)
|
||||
if location.hash is '#redirect'
|
||||
$.globalEval 'self.close = function(){};'
|
||||
window.resizeTo 700, 475
|
||||
Redirect.navigate 'report', {boardID: g.BOARD.ID, postID: Report.postID}
|
||||
return
|
||||
form = $ 'form'
|
||||
types = $.id 'reportTypes'
|
||||
message = $ 'h3'
|
||||
|
||||
link = $.el 'a',
|
||||
href: url
|
||||
textContent: 'Report to archive'
|
||||
$.on link, 'click', (e) ->
|
||||
unless e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
|
||||
window.resizeTo 700, 475
|
||||
$.add d.body, [$.tn(' ['), link, $.tn(']')]
|
||||
fieldset = $.el 'fieldset',
|
||||
id: 'archive-report'
|
||||
hidden: true
|
||||
,
|
||||
<%= readHTML('ArchiveReport.html') %>
|
||||
enabled = $ '#archive-report-enabled', fieldset
|
||||
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) ->
|
||||
$('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) {
|
||||
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