file_list.lua 1.1 KB

1234567891011121314151617181920212223242526272829
  1. return function (connection, req, args)
  2. dofile("httpserver-header.lc")(connection, 200, 'html')
  3. connection:send([===[
  4. <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Server File Listing</title></head>
  5. <body>
  6. <h1>Server File Listing</h1>
  7. ]===])
  8. local remaining, used, total = file.fsinfo()
  9. connection:send("<b>Total size: </b> " .. total .. " bytes<br/>\n" ..
  10. "<b>In Use: </b> " .. used .. " bytes<br/>\n" ..
  11. "<b>Free: </b> " .. remaining .. " bytes<br/>\n")
  12. local flashAddress, flashSize = file.fscfg ()
  13. connection:send("<b>Flash Address: </b> " .. flashAddress .. " bytes<br/>\n" ..
  14. "<b>Flash Size: </b> " .. flashSize .. " bytes<br/>\n")
  15. connection:send("<b>Files:</b><br/>\n<ul>\n")
  16. for name, size in pairs(file.list()) do
  17. local isHttpFile = string.match(name, "(http/)") ~= nil
  18. if isHttpFile then
  19. local url = string.match(name, ".*/(.*)")
  20. connection:send(' <li><a href="' .. url .. '">' .. url .. "</a> (" .. size .. " bytes)</li>\n")
  21. end
  22. end
  23. connection:send("</ul>\n</body></html>")
  24. end