Mercurial > prosody-modules
comparison mod_http_upload/mod_http_upload.lua @ 2691:92ddfc548ce8
mod_http_upload: Store filename and directory separately
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 15 Apr 2017 15:55:39 +0200 |
| parents | 43ad92c5b91a |
| children | 785465f8af3d |
comparison
equal
deleted
inserted
replaced
| 2690:43ad92c5b91a | 2691:92ddfc548ce8 |
|---|---|
| 79 if not uploads then return true; end | 79 if not uploads then return true; end |
| 80 uploads = array(uploads); | 80 uploads = array(uploads); |
| 81 local expiry = os.time() - max_age; | 81 local expiry = os.time() - max_age; |
| 82 local upload_window = os.time() - 900; | 82 local upload_window = os.time() - 900; |
| 83 uploads:filter(function (item) | 83 uploads:filter(function (item) |
| 84 local filename = item.filename; | |
| 85 if item.dir then | |
| 86 filename = join_path(storage_path, item.dir, item.filename); | |
| 87 end | |
| 84 if item.time < expiry then | 88 if item.time < expiry then |
| 85 local deleted, whynot = os.remove(item.filename); | 89 local deleted, whynot = os.remove(filename); |
| 86 if not deleted then | 90 if not deleted then |
| 87 module:log("warn", "Could not delete expired upload %s: %s", item.filename, whynot or "delete failed"); | 91 module:log("warn", "Could not delete expired upload %s: %s", filename, whynot or "delete failed"); |
| 88 end | 92 end |
| 89 return false; | 93 return false; |
| 90 elseif item.time < upload_window and not lfs.attributes(item.filename) then | 94 elseif item.time < upload_window and not lfs.attributes(filename) then |
| 91 return false; -- File was not uploaded or has been deleted since | 95 return false; -- File was not uploaded or has been deleted since |
| 92 end | 96 end |
| 93 return true; | 97 return true; |
| 94 end); | 98 end); |
| 95 return datamanager.list_store(username, host, module.name, uploads); | 99 return datamanager.list_store(username, host, module.name, uploads); |
| 159 repeat random_dir = uuid(); | 163 repeat random_dir = uuid(); |
| 160 until lfs.mkdir(join_path(storage_path, random_dir)) | 164 until lfs.mkdir(join_path(storage_path, random_dir)) |
| 161 or not lfs.attributes(join_path(storage_path, random_dir, filename)) | 165 or not lfs.attributes(join_path(storage_path, random_dir, filename)) |
| 162 | 166 |
| 163 local ok = datamanager.list_append(username, host, module.name, { | 167 local ok = datamanager.list_append(username, host, module.name, { |
| 164 filename = join_path(storage_path, random_dir, filename), size = filesize, time = os.time() }); | 168 filename = filename, dir = random_dir, size = filesize, time = os.time() }); |
| 169 | |
| 165 if not ok then | 170 if not ok then |
| 166 origin.send(st.error_reply(stanza, "wait", "internal-server-failure")); | 171 origin.send(st.error_reply(stanza, "wait", "internal-server-failure")); |
| 167 return true; | 172 return true; |
| 168 end | 173 end |
| 169 | 174 |
