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 }