11import { Redis } from '@upstash/redis' ;
2- import { createCipheriv , createDecipheriv , randomBytes } from 'crypto' ;
3- import { createLinkRequestSchema , type CreateLinkResponse } from './schema' ;
2+ import { createCipheriv , randomBytes } from 'node: crypto' ;
3+ import { createLinkRequestSchema , type CreateLinkRequest , type CreateLinkResponse } from './schema' ;
44
55const redis = new Redis ( {
6- url : process . env . UPSTASH_REDIS_REST_URL ! ,
7- token : process . env . UPSTASH_REDIS_REST_TOKEN ! ,
6+ url : process . env . UPSTASH_REDIS_REST_URL ?? "" ,
7+ token : process . env . UPSTASH_REDIS_REST_TOKEN ?? "" ,
88} ) ;
99
1010// AES-256-GCM encryption using AUTH_SECRET
1111function encrypt ( text : string ) : string {
12- const key = Buffer . from ( process . env . AUTH_SECRET ! ) . subarray ( 0 , 32 ) ;
12+ const key = Buffer . from ( process . env . AUTH_SECRET ?? "" ) . subarray ( 0 , 32 ) ;
1313 const iv = randomBytes ( 12 ) ;
1414 const cipher = createCipheriv ( 'aes-256-gcm' , key , iv ) ;
1515 const encrypted = Buffer . concat ( [ cipher . update ( text , 'utf8' ) , cipher . final ( ) ] ) ;
@@ -29,7 +29,7 @@ function generateId(length = 8): string {
2929export async function POST ( request : Request ) {
3030 try {
3131 // Parse and validate request body
32- let requestBody ;
32+ let requestBody : CreateLinkRequest | undefined ;
3333 try {
3434 const json = await request . json ( ) ;
3535 requestBody = createLinkRequestSchema . parse ( json ) ;
0 commit comments