Skip to content

Instantly share code, notes, and snippets.

@shmup
Forked from empjustine/.init.lua
Created August 9, 2022 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shmup/0df8c687cc269fa9e9ca0cbf7e5af9f1 to your computer and use it in GitHub Desktop.
Save shmup/0df8c687cc269fa9e9ca0cbf7e5af9f1 to your computer and use it in GitHub Desktop.
path = require 'path'
local function get_asset_comment(zip_path)
comment = GetAssetComment(zip_path)
if comment then
return comment
end
return ''
end
local function is_directory(zip_path)
if zip_path == "/" then
return true
end
if path.isdir("/zip"..zip_path) then
return true
end
end
local function folder_index()
header_size = GetAssetSize(GetPath()..".header.html")
if header_size then
Write(LoadAsset(GetPath()..".header.html"))
end
Write(EscapeHtml(GetPath()))
Write("<hr>\n<table><thead><tr><th></th><th>name</th><th>modified</th><th>mode</th><th>size</th><th>comment</th></tr></thead><tbody>\n")
for i, current_zip_path in pairs(GetZipPaths(GetPath())) do
if
(path.dirname(current_zip_path).."/"):gsub("%//", "/") == GetPath() -- in current dirname
and
string.sub(path.basename(current_zip_path), 1, 1) ~= "." -- not hidden
then
Write("<tr><td>")
-- TODO: improve this later
-- this "thing" retrieves icons and encode them in data URI pngs if the extension matches
extension = path.basename(current_zip_path):match("^.+(%..+)$") or ""
if GetAssetSize("/.extension_icons/" .. extension .. ".png") then
Write("<img src=\"data:image/png;base64,")
Write(EncodeBase64(LoadAsset("/.extension_icons/" .. extension .. ".png")))
Write("\">")
end
Write("</td><td><a href=\"")
Write(EscapePath(current_zip_path))
Write("\">")
Write(EscapeHtml(path.basename(current_zip_path)))
if is_directory(current_zip_path) then
Write("/")
end
Write("</a></td><td>")
Write(EscapeHtml(FormatHttpDateTime(GetAssetLastModifiedTime(current_zip_path))))
Write("</td><td>")
Write(EscapeHtml(oct(GetAssetMode(current_zip_path))))
Write("</td><td>")
Write(EscapeHtml(GetAssetSize(current_zip_path)))
Write("</td><td>")
Write(EscapeHtml(get_asset_comment(current_zip_path)))
Write("</td></tr>\n")
end
end
Write("</tbody>\n</table>")
footer_size = GetAssetSize(GetPath()..".footer.html")
if footer_size then
Write(LoadAsset(GetPath()..".footer.html"))
end
end
function OnHttpRequest()
if is_directory(GetPath()) then
folder_index()
else
Route()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment