From fe37ed50e6677233e2b0b4446b3d804c4409bdc8 Mon Sep 17 00:00:00 2001 From: "d.malygin" <d.malygin@iqdev.digital> Date: Fri, 23 Aug 2024 13:12:07 +0500 Subject: [PATCH] started trying to fix url size --- .env | 8 ++++++-- prisma/schema.prisma | 8 +++++--- services/homeService.js | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.env b/.env index 7385ade..b44961f 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 7d9d943..14e2031 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 af767e0..2862ea2 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({ -- GitLab