1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-09-27 14:48:20 +00:00

Handle Pastebin spam protection and add a cache buster (#127)

This commit is contained in:
SquidDev 2019-02-24 20:06:02 +00:00 committed by GitHub
commit 162fb37421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,18 +20,29 @@ end
local function get(paste) local function get(paste)
write( "Connecting to pastebin.com... " ) write( "Connecting to pastebin.com... " )
local response = http.get( -- Add a cache buster so that spam protection is re-checked
"https://pastebin.com/raw/"..textutils.urlEncode( paste ) local cacheBuster = ("%x"):format(math.random(0, 2^30))
local response, err = http.get(
"https://pastebin.com/raw/"..textutils.urlEncode( paste ).."?cb="..cacheBuster
) )
if response then if response then
-- If spam protection is activated, we get redirected to /paste with Content-Type: text/html
local headers = response.getResponseHeaders()
if not headers["Content-Type"] or not headers["Content-Type"]:find( "^text/plain" ) then
io.stderr:write( "Failed.\n" )
print( "Pastebin blocked the download due to spam protection. Please complete the captcha in a web browser: https://pastebin.com/"..textutils.urlEncode( paste ) )
return
end
print( "Success." ) print( "Success." )
local sResponse = response.readAll() local sResponse = response.readAll()
response.close() response.close()
return sResponse return sResponse
else else
print( "Failed." ) io.stderr:write( "Failed.\n" )
print(err)
end end
end end