Advertisement
DOGGYWOOF

Recovery Pocket server

Feb 19th, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. -- Doggy OS Pocket Recovery Server
  2.  
  3. local diskPath = "/disk/"
  4. local recoveryPath = "/recovery/"
  5.  
  6. local function handleRequest(path, response)
  7. local fullPath = shell.resolve(path)
  8.  
  9. if fs.exists(fullPath) then
  10. local file = fs.open(fullPath, "r")
  11. response.write(file.readAll())
  12. file.close()
  13. else
  14. response.setStatus(404)
  15. response.write("File not found.")
  16. end
  17. end
  18.  
  19. local function startServer()
  20. local modemSide = "back" -- Change this to the side where the modem is connected
  21. local modem = peripheral.wrap(modemSide)
  22.  
  23. local serverID = os.getComputerID()
  24.  
  25. print("Doggy OS Pocket Recovery Server")
  26. print("ID: " .. serverID)
  27.  
  28. while true do
  29. local event, modemSide, senderChannel, replyChannel, message = os.pullEvent("modem_message")
  30. if senderChannel == tonumber(serverID) then
  31. if message == "GET /disk/" then
  32. handleRequest(diskPath, modem)
  33. elseif message == "GET /recovery/" then
  34. handleRequest(recoveryPath, modem)
  35. end
  36. end
  37. end
  38. end
  39.  
  40. startServer()
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement