<%if(path!=="/"){path+="/"}%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>Index of <%= path %></title>
    <style>
        body {
            font-size: 16px;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            line-height: 1.5;
            padding: 0 10px 5px
        }

        table {
            width: 100%;
            border-collapse: collapse;
            font: .85em Monaco, monospace
        }

        tr.even {
            background-color: #eee
        }

        th {
            text-align: left
        }

        td,
        th {
            padding: .1em .25em
        }

        .version-wrapper {
            line-height: 2.25em;
            float: right
        }

        #version {
            font-size: 1em
        }

        address {
            text-align: right
        }
    </style>
</head>

<body>
    <h1>Index of <%= path %></h1>
    <hr />
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Type</th>
                <th>Size</th>
                <th>Last Modified</th>
            </tr>
        </thead>
        <tbody>
            <% 
                files.sort((fileA,fileB) => { 
                    let nameA = fileA.path.toUpperCase();
                    let nameB = fileB.path.toUpperCase();
                    if(fileA.type === "directory") return -1;
                    else if(fileB.type === "directory") return 1;
                    else if(nameA<nameB) return -1;
                    else if(nameA>nameB) return 1;
                    else return 0;
                })
                if(path!=="/"){
                    files.splice(0,0,{
                            path: "..",
                            type: "directory",
                    });
                }

            %>
            <% files.forEach((file,index) => { let name = `${file.path.replace(path,"")}${file.type==="directory"?"/":""}` %>
                <tr class="<%= index%2===0?"even":"odd" %> ">
                    <td><a title="<%= name %>" href="<%= name %>"><%= name %></a></td>
                    <td><%= file.type==="directory"?"-":file.contentType %></td>
                    <td><%= file.type==="directory"?"-":(()=>{
                        if(file.size<=1024) return file.size+" B";
                        else if(file.size<=1024*1024) return (file.size/1024).toFixed(2)+" KiB";
                        else return (file.size/1024/1024).toFixed(2)+" MB";
                    })() %></td>
                    <td><%= file.type==="directory"?"-":new Date(Date.parse(file.lastModified)).toISOString()
                        %></td>
                </tr>
            <% }) %>
        </tbody>
    </table>
    <hr />
    <address><%= package %> </address>
    <address>186526 Edge/1.20.1</address>
</body>

</html>