summaryrefslogtreecommitdiff
path: root/src/api.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-12-15 02:07:48 -0800
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-12-15 02:26:06 -0800
commitc4385abb3354ca5d4d647f07d2b02bf178dc52f7 (patch)
tree122b8ef06a25355ce184c4ab991387fbafb66a00 /src/api.ts
parent4f1e974623f7e38693d3e202cd387c51f652b9d8 (diff)
downloaduptime-c4385abb3354ca5d4d647f07d2b02bf178dc52f7.tar.gz
uptime-c4385abb3354ca5d4d647f07d2b02bf178dc52f7.zip
prettier
Diffstat (limited to 'src/api.ts')
-rw-r--r--src/api.ts18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/api.ts b/src/api.ts
index 722dc70..678f40d 100644
--- a/src/api.ts
+++ b/src/api.ts
@@ -1,5 +1,6 @@
-import { transformDurations } from "./duration";
+import { parse } from "./duration";
import { perform } from "./email";
+import type { EmailJob } from "./job";
import { ConsoleLogger } from "./logger";
export const main = (port: number) => {
@@ -10,12 +11,17 @@ export const main = (port: number) => {
const url = new URL(req.url);
if (req.method === "POST" && url.pathname === "/api/email") {
- const prevalidatedJob = transformDurations(await req.json());
- if (prevalidatedJob._tag === "Left") {
- return new Response(prevalidatedJob.left, { status: 400 });
+ const prevalidatedJob = await req.json();
+ const interval = parse(prevalidatedJob.readRetry.interval);
+ if (interval._tag === "Left") {
+ return new Response(interval.left, { status: 400 });
}
- const job = prevalidatedJob.right;
-
+ prevalidatedJob.readRetry.interval = interval;
+ const job: EmailJob = {
+ ...prevalidatedJob,
+ readRetry: { ...prevalidatedJob.readRetry, interval },
+ };
+
const jobInsensitive = structuredClone(job);
jobInsensitive.from.username = "****REDACTED****";
jobInsensitive.from.password = "****REDACTED****";