1
0
mirror of https://github.com/kepler155c/opus synced 2024-06-18 11:20:01 +00:00
opus/sys/apps/pastebin.lua

86 lines
1.8 KiB
Lua
Raw Normal View History

2019-03-26 13:08:39 +00:00
local function printUsage()
print( "Usages:" )
print( "pastebin put <filename>" )
print( "pastebin get <code> <filename>" )
print( "pastebin run <code> <arguments>" )
end
local tArgs = { ... }
if #tArgs < 2 then
printUsage()
return
end
if not http then
printError( "Pastebin requires http API" )
printError( "Set http_enable to true in ComputerCraft.cfg" )
return
end
2019-04-11 12:41:23 +00:00
local pastebin = require('http.pastebin')
2019-03-26 13:08:39 +00:00
local sCommand = tArgs[1]
if sCommand == "put" then
-- Upload a file to pastebin.com
-- Determine file to upload
local sFile = tArgs[2]
local sPath = shell.resolve( sFile )
if not fs.exists( sPath ) or fs.isDir( sPath ) then
print( "No such file" )
return
end
2019-04-11 12:41:23 +00:00
print( "Connecting to pastebin.com... " )
local resp, msg = pastebin.put(sFile)
2019-03-26 13:08:39 +00:00
2019-04-11 12:41:23 +00:00
if resp then
2019-03-26 13:08:39 +00:00
print( "Uploaded as "..msg )
2019-04-11 12:41:23 +00:00
print( "Run \"pastebin get "..resp.."\" to download anywhere" )
2019-03-26 13:08:39 +00:00
else
2019-04-11 12:41:23 +00:00
printError( msg )
2019-03-26 13:08:39 +00:00
end
elseif sCommand == "get" then
-- Download a file from pastebin.com
if #tArgs < 3 then
printUsage()
return
end
2019-04-11 12:41:23 +00:00
print( "Connecting to pastebin.com... " )
2019-03-26 13:08:39 +00:00
-- Determine file to download
local sCode = tArgs[2]
local sFile = tArgs[3]
local sPath = shell.resolve( sFile )
if fs.exists( sPath ) then
2019-04-11 12:41:23 +00:00
printError( "File already exists" )
2019-03-26 13:08:39 +00:00
return
end
2019-04-11 12:41:23 +00:00
local resp, msg = pastebin.get(sCode, sPath)
2019-03-26 13:08:39 +00:00
2019-04-11 12:41:23 +00:00
if resp then
print( "Downloaded as "..resp )
2019-03-26 13:08:39 +00:00
else
2019-04-11 12:41:23 +00:00
printError( msg )
2019-03-26 13:08:39 +00:00
end
2019-04-11 12:41:23 +00:00
2019-03-26 13:08:39 +00:00
elseif sCommand == "run" then
local sCode = tArgs[2]
2019-04-11 12:41:23 +00:00
print( "Connecting to pastebin.com... " )
local resp, msg = pastebin.run(sCode, table.unpack(tArgs, 3))
if not resp then
printError( msg )
2019-03-26 13:08:39 +00:00
end
else
2019-04-11 12:41:23 +00:00
2019-03-26 13:08:39 +00:00
printUsage()
return
end