diff options
author | Shav Kinderlehrer <[email protected]> | 2023-10-16 14:08:23 -0400 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2023-10-16 14:08:23 -0400 |
commit | c5d3db7993b5ca39b48d055a5b42a57113757839 (patch) | |
tree | fa0a8fdff5dc2e96779623711c61c6d24ecc1d6d /src/get.ts | |
parent | 612e67d3dca483fa03b5f0e9d5778a0a693a7474 (diff) | |
download | url-shortener-main.tar.gz url-shortener-main.zip |
Diffstat (limited to 'src/get.ts')
-rw-r--r-- | src/get.ts | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -25,7 +25,14 @@ export async function get_id( context: { params: Record<"id", string>, headers: Record<string, string | null> }, sql: Sql) { - const id = context.params.id; + let id = context.params.id; + + let get_query = false; + if (id.endsWith("+")) { + id = id.slice(0, id.length - 1); + get_query = true; + } + let db_res = await sql` SELECT * FROM urls WHERE id=${id} @@ -33,6 +40,8 @@ export async function get_id( if (!db_res.length) { return new Response(`url for id '${id}' not found.`, { status: 404 }); + } else if (get_query) { + return new Response(`trkt.in/${id} -> ${db_res[0]['url']}`); } else { await sql` INSERT INTO tracking (id,clicks) |