luci-app-nlbwmon: add proper file names for json and csv exports.
authorAmeer Dawood <ameer1234567890@gmail.com>
Mon, 23 Jul 2018 19:41:33 +0000 (00:41 +0500)
committerJo-Philipp Wich <jo@mein.io>
Sat, 29 Sep 2018 12:59:42 +0000 (14:59 +0200)
Currently, the json and csv exports are just named `data` which is not
intuitive. This adds proper file name extensions using the
Content-disposition HTTP header.

Suggested-by: Ameer Dawood <ameer1234567890@gmail.com>
[slightly reword commit message, squash commits]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua

index a8c577929ab93f6cf732ec06edd3eb88d4f90eee..72e87e8f90579f2e028caf15edbde56fe73be495 100644 (file)
@@ -57,6 +57,8 @@ function action_data()
                json = "application/json"
        }
 
+       local filename = "data." .. mtype
+
        local args = { }
        local mtype = http.formvalue("type") or "json"
        local delim = http.formvalue("delim") or ";"
@@ -92,6 +94,7 @@ function action_data()
        end
 
        http.prepare_content(types[mtype])
+       http.header("Content-Disposition", "attachment; filename=\"%s\"" % filename)
        exec("/usr/sbin/nlbw", args, http.write)
 end