From cb18b75e639e2a602167095fb3a66281539a023c Mon Sep 17 00:00:00 2001 From: Daniel Einars Date: Sun, 29 Oct 2023 14:09:59 +0100 Subject: [PATCH] something is broken somewhere with prisma.. investigating Signed-off-by: Daniel Einars --- .env.development | 5 ++- package.json | 7 ++-- prisma/seed.js | 36 +++++++++++++------- src/lib/components/atoms/media/avatar.svelte | 2 +- src/lib/server/repository/prismaClient.ts | 2 +- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.env.development b/.env.development index 222903e..7b79407 100644 --- a/.env.development +++ b/.env.development @@ -10,11 +10,10 @@ REDIS_URL="redis://default:redispw@localhost:6379" REDIS_TOKEN="" # Thumbor -PUBLIC_THUMBOR_URL="http://localhost:6501" THUMBOR_UPLOAD_URL="http://localhost:6501/image" # Images: Cloudflare CLOUDFLARE_IMAGE_API_TOKEN="" -CLOUDFLARE_IMAGE_API="" -PUBLIC_CLOUDFLARE_IMAGE_DELIVERY="" +CLOUDFLARE_IMAGE_API="http://localhost:6501/image" +PUBLIC_CLOUDFLARE_IMAGE_DELIVERY="https://img.cloudkit.dle.dev" IS_CI=false diff --git a/package.json b/package.json index b33ef49..0f0ecc6 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "private": true, "type": "module", "scripts": { + "prep": "docker-compose up -d && pnpm prisma:push:dev && pnpm psql:seed", "dev": "pnpm prisma:gen:dev && vite dev", + "dev:prod": "pnpm prisma:gen:prod && vite dev", "clean": "rimraf playwright-report && rimraf ./build && rimraf ./.svelte-kit", "build:prod": "pnpm clean && pnpm prisma:gen:prod && vite build --mode production", "build:ci": "pnpm clean && pnpm prisma:gen:ci && vite build --mode ci", @@ -25,7 +27,8 @@ "prisma:gen:prod": "dotenv -e .env.production -- prisma generate --no-engine --schema ./prisma/prod.schema.prisma", "prisma:push:dev": "dotenv -e .env.development -- prisma db push --schema ./prisma/dev.schema.prisma", "prisma:push:prod": "dotenv -e .env.production -- prisma db push --schema ./prisma/prod.schema.prisma", - "prisma:studio": "dotenv -e .env.development -- prisma studio --schema ./prisma/schema.prisma", + "prisma:studio": "dotenv -e .env.development -- prisma studio --schema ./prisma/dev.schema.prisma", + "prisma:studio:prod": "dotenv -e .env.production -- prisma studio --schema ./prisma/prod.schema.prisma", "psql:dump": "docker exec -i sk-db /bin/bash -c \"PGPASSWORD=pass123 pg_dump --username admin sk-db\" > ./sk-db-dump.sql", "psql:restore": "docker exec -i sk-db /bin/bash -c \"PGPASSWORD=pass123 psql --username admin sk-db\" < /sk-db-dump.sql", "psql:seed": "pnpm prisma:gen:dev && dotenv -e .env.development -- node prisma/seed.js", @@ -95,4 +98,4 @@ "vitest": "0.34.6", "wrangler": "^3.15.0" } -} \ No newline at end of file +} diff --git a/prisma/seed.js b/prisma/seed.js index bfd0463..dc337d7 100644 --- a/prisma/seed.js +++ b/prisma/seed.js @@ -33,30 +33,42 @@ const auth = lucia({ } }); -async function createImageSet(type) { +async function createImageInService(type) { const id = uuid(); const image = await fetch('https://picsum.photos/736') .then((response) => response.arrayBuffer()) .then((buffer) => sharp(buffer).webp({ quality: 80 }).toBuffer()); const path = `${type}/${id}`; - await fetch(`${process.env.THUMBOR_UPLOAD_URL}/${path}`, { - method: 'PUT', + + const form = new FormData(); + form.append('file', new Blob([image]), id); + form.append('id', path); + + await fetch(process.env.CLOUDFLARE_IMAGE_API, { + method: 'POST', headers: { - 'Content-Type': 'image/webp', - Slug: `${id}.webp` + Authorization: `Bearer ${process.env.CLOUDFLARE_IMAGE_API_TOKEN}` }, - body: image + body: form }); + // await fetch(`${process.env.THUMBOR_UPLOAD_URL}/${path}`, { + // method: 'PUT', + // headers: { + // 'Content-Type': 'image/webp', + // Slug: `${id}.webp` + // }, + // body: image + // }); - return { path: `${process.env.THUMBOR_UPLOAD_URL}/${type}/${id}`, id: id }; + return { path, id }; } async function freshInit() { await db.user.deleteMany({}); await db.image.deleteMany({}); - const { path, id } = await createImageSet('avatars'); + const { path, id } = await createImageInService('avatars'); const image = await db.image.create({ data: { id: id, @@ -68,11 +80,11 @@ async function freshInit() { key: { providerId: 'username', providerUserId: 'admin@dle.dev', - password: 'adminadmin' + password: 'admin@dle.dev' }, attributes: { email: 'admin@dle.dev', - firstName: 'Svelte', + firstName: 'Daniel', lastName: 'Kit', bio: "I'm a full-stack web developer.", avatarId: image.id, @@ -84,8 +96,8 @@ async function freshInit() { }); // Create 10 users - for (let i = 0; i < 2; i++) { - const { path, id } = await createImageSet('avatars'); + for (let i = 0; i < 10; i++) { + const { path, id } = await createImageInService('avatars'); const image = await db.image.create({ data: { id: id, diff --git a/src/lib/components/atoms/media/avatar.svelte b/src/lib/components/atoms/media/avatar.svelte index 43130d3..3f82543 100644 --- a/src/lib/components/atoms/media/avatar.svelte +++ b/src/lib/components/atoms/media/avatar.svelte @@ -7,7 +7,7 @@ export let initials = ''; export let border = ''; export let isBase64 = false; - $: url = isBase64 + let url = isBase64 ? (src as string) : `${PUBLIC_CLOUDFLARE_IMAGE_DELIVERY}/${src}/${isLarge ? 'public' : 'public'}`; diff --git a/src/lib/server/repository/prismaClient.ts b/src/lib/server/repository/prismaClient.ts index 1fc463e..fc96dc2 100644 --- a/src/lib/server/repository/prismaClient.ts +++ b/src/lib/server/repository/prismaClient.ts @@ -6,7 +6,7 @@ import { dev } from '$app/environment'; const prismaConfiguration = { datasources: { db: { - url: dev ? DATABASE_URL : DATA_PROXY + url: !dev ? DATABASE_URL : DATA_PROXY } } };