1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { Statement } from "https://esm.town/v/postpostscript/sqliteBuilder?v=36";
const DEFAULT = `
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
NO EMAILS IN LAST 15 MINUTES<br>
<a href='mailto:neverstew.peachGoat@valtown.email'>Email me!</a>
</body>
</html>
`;
export default async function(req: Request): Promise<Response> {
const now = new Date().getTime();
const fifteenMins = 15 * 60 * 1000;
const [latestEmail] = await Statement`select * from emails where timestamp > ${
now - fifteenMins
} order by timestamp desc limit 1`.execute();
return new Response(latestEmail?.content || DEFAULT, { headers: { "Content-Type": "text/html" } });
}