1
0
mirror of https://github.com/kepler155c/opus synced 2026-06-02 10:42:10 +00:00

pastebin as an api

This commit is contained in:
kepler155c@gmail.com
2019-03-26 09:08:39 -04:00
parent ade354660f
commit 82f6d3451d
6 changed files with 249 additions and 10 deletions
+22 -9
View File
@@ -9,6 +9,8 @@ local multishell = _ENV.multishell
local os = _G.os
local shell = _ENV.shell
local FILE = 1
UI:configure('Files', ...)
local config = Config.load('Files', {
@@ -38,12 +40,13 @@ local Browser = UI.Page {
buttons = {
{ text = '^-', event = 'updir' },
{ text = 'File', dropdown = {
{ text = 'Run', event = 'run' },
{ text = 'Edit e', event = 'edit' },
{ text = 'Cloud edit c', event = 'cedit' },
{ text = 'Shell s', event = 'shell' },
{ text = 'Run', event = 'run', flags = FILE },
{ text = 'Edit e', event = 'edit', flags = FILE },
{ text = 'Cloud edit c', event = 'cedit', flags = FILE },
{ text = 'Pastebin put p', event = 'cedit', flags = FILE },
{ text = 'Shell s', event = 'shell' },
UI.MenuBar.spacer,
{ text = 'Quit q', event = 'quit' },
{ text = 'Quit q', event = 'quit' },
} },
{ text = 'Edit', dropdown = {
{ text = 'Cut ^x', event = 'cut' },
@@ -140,6 +143,7 @@ local Browser = UI.Page {
c = 'cedit',
e = 'edit',
s = 'shell',
p = 'pastebin',
r = 'refresh',
space = 'mark',
backspace = 'updir',
@@ -162,10 +166,8 @@ end
function Browser.menuBar:getActive(menuItem)
local file = Browser.grid:getSelected()
if file then
if menuItem.event == 'edit' or menuItem.event == 'run' then
return not file.isDir
end
if menuItem.flags == FILE then
return file and not file.isDir
end
return true
end
@@ -346,6 +348,7 @@ function Browser:eventHandler(event)
elseif event.type == 'cedit' and file then
self:run('cedit', file.name)
self:setStatus('Started cloud edit')
elseif event.type == 'shell' then
self:run('sys/apps/shell.lua')
@@ -358,6 +361,16 @@ function Browser:eventHandler(event)
elseif event.type == 'associate' then
self.associations:show()
elseif event.type == 'pastebin' then
if file and not file.isDir then
local s, m = pastebin.put(file.fullName)
if s then
self.notification:success(string.format('Uploaded as %s', m), 0)
else
self.notification:error(m)
end
end
elseif event.type == 'toggle_hidden' then
config.showHidden = not config.showHidden
Config.update('Files', config)
+75
View File
@@ -0,0 +1,75 @@
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
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
local success, msg = pastebin.put(sFile)
if success then
print( "Uploaded as "..msg )
print( "Run \"pastebin get "..msg.."\" to download anywhere" )
else
print( msg )
end
elseif sCommand == "get" then
-- Download a file from pastebin.com
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
local success, msg = pastebin.get(sCode, sPath)
if success then
print( "Downloaded as "..sFile )
else
print(msg)
end
elseif sCommand == "run" then
local sCode = tArgs[2]
local success, msg = pastebin.run(sCode, table.unpack(tArgs, 3))
if not success then
print(msg)
end
else
printUsage()
return
end
+2
View File
@@ -4,6 +4,8 @@ local UI = require('ui')
local colors = _G.colors
-- -t80x30
if _G.http.websocket then
local config = Config.load('cloud')