Remove temporary file with configurable delay

This commit is contained in:
Marcel van der Boom 2014-11-22 18:01:14 +01:00
parent 33353bf644
commit 221b368014
2 changed files with 13 additions and 2 deletions

View File

@ -29,6 +29,11 @@
function ok_cb(extra, success, result)
end
-- Callback to remove tmp files
function rmtmp_cb(file_path, success, result)
os.remove(file_path)
end
function msg_valid(msg)
if msg.text == nil then
return false
@ -145,7 +150,7 @@
return result
end
function download_to_file( url )
function download_to_file( url , noremove )
print("url to download: "..url)
req, c, h = http.request(url)
htype = h["content-type"]
@ -171,6 +176,11 @@
file = io.open(file_path, "w+")
file:write(req)
file:close()
if noremove~=nil then
postpone(rmtmp_cb, file_path, config.rmtmp_delay)
end
return file_path
end

View File

@ -1,4 +1,5 @@
{
"rmtmp_delay": 20,
"google_api_key": "",
"log_file": "/var/www/html/log.txt",
"sh_enabled": false,