-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.tsx
More file actions
124 lines (108 loc) · 2.34 KB
/
utils.tsx
File metadata and controls
124 lines (108 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { FC } from '@hono/hono/jsx';
import { css, Style } from '@hono/hono/css';
export async function listFilesAndDir(path?: string | null) {
const entries: Deno.DirEntry[] = [];
for await (const entry of Deno.readDir(path || Deno.cwd())) {
entries.push(entry);
}
return entries;
}
interface Props {
filesAndDirs: Deno.DirEntry[];
base: string;
}
const globalCSS = css`
body {
margin: 0;
padding: 1rem;
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
'Helvetica Neue',
Arial,
sans-serif;
background-color: #f7f7f7;
color: #333;
}
a {
color: #0366d6;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
h2 {
margin-top: 0.5rem;
font-size: 1.5rem;
}
ul {
list-style: none;
padding-left: 0;
}
li {
margin: 0.25rem 0;
}
li a {
display: inline-block;
padding: 0.25rem 0.5rem;
border-radius: 4px;
}
li a:hover {
background-color: #e1e4e8;
}
li a.file::before {
content: '📄';
margin-right: 0.5rem;
}
li a.dir::before {
content: '📁';
margin-right: 0.5rem;
}
`;
export const Page: FC<Props> = ({ filesAndDirs, base }) => {
const hrefBase = base === '/' ? '' : base;
return (
<>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>FTP - Server</title>
<Style>{globalCSS}</Style>
</head>
<body>
<a href="/">Home</a>
<h2>{base}</h2>
<ul>
{filesAndDirs.map(({ name, isDirectory, isFile }) => {
return (
<li key={name}>
{isFile && (
<a
class="file"
download={name}
href={`/file${hrefBase}/${name}`}
>
{name}
</a>
)}
{isDirectory && (
<a class="dir" href={`${hrefBase}/${name}`}>
{name}
</a>
)}
</li>
);
})}
</ul>
</body>
</html>
</>
);
};