From beb2f2b61e9111f0b950bfe3a153b09bbbfe2dc7 Mon Sep 17 00:00:00 2001 From: Alexander Daichendt Date: Wed, 1 Jan 2025 22:36:29 +0100 Subject: [PATCH] feat: switch to nanoid over uuid --- package.json | 1 + pnpm-lock.yaml | 10 ++++++++++ src/content/blog/little-things-in-oslo.mdx | 3 +++ src/pages/admin/api/verifications/index.ts | 4 +++- src/pages/{cv_verification => cv}/index.astro | 6 +++--- 5 files changed, 20 insertions(+), 4 deletions(-) rename src/pages/{cv_verification => cv}/index.astro (89%) diff --git a/package.json b/package.json index b60e75d..5adfcd7 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "astro-icon": "^1.1.4", "drizzle-orm": "^0.38.3", "mdast-util-to-string": "^4.0.0", + "nanoid": "^5.0.9", "reading-time": "^1.5.0", "sharp": "^0.33.5", "tailwindcss": "^3.4.16", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 406a8d8..cdc694e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,6 +50,9 @@ importers: mdast-util-to-string: specifier: ^4.0.0 version: 4.0.0 + nanoid: + specifier: ^5.0.9 + version: 5.0.9 reading-time: specifier: ^1.5.0 version: 1.5.0 @@ -2565,6 +2568,11 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true + nanoid@5.0.9: + resolution: {integrity: sha512-Aooyr6MXU6HpvvWXKoVoXwKMs/KyVakWwg7xQfv5/S/RIgJMy0Ifa45H9qqYy7pTCszrHzP21Uk4PZq2HpEM8Q==} + engines: {node: ^18 || >=20} + hasBin: true + napi-build-utils@1.0.2: resolution: {integrity: sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==} @@ -6200,6 +6208,8 @@ snapshots: nanoid@3.3.8: {} + nanoid@5.0.9: {} + napi-build-utils@1.0.2: {} neotraverse@0.6.18: {} diff --git a/src/content/blog/little-things-in-oslo.mdx b/src/content/blog/little-things-in-oslo.mdx index b3f0981..91c5fca 100644 --- a/src/content/blog/little-things-in-oslo.mdx +++ b/src/content/blog/little-things-in-oslo.mdx @@ -35,3 +35,6 @@ It seems like that legislation is more permissive when it comes to renting out a ### 8. Old houses with chargers for EVs There is this stark contrast between old wooden houses with a Tesla or some other modern EV parked in front and hooked up to a charger. It's funny. + +### 9. A lappen is a lappen +Apparently, a lappen can mean driver's license, which is exactly the same in German. Never once I expected to find this informal colloquialism anywhere outside the DACH area. diff --git a/src/pages/admin/api/verifications/index.ts b/src/pages/admin/api/verifications/index.ts index 7c398ab..21761dc 100644 --- a/src/pages/admin/api/verifications/index.ts +++ b/src/pages/admin/api/verifications/index.ts @@ -1,6 +1,7 @@ import type { APIContext } from "astro"; import { drizzle } from "drizzle-orm/d1"; import { cvTable } from "../../../../db/schema"; +import { nanoid } from "nanoid"; export const prerender = false; @@ -16,7 +17,7 @@ export async function POST(context: APIContext) { const purpose = formData.get("purpose") as string; const tooling = formData.get("tooling") as string; const created = new Date(); - const uuid = crypto.randomUUID(); + const uuid = nanoid(8); try { await db @@ -24,6 +25,7 @@ export async function POST(context: APIContext) { .values({ company_name, author, purpose, tooling, created, uuid }) .execute(); } catch (error) { + console.error(error); return new Response(JSON.stringify({ success: false, error })); } diff --git a/src/pages/cv_verification/index.astro b/src/pages/cv/index.astro similarity index 89% rename from src/pages/cv_verification/index.astro rename to src/pages/cv/index.astro index 2d69585..4df2e23 100644 --- a/src/pages/cv_verification/index.astro +++ b/src/pages/cv/index.astro @@ -9,12 +9,12 @@ import Verified from "../../components/verification/Verified.astro"; import Revoked from "../../components/verification/Revoked.astro"; export const prerender = false; -const uuid = Astro.url.searchParams.get("uuid"); +const id = Astro.url.searchParams.get("id"); const db = drizzle(Astro.locals.runtime.env.DB); -const cv = uuid - ? await db.select().from(cvTable).where(eq(cvTable.uuid, uuid)) +const cv = id + ? await db.select().from(cvTable).where(eq(cvTable.uuid, id)) : []; ---