summaryrefslogtreecommitdiff
path: root/src/api.ts
diff options
context:
space:
mode:
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****";