SHARE
TWEET

Untitled

angrytuberslp May 20th, 2019 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function printUsage()
  2.     print( "Usages:" )
  3.     print( "vortex get <code> <filename>" )
  4. end
  5.  
  6. local tArgs = { ... }
  7. if #tArgs < 2 then
  8.     printUsage()
  9.     return
  10. end
  11.  
  12. if not http then
  13.     print( "vortex requires http API" )
  14.     print( "Set enableAPI_http to 1 in mod_ComputerCraft.cfg" )
  15.     return
  16. end
  17.  
  18. local sCommand = tArgs[1]
  19. if sCommand == "get" then
  20.     -- Download a file from vortex
  21.     if #tArgs < 3 then
  22.         printUsage()
  23.         return
  24.     end
  25.  
  26.     -- Determine file to download
  27.     local sCode = tArgs[2]
  28.     local sFile = tArgs[3]
  29.     local sPath = shell.resolve( sFile )
  30.     if fs.exists( sPath ) then
  31.         print( "File already exists" )
  32.         return
  33.     end
  34.    
  35.     -- GET the contents from vortex
  36.     write( "Connecting to vortex... " )
  37.     http.request("https://vortexcdn.64i.de/"..textutils.urlEncode( sCode ))
  38.        
  39.     event, url, response = os.pullEvent()
  40.     if (event == "http_success") then
  41.         print( "Success." )
  42.        
  43.         local sResponse = response.readAll()
  44.         response.close()
  45.        
  46.         local file = fs.open( sPath, "w" )
  47.         file.write( sResponse )
  48.         file.close()
  49.        
  50.         print( "Downloaded as "..sFile )
  51.        
  52.     else
  53.         print( "Failed." )
  54.     end
  55.  
  56. else
  57.     printUsage()
  58.     return
  59. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top