Commit 6bdddffb authored by Дмитрий Малюгин's avatar Дмитрий Малюгин 🕓
Browse files

Merge branch 'refactor/imageProperties' into 'main'

Refactor image entity

See merge request !6
parents e1717c7c 9125b327
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@ model Entity {
  text_position         String?
  image_path            String? @db.Text
  image_width           Int?
  image_height          Int?
  file_width            Int?
  file_height           Int?
  entity_position       String?
  entity_title_position String?
  image_scale           String?
@@ -81,8 +82,13 @@ model Image {
  entity_uuid           String @id @default(uuid())
  entity_order          Int
  image_path            String? @db.Text
  image_url_initial     String?
  image_width_initial   Int
  file_width_initial    Int
  file_height_initial   Int
  image_width           Int?
  image_height          Int?
  file_width            Int?
  file_height           Int?
  image_scale           String?
  title                 String?
  text                  String? @db.Text
+9 −2
Original line number Diff line number Diff line
@@ -10,9 +10,9 @@ class EntitiesController {
      console.log(error);
    }
  }
  async createImage(req: Buffer) {
  async createImage(req: Buffer, isCropImageNow: boolean) {
    try {
      return await EntitiesService.createImage(req);
      return await EntitiesService.createImage(req, isCropImageNow);
    } catch (error) {
      console.log(error);
    }
@@ -39,6 +39,13 @@ class EntitiesController {
      console.log(error);
    }
  }
  async returnOriginalSizeImage(req: IWSRequest<'returnOriginalSizeImage', IEntity>) {
    try {
      return await EntitiesService.returnOriginalSizeImage(req.body);
    } catch (error) {
      console.log(error);
    }
  }
  async changeEntitiesOrder(req: IChangeEntitiesOrder) {
    try {
      return await EntitiesService.changeEntitiesOrder(req.body);
+23 −1
Original line number Diff line number Diff line
import { bot } from '../telegramBot';
import { PrismaClient } from '@prisma/client';
import path from 'node:path';

export const validateMessage = async (
  response: any,
@@ -57,6 +58,27 @@ export const getPrismaEntity = async (body: any) => {
    //     });
  }
};
export const getImagePathByUuid = (entity_uuid: string, isOriginal?: boolean) => {
  const imagePath = path.join(path.resolve(), `/public/images/image.jpg`);
  let newImagePath;
  if (process.platform.includes('win')) {
    newImagePath = imagePath.split('\\');
  } else {
    newImagePath = imagePath.split('/');
  }
  newImagePath.splice(-1);
  if (isOriginal) {
    newImagePath.push(`original${entity_uuid}.jpg`);
  } else {
    newImagePath.push(`${entity_uuid}.jpg`);
  }
  if (process.platform.includes('win')) {
    newImagePath = newImagePath.join('\\');
  } else {
    newImagePath = newImagePath.join('/');
  }
  return newImagePath;
};
export const updatePrismaEntity = async (body: any) => {
  switch (body.entity_type) {
    case 'divider':
@@ -74,7 +96,7 @@ export const updatePrismaEntity = async (body: any) => {
        data: { ...body }
      });
    case 'image':
      delete body.imageUrl;
      delete body.image_url;
      return prisma.image.update({
        where: {
          entity_uuid: body.entity_uuid
+8 −2
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import { connectBot } from './telegramBot';
await connectBot();

const users = new Set();
let isCropImageNow: boolean = false;

const PORT = Number(process.env.PORT) || 5000;
const FILES_PORT = process.env.FILES_PORT || 5001;
@@ -22,6 +23,7 @@ wss.on('connection', (ws) => {
  ws.id = Date.now();
  ws.on('message', async (req) => {
    req = JSON.parse(req);
    if (req.event === 'setCropNow') isCropImageNow = true;
    await websocketRoute(req);
  });
});
@@ -36,8 +38,12 @@ filesWss.on('connection', (ws) => {
  users.add(ws);
  console.log('users wss: ', users.size);
  ws.on('message', async (req: Buffer) => {
    await EntitiesController.createImage(req);
    await EntitiesController.createImage(req, isCropImageNow);
    if (!isCropImageNow) {
      submitToUsers('createImageEntity', '');
    } else {
      isCropImageNow = false;
    }
  });
});

+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ export interface IEntity {
  text_position?: string | null;
  image_buffer?: string;
  image_path?: string;
  imageUrl?: string;
  image_url?: string;
  image_width?: number;
  image_height?: number;
  entity_position?: string;
Loading