-
Notifications
You must be signed in to change notification settings - Fork 3
/
market.cc.lua
107 lines (104 loc) · 3.19 KB
/
market.cc.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--Market by: TurtleScripts.com
--This is a modified version of the PasteBin script to work directly with TurtleScript project files.
local tArgs = { ... }
local function printUsage()
term.clear()
term.setCursorPos(1,1)
print( "TurtleMarket v1.0 BETA [#gjdgyl]" )
print( "-------------------------------------------------" )
print( "by: TurtleScripts.com (update file_key: #gjdgz7)" )
print( " " )
print( "Usages:" )
print( " ==UPLOAD==" )
print( " market put (file_key) (filename) (write_pin)" )
print( " [pin req'd]" )
print( " ==DOWNLOAD==" )
print( " market get (file_key) (filename) (read_pin) [y]" )
print( " [pin req'd for private/drafts]" )
print( " " )
end
local function putFile(sCode, sFile, sPin, sOverride)
local sPath = shell.resolve( sFile )
if not fs.exists( sPath ) or fs.isDir( sPath ) then
print( "No such file" )
return
end
local sName = fs.getName( sPath )
local file = fs.open( sPath, "r" )
local sText = file.readAll()
file.close()
write( "Connecting to TurtleScripts.com... " )
local response = http.post("http://api.turtlescripts.com/putFileRaw/"..textutils.urlEncode( sCode ),"pin="..sPin.."&".."data="..textutils.urlEncode(sText))
if response then
print( "Success." )
local sResponse = response.readAll()
response.close()
print( " " )
print( "Local: "..sFile )
print( "Remote: #"..sCode )
print( "[==========================================] 100%" )
print(string.len(sText).." bytes")
print( " " )
print( "Upload Complete." )
else
print( "Failed." )
print( " " )
print( "ERROR: The file key is bad or project pin is wrong." )
end
end
local function getFile(sCode, sFile, sPin, sOverride)
local sPath = shell.resolve( sFile )
if sCode == "" then
print( "You must specify a File Key from TurtleScripts.com!" )
return
end
if sFile == "" then
print( "You must specify a Filename to write to!" )
return
end
if fs.exists( sPath ) then
print( "File already exists" )
if sOverride == "" and (sPin ~= "y" or sOverride ~= "") then
return
end
end
write( "Connecting to TurtleScripts.com... " )
local response = http.post("http://api.turtlescripts.com/getFileRaw/"..textutils.urlEncode( sCode ),"pin="..sPin)
if response then
print( "Success." )
local sResponse = response.readAll()
response.close()
local file = fs.open( sPath, "w" )
file.write( sResponse )
file.close()
print( " " )
print( "Remote: #"..sCode )
print( "Local: "..sFile )
print( "[==========================================] 100%" )
print(string.len(sResponse).." bytes")
print( " " )
print( "Downloaded Complete." )
else
print( "Failed." )
print( " " )
print( "ERROR: The file key is bad or project is private (in which case, did you specify your project pin??)." )
end
end
local gui_mode = false
if #tArgs < 3 then
printUsage()
return
end
local sCommand = tArgs[1]
local sCode = tArgs[2] or ""
local sFile = tArgs[3] or ""
local sPin = tArgs[4] or ""
if sCommand == "put" then
putFile(sCode, sFile, sPin)
elseif sCommand == "get" then
local sOverride = tArgs[5] or ""
getFile(sCode, sFile, sPin, sOverride)
else
printUsage()
return
end