From ed1be26d38e51ca32cea0a7ad2d24a1c1b1d77f9 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Wed, 13 Mar 2024 02:34:48 +0800 Subject: [PATCH] check for active/inactive on redirect --- redirect/src/index.ts | 10 +++++----- redirect/src/types.ts | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/redirect/src/index.ts b/redirect/src/index.ts index c2c1d15..490b5b0 100644 --- a/redirect/src/index.ts +++ b/redirect/src/index.ts @@ -31,6 +31,11 @@ app.get( .orderBy('created_at', 'desc') .execute() + if (!shortener.length || !shortener[0].active) { + set.redirect = '/invalid' + return + } + const visitor_data = { shortener_id: shortener[0].id, country: geolocation.data.location.country.name as string, @@ -44,11 +49,6 @@ app.get( await db.insertInto('visitor').values(visitor_data).execute() - if (!shortener.length) { - set.redirect = '/invalid' - return - } - set.redirect = shortener[0].link } catch { set.redirect = fallback_url diff --git a/redirect/src/types.ts b/redirect/src/types.ts index 31fc5f9..828c5df 100644 --- a/redirect/src/types.ts +++ b/redirect/src/types.ts @@ -18,6 +18,7 @@ export interface ShortenerTable { id: Generated link: string code: string + active: boolean created_at: ColumnType }