Update.
This commit is contained in:
101
modules/actions/dir.ejs
Normal file
101
modules/actions/dir.ejs
Normal file
@ -0,0 +1,101 @@
|
||||
<%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>
|
@ -99,4 +99,14 @@ async function serveDirectoryMetadata(req, res) {
|
||||
res.send(metadata);
|
||||
}
|
||||
|
||||
export async function getMetadataMoreEasier(req,res) {
|
||||
const stream = await getPackage(req.packageName, req.packageVersion, req.log);
|
||||
|
||||
const filename = req.filename.slice(0, -1) || '/';
|
||||
const entries = await findMatchingEntries(stream, filename);
|
||||
const metadata = getMetadata(entries[filename], entries);
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
export default asyncHandler(serveDirectoryMetadata);
|
||||
|
@ -29,7 +29,6 @@ export default function serveMainPage(req, res) {
|
||||
|
||||
res
|
||||
.set({
|
||||
'Cache-Control': 'public, max-age=14400', // 4 hours
|
||||
'Cache-Tag': 'main'
|
||||
})
|
||||
.send(html);
|
||||
|
Reference in New Issue
Block a user