Mercurial > prosody-hg
comparison plugins/mod_http_files.lua @ 13873:8525b7c7ba6c
mod_http_files: Replace public API with errors
Modules wishing to serve files directly from the file system should be
using net.http.files instead, as per the error.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 13 May 2025 22:38:30 +0200 |
| parents | 50324f66ca2a |
| children | bfa8ac5881a0 |
comparison
equal
deleted
inserted
replaced
| 13872:76582d10bc09 | 13873:8525b7c7ba6c |
|---|---|
| 53 if not info then return "An unknown module"; end | 53 if not info then return "An unknown module"; end |
| 54 return info.source:match"mod_[^/\\.]+" or info.short_src; | 54 return info.source:match"mod_[^/\\.]+" or info.short_src; |
| 55 end | 55 end |
| 56 | 56 |
| 57 -- COMPAT -- TODO deprecate | 57 -- COMPAT -- TODO deprecate |
| 58 function serve(opts) | 58 function serve() |
| 59 if type(opts) ~= "table" then -- assume path string | 59 error(string.format("%s should be updated to use 'prosody.net.http.files' instead of mod_http_files", get_calling_module())); |
| 60 opts = { path = opts }; | |
| 61 end | |
| 62 if opts.directory_index == nil then | |
| 63 opts.directory_index = directory_index; | |
| 64 end | |
| 65 if opts.mime_map == nil then | |
| 66 opts.mime_map = mime_map; | |
| 67 end | |
| 68 if opts.cache_size == nil then | |
| 69 opts.cache_size = cache_size; | |
| 70 end | |
| 71 if opts.cache_max_file_size == nil then | |
| 72 opts.cache_max_file_size = cache_max_file_size; | |
| 73 end | |
| 74 if opts.index_files == nil then | |
| 75 opts.index_files = dir_indices; | |
| 76 end | |
| 77 module:log("warn", "%s should be updated to use 'prosody.net.http.files' instead of mod_http_files", get_calling_module()); | |
| 78 return fileserver.serve(opts); | |
| 79 end | 60 end |
| 80 | 61 |
| 81 function wrap_route(routes) | 62 function wrap_route() |
| 82 module:log("debug", "%s should be updated to use 'prosody.net.http.files' instead of mod_http_files", get_calling_module()); | 63 error(string.format("%s should be updated to use 'prosody.net.http.files' instead of mod_http_files", get_calling_module())); |
| 83 for route,handler in pairs(routes) do | |
| 84 if type(handler) ~= "function" then | |
| 85 routes[route] = fileserver.serve(handler); | |
| 86 end | |
| 87 end | |
| 88 return routes; | |
| 89 end | 64 end |
| 90 | 65 |
| 91 module:provides("http", { | 66 module:provides("http", { |
| 92 route = { | 67 route = { |
| 93 ["GET /*"] = fileserver.serve({ | 68 ["GET /*"] = fileserver.serve({ |
