Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function printUsage()
- print( "Usages:" )
- print( "vortex get <code> <filename>" )
- end
- local tArgs = { ... }
- if #tArgs < 2 then
- printUsage()
- return
- end
- if not http then
- print( "vortex requires http API" )
- print( "Set enableAPI_http to 1 in mod_ComputerCraft.cfg" )
- return
- end
- local sCommand = tArgs[1]
- if sCommand == "get" then
- -- Download a file from vortex
- if #tArgs < 3 then
- printUsage()
- return
- end
- -- Determine file to download
- local sCode = tArgs[2]
- local sFile = tArgs[3]
- local sPath = shell.resolve( sFile )
- if fs.exists( sPath ) then
- print( "File already exists" )
- return
- end
- -- GET the contents from vortex
- write( "Connecting to vortex... " )
- http.request("https://vortexcdn.64i.de/"..textutils.urlEncode( sCode ))
- event, url, response = os.pullEvent()
- if (event == "http_success") then
- print( "Success." )
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( sPath, "w" )
- file.write( sResponse )
- file.close()
- print( "Downloaded as "..sFile )
- else
- print( "Failed." )
- end
- else
- printUsage()
- return
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement