daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main = "http://cloud.welcomer.fun:2082"
  2. fallback = "http://192.187.100.194:2082"
  3. os.loadAPI("json")
  4.  
  5. _G.ccloud = {}
  6. _G.ccloud.username = ""
  7. _G.ccloud.token = ""
  8. _G.ccloud.id = ""
  9. _G.ccloud.fallback = true
  10.  
  11. function _G.ccloud.post(_sPath,_sData,_tHeader)
  12.     local _URL
  13.     local _HTTP_HANDLE
  14.     local _HTTP_RETURN
  15.     if _G.ccloud.fallback == true then
  16.         _URL = fallback .. _sPath
  17.     else
  18.         _URL = main .. _sPath
  19.     end
  20.     _HTTP_HANDLE = http.post(_URL,_sData,_tHeader)
  21.     if _HTTP_HANDLE == nil then
  22.         if _G.ccloud.fallback == true then
  23.             return '{"error": true, "reason": "Unable to contact the server"}'
  24.         end
  25.         _G.ccloud.fallback = true
  26.         return _G.ccloud.post(_sPath,_sData,_tHeader)
  27.     else
  28.         _HTTP_RETURN = _HTTP_HANDLE.readAll()
  29.         _HTTP_HANDLE.close()
  30.         return _HTTP_RETURN
  31.     end
  32. end
  33.  
  34. function _G.ccloud.login(_sUsername,_sPassword)
  35.     local _RETURN_DEC
  36.     local _HTTP_RETURN
  37.     _HTTP_RETURN = _G.ccloud.post("go","username=" .. _sUsername .. "&password=" .. _sPassword,{})
  38.     _RETURN_DEC = json.decode(_HTTP_RETURN)
  39.     if _RETURN_DEC['error'] == true then
  40.         return false, _RETURN_DEC['reason']
  41.     else
  42.         _G.ccloud.username = _sUsername
  43.         _G.ccloud.id = _RETURN_DEC['id']
  44.         _G.ccloud.token =  _RETURN_DEC['token']
  45.         return true, _RETURN_DEC['id']
  46.     end
  47. end
  48.  
  49. function _G.ccloud.directory(_sPath)
  50.     local _RETURN_DEC
  51.     local _HTTP_RETURN
  52.     local _HEADER = {}
  53.     _HEADER['Authorization'] = _G.ccloud.token
  54.     _HTTP_RETURN = _G.ccloud.post("dir","path=" .. _sPath,_HEADER)
  55.     _RETURN_DEC = json.decode(_HTTP_RETURN)
  56.     if _RETURN_DEC['error'] == true then
  57.         return false, _RETURN_DEC['reason']
  58.     else
  59.         return true, _RETURN_DEC['content']
  60.     end
  61. end
  62.  
  63. function _G.ccloud.getsize(_sPath)
  64.     local _RETURN_DEC
  65.     local _HTTP_RETURN
  66.     local _HEADER = {}
  67.     _HEADER['Authorization'] = _G.ccloud.token
  68.     _HTTP_RETURN = _G.ccloud.post("size","path=" .. _sPath,_HEADER)
  69.     _RETURN_DEC = json.decode(_HTTP_RETURN)
  70.     if _RETURN_DEC['error'] == true then
  71.         return false, _RETURN_DEC['reason']
  72.     else
  73.         return true, _RETURN_DEC['size']
  74.     end
  75. end
  76.  
  77. function _G.ccloud.getfile(_sPath)
  78.     local _RETURN_DEC
  79.     local _HTTP_RETURN
  80.     local _HEADER = {}
  81.     _HEADER['Authorization'] = _G.ccloud.token
  82.     _HTTP_RETURN = _G.ccloud.post("get","path=" .. _sPath,_HEADER)
  83.     _RETURN_DEC = json.decode(_HTTP_RETURN)
  84.     if _RETURN_DEC['error'] == true then
  85.         return false, _RETURN_DEC['reason']
  86.     else
  87.         return true, _RETURN_DEC['content']
  88.     end
  89. end
  90.  
  91. function _G.ccloud.deletefile(_sPath)
  92.     local _RETURN_DEC
  93.     local _HTTP_RETURN
  94.     local _HEADER = {}
  95.     _HEADER['Authorization'] = _G.ccloud.token
  96.     _HTTP_RETURN = _G.ccloud.post("delete","path=" .. _sPath,_HEADER)
  97.     _RETURN_DEC = json.decode(_HTTP_RETURN)
  98.     if _RETURN_DEC['error'] == true then
  99.         return false, _RETURN_DEC['reason']
  100.     else
  101.         return true, ""
  102.     end
  103. end
  104.  
  105. function _G.ccloud.uploadfile(_sPath,_sUploadFrom)
  106.     local _RETURN_DEC
  107.     local _HTTP_RETURN
  108.     local _FILE_DATA
  109.     local _HEADER = {}
  110.     local _FILE = fs.open(_sUploadFrom,"r")
  111.     _FILE_DATA = _FILE.readAll()
  112.     _FILE.close()
  113.     _HEADER['Authorization'] = _G.ccloud.token
  114.     _HTTP_RETURN = _G.ccloud.post("upload","path=" .. _sPath .. "&data=" .. textutils.urlEncode(_FILE_DATA),_HEADER)
  115.     _RETURN_DEC = json.decode(_HTTP_RETURN)
  116.     if _RETURN_DEC['error'] == true then
  117.         return false, _RETURN_DEC['reason']
  118.     else
  119.         return true, ""
  120.     end
  121. end
  122.  
  123. function _G.ccloud.uploadstring(_sPath,_sString)
  124.     local _RETURN_DEC
  125.     local _HTTP_RETURN
  126.     local _HEADER = {}
  127.     _HEADER['Authorization'] = _G.ccloud.token
  128.     _HTTP_RETURN = _G.ccloud.post("upload","path=" .. _sPath .. "&data=" .. textutils.urlEncode(_sString),_HEADER)
  129.     _RETURN_DEC = json.decode(_HTTP_RETURN)
  130.     if _RETURN_DEC['error'] == true then
  131.         return false, _RETURN_DEC['reason']
  132.     else
  133.         return true, ""
  134.     end
  135. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top