diff --git a/.env b/.env index 7385ade5b651943532ea2f93c2bb5210fabbe5a8..b44961fa91b24da648c93a1500aacf06d237f6e2 100644 --- a/.env +++ b/.env @@ -4,6 +4,10 @@ DB_USER=postgres DB_PASSWORD=xoxo2002! DB_HOST=localhost DB_PORT=5432 +// prisma db push +; при запуÑке Ñ Ñ€Ð¾Ð´Ð½Ð¾Ð³Ð¾ ноутбука +; DATABASE_URL="postgresql://postgres:xoxo2002!@localhost:5432/Shelf_note" -DATABASE_URL="postgresql://postgres:xoxo2002!@localhost:5432/Shelf_note" - +; при запуÑке Ñ Ñ€Ð°Ð±Ð¾Ñ‡ÐµÐ³Ð¾ ноутбука +DATABASE_URL="postgresql://postgres.wrwwvdgppriodcdoyohp:Xoxo2002!qwe@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?pgbouncer=true" +DIRECT_URL="postgresql://postgres.wrwwvdgppriodcdoyohp:Xoxo2002!qwe@aws-0-eu-central-1.pooler.supabase.com:5432/postgres" diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7d9d9431b40815334286b35e01144d974c9d5886..14e2031170ebc329a6f4d379022188dae9fff317 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -4,7 +4,6 @@ // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init -// prisma db push generator client { provider = "prisma-client-js" } @@ -12,6 +11,8 @@ generator client { datasource db { provider = "postgresql" url = env("DATABASE_URL") + // при запуÑке Ñ Ñ€Ð°Ð±Ð¾Ñ‡ÐµÐ³Ð¾ ноутбука + directUrl = env("DIRECT_URL") } model User { @@ -34,13 +35,14 @@ model Home_entity { entity_type String title String? text String? @db.Text - text_size String? + font_size String? paragraph_size String? text_position String? image_url String? @db.Text image_width Int? image_height Int? - image_position String? + entity_position String? + entity_title_position String? image_scale String? table_columns Json? table_data Json? diff --git a/services/homeService.js b/services/homeService.js index af767e02ac7757e548a5197e88ebe17b561d3f39..2862ea2a75255fe2db1420869260aabae0c15e47 100644 --- a/services/homeService.js +++ b/services/homeService.js @@ -1,4 +1,6 @@ import { PrismaClient } from '@prisma/client'; +import * as fs from 'node:fs'; +import path from 'node:path'; const prisma = new PrismaClient(); @@ -16,7 +18,19 @@ class HomeService { }); } async createEntity(body) { - return prisma.home_entity.create({ data: body }); + let pathOfImage = ''; + if (body.image_url) { + console.log('body.image_url', body.image_url); + // const response = await fetch(body.image_url); + // const blob = await body.image_url.blob(); + const arrayBuffer = new ArrayBuffer(body.image_url); + // const arrayBuffer = await body.image_url.arrayBuffer(); + const buffer = Buffer.from(arrayBuffer); + pathOfImage = path.join(path.resolve(), `/public/images/${body.entity_uuid}`); + console.log('pathOfImage', pathOfImage); + fs.writeFile(pathOfImage, buffer, () => console.log('Written!')); + } + return prisma.home_entity.create({ data: { ...body, image_url: pathOfImage } }); } async editEntity(body) { return prisma.home_entity.update({