This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ComputerCraftFan11's profile picture

[HTTP] RDNT Database API

Started by ComputerCraftFan11, 26 August 2012 - 08:55 PM
ComputerCraftFan11 #1
Posted 26 August 2012 - 10:55 PM
Hello, If you would like to connect to the rednet database, here is a updated API to make it easier:

local WebsiteDatabase = "http://www.ccnet.netau.net/php/folder/" --Folder with all the sites
local ApiPath = "http://www.ccnet.netau.net/php/mcmain.php" --Path API is stored
function upload(path, domain, debug, user, pass)
if user and pass then else
  user = "guest"
  pass = "guest"
end

if fs.exists(path) then
  file = fs.open(path, "r")
  if file then
   data = file.readAll()
   file.close()
   if not data then
    print("Failed to read " ..path)
    return
   end
   local response = http.post(
   ApiPath,
   "type=upload&"..
   "user=guest&"..
   "pass=guest&"..
   "name=".. textutils.urlEncode(domain) .. "&"..
   "data=".. textutils.urlEncode(data.. " --[[")
   )
	 
   if response then
    local sResponse = response.readAll()
    response.close()
    print("Done!")
    print("Log: ")
    sleep(0.5)
    if sResponse == "success" then
	 if debug then
	  print("Uploading " ..shell.resolve(path).. " complete!")
	  print("Errors: 0")
	  print("\nGo to " ..domain.. " to check the site!")
	 end
	 return sResponse
    else
	 if debug then
	  print("Failed : " ..sResponse)
	 end
	 return sResponse
    end
   else
    if debug then
	 print("Failed to connect to database.")
    end
   end
  else
   if debug then
    print("Failed to open " ..path)
   end
  end
else
  if debug then
   print(path.. " doesn't exist.")
  end
end
end
function delete(path, user, pass)
local response = http.post(
ApiPath,
"type=delete&"..
"user=" ..user.. "&"..
"pass=" ..pass.. "&"..
"name=".. textutils.urlEncode(path)
)

return response.readAll()
end
function lister()
local response = http.post(
ApiPath,
"type=list&"..
"user=guest&"..
"pass=guest"
)

return response.readAll()
end
[/CODE]
There is currently no download(), you will have to check rednet_Explorer for that.
justync7 #2
Posted 26 August 2012 - 11:24 PM
Dont make this public, then people will spam it D: