Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions meshchat
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,36 @@ function file_download()
release_lock()

print("Content-MD5: " .. md5 .. "\r")
print("Content-Disposition: attachment; filename=\"" .. file .. "\";\r")
print("Content-type: application/octet-stream\r")

local ext = string.match(file, "%.(%a+)$")
local content_type

if ext == "jpe" or ext == "jpg" or ext == "jpeg" then
content_type = "image/jpeg"
elseif ext == "png" then
content_type = "image/png"
elseif ext == "gif" then
content_type = "image/gif"
elseif ext == "webp" then
content_type = "image/webp"
elseif ext == "bmp" then
content_type = "image/bmp"
elseif ext == "tiff" or ext == "tif" then
content_type = "image/tiff"
elseif ext == "ico" then
content_type = "image/x-icon"
elseif ext == "svg" or ext == "svgz" then
content_type = "image/svg+xml"
elseif ext == "avif" then
content_type = "image/avif"
elseif ext == "heic" or ext == "heif" then
content_type = "image/heic"
else
print("Content-Disposition: attachment; filename=\"" .. file .. "\";\r")
content_type = "application/octet-stream"
end

print("Content-Type: " .. content_type .. "\r")
print("\r")

if f then
Expand Down
2 changes: 1 addition & 1 deletion www/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function load_files() {
port = ':8080'
}
}
html += '<td><a href="http://' + aredn_domain(data.files[i].node) + port + '/cgi-bin/meshchat?action=file_download&file=' + encodeURIComponent(data.files[i].file) + '">' + data.files[i].file + '</a></td>';
Comment thread
ham-k7dev marked this conversation as resolved.
html += '<td><a href="http://' + aredn_domain(data.files[i].node) + port + '/cgi-bin/meshchat?action=file_download&file=' + encodeURIComponent(data.files[i].file) + '" target="_blank">' + data.files[i].file + '</a></td>';
html += '<td>' + numeral(data.files[i].size).format('0.0 b') + '</td>';
html += '<td class="col_node">' + data.files[i].node + '</td>';
html += '<td class="col_time">' + format_date(date) + '</td>';
Expand Down