init
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
"use server";
|
||||
|
||||
import { headers } from "next/headers";
|
||||
import { allowRequest, clientIp } from "../../lib/rate-limit";
|
||||
import { lookupBikes } from "../../lib/status";
|
||||
import type { StatusResult } from "../../lib/workshop";
|
||||
|
||||
export async function lookupStatus(_prev: StatusResult | null, formData: FormData): Promise<StatusResult> {
|
||||
const headerList = await headers();
|
||||
const ip = clientIp(headerList.get("x-forwarded-for"));
|
||||
if (!allowRequest(ip)) {
|
||||
return {
|
||||
message: null,
|
||||
error: "Too many lookups. Wait a minute and try again.",
|
||||
bikes: [],
|
||||
};
|
||||
}
|
||||
try {
|
||||
return await lookupBikes(String(formData.get("phone") ?? ""));
|
||||
} catch {
|
||||
console.error("status lookup failed");
|
||||
return { message: null, error: "Lookup failed. Try again.", bikes: [] };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user