1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Use stderr for pastebin errors, and a prettier cache buster

This commit is contained in:
Drew Lemmy 2019-02-24 19:59:10 +00:00
parent bd04a93ffb
commit 7fde89ad95

View File

@ -21,8 +21,8 @@ end
local function get(paste)
write( "Connecting to pastebin.com... " )
-- Add a cache buster so that spam protection is re-checked
local cacheBuster = tostring(math.random())
local response = http.get(
local cacheBuster = ("%x"):format(math.random(0, 2^30))
local response, err = http.get(
"https://pastebin.com/raw/"..textutils.urlEncode( paste ).."?cb="..cacheBuster
)
@ -30,7 +30,8 @@ local function get(paste)
-- 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
printError( "\nFailed to get paste. Please complete the captcha in a web browser: https://pastebin.com/"..textutils.urlEncode( paste ) )
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
@ -40,7 +41,8 @@ local function get(paste)
response.close()
return sResponse
else
print( "Failed." )
io.stderr:write( "Failed.\n" )
print(err)
end
end
@ -76,6 +78,8 @@ if sCommand == "put" then
if response then
print( "Success." )
print(response.getResponseHeaders())
local sResponse = response.readAll()
response.close()