remove cleanup for now
This commit is contained in:
parent
975c47b174
commit
838ca2cb23
@ -12,7 +12,8 @@ import { z } from "zod";
|
||||
import { UserAgentHeader } from "../../../utils/blockUserAgent";
|
||||
import { setResponseJson } from "../../../utils/responseUtils";
|
||||
import { LOG_CALL_SK, LogCallSchema } from "../../../schema/LogCall";
|
||||
import { isTTLInFuture } from "../../../common/TTLHelper";
|
||||
|
||||
import crypto from "crypto";
|
||||
|
||||
export const LogCallRequestSchema = z.object({
|
||||
caller: z.string(),
|
||||
@ -27,8 +28,24 @@ export const LogCallResponseSchema = z.object({
|
||||
|
||||
export type LogCallResponse = z.infer<typeof LogCallResponseSchema>;
|
||||
|
||||
function getCode() {
|
||||
return `${Math.floor(Math.random() * 10000)}`.padStart(4, '0');
|
||||
// hash is 4 digit number based on todays date + phone number caller
|
||||
// cost saving so we don't generate a new OTP for every caller even if its the same caller
|
||||
function getCode(caller: string) {
|
||||
const hash = crypto.createHash("sha256");
|
||||
const today = new Date();
|
||||
|
||||
hash.update(today.toLocaleDateString('en-US'));
|
||||
hash.update(caller);
|
||||
|
||||
const hashHex = hash.digest('hex');
|
||||
|
||||
// 2. Convert the hexadecimal string to a BigInt
|
||||
// This is necessary for large hash values that exceed JavaScript's Number limit.
|
||||
const hashBigInt = BigInt(`0x${hashHex}`);
|
||||
|
||||
// 3. Convert the BigInt to a decimal string
|
||||
const hashDecimal = hashBigInt.toString();
|
||||
return hashDecimal.substring(hashDecimal.length - 4,);
|
||||
};
|
||||
|
||||
export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestTwilio> = withMetrics("logCall", async (context, event, callback, metricsRegistry) => {
|
||||
@ -47,17 +64,16 @@ export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestT
|
||||
msg: "Onboarding is not open",
|
||||
});
|
||||
} else {
|
||||
// best efforts cleanup
|
||||
// TODO: make this use an INDEX instead of scan
|
||||
console.log("Attempting best efforts cleanup of logged calls")
|
||||
const logs = await db.entities.logCall.findAll();
|
||||
const toRemove = logs.filter(log => !isTTLInFuture(log));
|
||||
console.log(`There are ${toRemove.length} old call logs to remove`);
|
||||
await db.entities.logCall.deleteBatch(toRemove);
|
||||
console.log("done cleaning up logged calls");
|
||||
// TODO: best efforts cleanup
|
||||
// console.log("Attempting best efforts cleanup of logged calls")
|
||||
// const items = await db.entities.logCall.findAll();
|
||||
// const toRemove = items.filter(item => item.SK === LOG_CALL_SK && !isTTLInFuture(item));
|
||||
// console.log(`There are ${toRemove.length} old call logs to remove`);
|
||||
// await db.entities.logCall.deleteBatch(toRemove);
|
||||
// console.log("done cleaning up logged calls");
|
||||
|
||||
// log this caller
|
||||
const otp = getCode();
|
||||
const otp = getCode(caller);
|
||||
const logCall = LogCallSchema.parse({
|
||||
PK: otp,
|
||||
SK: LOG_CALL_SK,
|
||||
|
||||
@ -4,6 +4,7 @@ import { AppLayout, BreadcrumbGroup, Container, Flashbar, FlashbarProps, Header,
|
||||
import OtpInput from 'react-otp-input';
|
||||
import { CountdownBar } from "../components/CountdownBar";
|
||||
import { fetchUrlEncoded } from "../helpers/FetchHelper";
|
||||
import { readSync } from "fs";
|
||||
|
||||
export function OnboardingPage() {
|
||||
const navigate = useNavigate();
|
||||
@ -111,10 +112,13 @@ export function OnboardingPage() {
|
||||
}
|
||||
|
||||
if (detail.requestedStepIndex === 2) {
|
||||
fetch('/api/door/auth?door=onboardingflag&key=1234')
|
||||
fetchUrlEncoded('/api/door/auth', {
|
||||
door: "onboardingflag",
|
||||
key: 1234
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(res => {
|
||||
if (res.status === "CLOSED") {
|
||||
if (res.status === "CLOSED" || !res.msg) {
|
||||
addAlert('error', 'Something went wrong, please try again');
|
||||
} else {
|
||||
addAlert("in-progress", (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user