2018-02-17 00:00:06 +00:00
|
|
|
const React = require("react");
|
2018-04-04 05:24:22 +00:00
|
|
|
const formatBytes = require("pretty-bytes");
|
2018-02-17 00:00:06 +00:00
|
|
|
const getFileContentType = require("../utils/getFileContentType");
|
2017-05-25 18:25:42 +00:00
|
|
|
|
2018-02-17 00:00:06 +00:00
|
|
|
const e = React.createElement;
|
2017-05-25 18:25:42 +00:00
|
|
|
|
2018-04-04 05:24:22 +00:00
|
|
|
function formatTime(time) {
|
|
|
|
return new Date(time).toISOString();
|
|
|
|
}
|
2017-05-25 18:25:42 +00:00
|
|
|
|
2018-02-17 00:00:06 +00:00
|
|
|
function DirectoryListing({ dir, entries }) {
|
2017-05-25 18:25:42 +00:00
|
|
|
const rows = entries.map(({ file, stats }, index) => {
|
2018-02-17 00:00:06 +00:00
|
|
|
const isDir = stats.isDirectory();
|
|
|
|
const href = file + (isDir ? "/" : "");
|
2017-05-25 18:25:42 +00:00
|
|
|
|
2017-11-08 16:57:15 +00:00
|
|
|
return e(
|
2017-11-25 21:25:01 +00:00
|
|
|
"tr",
|
|
|
|
{ key: file, className: index % 2 ? "odd" : "even" },
|
|
|
|
e("td", null, e("a", { title: file, href }, file)),
|
|
|
|
e("td", null, isDir ? "-" : getFileContentType(file)),
|
2018-04-04 05:24:22 +00:00
|
|
|
e("td", null, isDir ? "-" : formatBytes(stats.size)),
|
2017-11-25 21:25:01 +00:00
|
|
|
e("td", null, isDir ? "-" : formatTime(stats.mtime))
|
2018-02-17 00:00:06 +00:00
|
|
|
);
|
|
|
|
});
|
2017-05-25 18:25:42 +00:00
|
|
|
|
2018-02-17 00:00:06 +00:00
|
|
|
if (dir !== "/") {
|
2017-05-25 18:25:42 +00:00
|
|
|
rows.unshift(
|
2017-11-08 16:57:15 +00:00
|
|
|
e(
|
2017-11-25 21:25:01 +00:00
|
|
|
"tr",
|
|
|
|
{ key: "..", className: "odd" },
|
|
|
|
e("td", null, e("a", { title: "Parent directory", href: "../" }, "..")),
|
|
|
|
e("td", null, "-"),
|
|
|
|
e("td", null, "-"),
|
|
|
|
e("td", null, "-")
|
2017-05-25 18:25:42 +00:00
|
|
|
)
|
2018-02-17 00:00:06 +00:00
|
|
|
);
|
|
|
|
}
|
2017-05-25 18:25:42 +00:00
|
|
|
|
2017-11-08 16:57:15 +00:00
|
|
|
return e(
|
2017-11-25 21:25:01 +00:00
|
|
|
"table",
|
2017-11-08 16:57:15 +00:00
|
|
|
null,
|
|
|
|
e(
|
2017-11-25 21:25:01 +00:00
|
|
|
"thead",
|
2017-11-08 16:57:15 +00:00
|
|
|
null,
|
|
|
|
e(
|
2017-11-25 21:25:01 +00:00
|
|
|
"tr",
|
2017-11-08 16:57:15 +00:00
|
|
|
null,
|
2017-11-25 21:25:01 +00:00
|
|
|
e("th", null, "Name"),
|
|
|
|
e("th", null, "Type"),
|
|
|
|
e("th", null, "Size"),
|
|
|
|
e("th", null, "Last Modified")
|
2017-11-08 16:57:15 +00:00
|
|
|
)
|
|
|
|
),
|
2017-11-25 21:25:01 +00:00
|
|
|
e("tbody", null, rows)
|
2018-02-17 00:00:06 +00:00
|
|
|
);
|
2017-05-25 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 00:00:06 +00:00
|
|
|
module.exports = DirectoryListing;
|