1
0

aserv.rb 860 B

1234567891011121314151617181920212223242526272829303132333435
  1. require "webrick"
  2. #
  3. # Dummy asset server
  4. #
  5. class AssetServlet < WEBrick::HTTPServlet::AbstractServlet
  6. def do_GET(req, res)
  7. uuid = req.path.split("/")[2].downcase.gsub(/[^0-9a-f]+/, "")
  8. if uuid.length == 32
  9. # length is correct
  10. File.open("assets/#{uuid}/data") do |f|
  11. res.body = f.read
  12. end
  13. end
  14. # res["content-type"] = "text/plain" # or what do we set it to ?
  15. end
  16. def do_POST(req, res)
  17. uuid = req.path.split("/")[2].downcase.gsub(/[^0-9a-f]+/, "")
  18. if uuid.length == 32
  19. Dir.mkdir("assets/#{uuid}")
  20. File.open("assets/#{uuid}/data", "wb") do |f|
  21. f.write req.body
  22. STDERR.print "Written #{req.body.length} bytes for uuid #{uuid}\n\n"
  23. end
  24. end
  25. end
  26. end
  27. svr = WEBrick::HTTPServer.new(:Port=>8003)
  28. svr.mount("/assets", AssetServlet, 5000000)
  29. trap(:INT){ svr.shutdown }
  30. svr.start