feat: switch to nanoid over uuid

This commit is contained in:
Alexander Daichendt 2025-01-01 22:36:29 +01:00
parent ba54eda347
commit beb2f2b61e
5 changed files with 20 additions and 4 deletions

View file

@ -30,6 +30,7 @@
"astro-icon": "^1.1.4", "astro-icon": "^1.1.4",
"drizzle-orm": "^0.38.3", "drizzle-orm": "^0.38.3",
"mdast-util-to-string": "^4.0.0", "mdast-util-to-string": "^4.0.0",
"nanoid": "^5.0.9",
"reading-time": "^1.5.0", "reading-time": "^1.5.0",
"sharp": "^0.33.5", "sharp": "^0.33.5",
"tailwindcss": "^3.4.16", "tailwindcss": "^3.4.16",

10
pnpm-lock.yaml generated
View file

@ -50,6 +50,9 @@ importers:
mdast-util-to-string: mdast-util-to-string:
specifier: ^4.0.0 specifier: ^4.0.0
version: 4.0.0 version: 4.0.0
nanoid:
specifier: ^5.0.9
version: 5.0.9
reading-time: reading-time:
specifier: ^1.5.0 specifier: ^1.5.0
version: 1.5.0 version: 1.5.0
@ -2565,6 +2568,11 @@ packages:
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true 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: napi-build-utils@1.0.2:
resolution: {integrity: sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==} resolution: {integrity: sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==}
@ -6200,6 +6208,8 @@ snapshots:
nanoid@3.3.8: {} nanoid@3.3.8: {}
nanoid@5.0.9: {}
napi-build-utils@1.0.2: {} napi-build-utils@1.0.2: {}
neotraverse@0.6.18: {} neotraverse@0.6.18: {}

View file

@ -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 ### 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. 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.

View file

@ -1,6 +1,7 @@
import type { APIContext } from "astro"; import type { APIContext } from "astro";
import { drizzle } from "drizzle-orm/d1"; import { drizzle } from "drizzle-orm/d1";
import { cvTable } from "../../../../db/schema"; import { cvTable } from "../../../../db/schema";
import { nanoid } from "nanoid";
export const prerender = false; export const prerender = false;
@ -16,7 +17,7 @@ export async function POST(context: APIContext) {
const purpose = formData.get("purpose") as string; const purpose = formData.get("purpose") as string;
const tooling = formData.get("tooling") as string; const tooling = formData.get("tooling") as string;
const created = new Date(); const created = new Date();
const uuid = crypto.randomUUID(); const uuid = nanoid(8);
try { try {
await db await db
@ -24,6 +25,7 @@ export async function POST(context: APIContext) {
.values({ company_name, author, purpose, tooling, created, uuid }) .values({ company_name, author, purpose, tooling, created, uuid })
.execute(); .execute();
} catch (error) { } catch (error) {
console.error(error);
return new Response(JSON.stringify({ success: false, error })); return new Response(JSON.stringify({ success: false, error }));
} }

View file

@ -9,12 +9,12 @@ import Verified from "../../components/verification/Verified.astro";
import Revoked from "../../components/verification/Revoked.astro"; import Revoked from "../../components/verification/Revoked.astro";
export const prerender = false; 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 db = drizzle(Astro.locals.runtime.env.DB);
const cv = uuid const cv = id
? await db.select().from(cvTable).where(eq(cvTable.uuid, uuid)) ? await db.select().from(cvTable).where(eq(cvTable.uuid, id))
: []; : [];
--- ---