Skip to content
Snippets Groups Projects
Commit fe37ed50 authored by Дмитрий Малюгин's avatar Дмитрий Малюгин :clock4:
Browse files

started trying to fix url size

parent 467d1db0
No related branches found
No related tags found
1 merge request!2Refactor/image and text
......@@ -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"
......@@ -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?
......
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({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment