Skip to content

Commit

Permalink
Merge pull request #92 from VitorCarvalho67/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
VitorCarvalho67 authored Nov 1, 2024
2 parents 9800ffb + dbb0b00 commit 8d548f5
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 33 deletions.
13 changes: 7 additions & 6 deletions client/src/components/funcionario/AsideDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
<p v-if="showPs">Boletins</p>
</router-link>
</li>
<li>
<router-link to="/funcionario/register/vaga">
<img :src="icons.form">
<p v-if="showPs">Vagas</p>
</router-link>
</li>
</ul>
<li>
<router-link to="/funcionario/register/vaga">
<img :src="icons.form">
<p v-if="showPs">Vagas</p>
</router-link>
</li>

</div>
<button @click="changePsVisualization">
<img :src="icons.angulo" alt="<">
Expand Down
6 changes: 3 additions & 3 deletions client/src/views/aluno/Rede.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="infoVinculo">
<div class="contentVinculo name">
<p class="who">{{ vinculo.data.aluno.nome }}</p>
<p>{{ vinculo.data.aluno.endereco }}</p>
<p v-text="JSON.parse(vinculo.data.aluno.endereco).municipio + ', ' + JSON.parse(vinculo.data.aluno.endereco).estado"></p>
</div>
<div class="box-button">
<button @click="removeVinculo(vinculo.data.aluno.email, vinculo.info)">Desvincular-se</button>
Expand All @@ -36,7 +36,7 @@
<div class="infoVinculo">
<div class="contentVinculo name">
<p class="who">{{ vinculo.data.aluno.nome }}</p>
<p>{{ vinculo.data.aluno.endereco }}</p>
<p v-text="JSON.parse(vinculo.data.aluno.endereco).municipio + ', ' + JSON.parse(vinculo.data.aluno.endereco).estado"></p>
</div>
<div class="box-button">
<button @click="acceptSolicitation(vinculo.info)" class="aceitar">Aceitar pedido</button>
Expand All @@ -60,7 +60,7 @@
<div class="infoVinculo">
<div class="contentVinculo name">
<p class="who">{{ vinculo.data.aluno.nome }}</p>
<p>{{ vinculo.data.aluno.endereco }}</p>
<p v-text="JSON.parse(vinculo.data.aluno.endereco).municipio + ', ' + JSON.parse(vinculo.data.aluno.endereco).estado"></p>
</div>
<div class="box-button">
<button @click="removeSolicitation('sender', vinculo.info)">Remover pedido</button>
Expand Down
41 changes: 38 additions & 3 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
FROM node:latest
FROM node:18

WORKDIR /server

# We don't need the standalone Chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

# Install Google Chrome Stable and fonts
RUN apt-get update && apt-get install -y gnupg wget && \
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && \
apt-get install -y google-chrome-stable --no-install-recommends && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y \
wget \
gnupg2 \
fonts-liberation \
libappindicator3-1 \
libasound2 \
libcups2 \
libx11-xcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxrandr2 \
libxss1 \
libxtst6 \
libnss3 \
libxss1 \
libxshmfence1 \
--no-install-recommends && \
rm -rf /var/lib/apt/lists/*

# Set the path to the Chrome executable
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome

COPY package*.json ./
RUN npm install
COPY pnpm-lock.yaml ./
RUN npm install

COPY . .
RUN npx prisma generate

EXPOSE 3333
CMD ["npm","run", "dev"]
CMD ["npm", "run", "dev"]
58 changes: 39 additions & 19 deletions server/src/modules/services/aluno/GenerateCurriculumUseCase.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import fs from 'fs';
import path from 'path';
import html_to_pdf from 'html-pdf-node';
import axios from 'axios';
import { prisma } from '../../../prisma/client';
import { uploadToMinio } from '../../../minioService';
import { minioClient } from '../../../minioService';
import { AppError } from '../../../errors/error';
import { Endereco } from '../../interfaces/alunoDTOs';
import puppeteer from 'puppeteer'; // Adicionando importação do Puppeteer

export class GenerateCurriculumUseCase {
async execute(email: string) {
Expand All @@ -24,25 +23,22 @@ export class GenerateCurriculumUseCase {
});

if (!aluno) throw new AppError("Aluno não encontrado");

if(aluno.endereco && aluno.rm && aluno.dataNascimento){

if (aluno.endereco && aluno.rm && aluno.dataNascimento) {
const hoje = new Date();
const dataNascimento = new Date(aluno.dataNascimento);

let idade = hoje.getFullYear() - dataNascimento.getFullYear();
const mesAtual = hoje.getMonth() + 1;
const mesNascimento = dataNascimento.getMonth() + 1;

if (
mesAtual < mesNascimento ||
(mesAtual === mesNascimento &&
hoje.getDate() < dataNascimento.getDate())
(mesAtual === mesNascimento && hoje.getDate() < dataNascimento.getDate())
) {
idade--;
}

const endereco = JSON.parse(aluno.endereco) as Endereco;
const endereco = JSON.parse(aluno.endereco) as Endereco;

const { name, curriculo } = aluno;
const title = aluno.turmas[0]?.turma?.curso?.name ? `Técnico(a) em ${aluno.turmas[0].turma.curso.name}` : "Estudante";
Expand All @@ -61,13 +57,12 @@ export class GenerateCurriculumUseCase {
})
.join("");


const bucketName = 'boot';
var imageName = aluno.imagem as string;

const objectExists = await minioClient.statObject(bucketName, imageName);
if (!objectExists) {
imageName = "assets/img/default_profile_image.png"
imageName = "assets/img/default_profile_image.png";
}
const imageURL = await minioClient.presignedUrl('GET', bucketName, imageName, 24 * 60 * 60);

Expand All @@ -92,21 +87,46 @@ export class GenerateCurriculumUseCase {
.replace('{{academicTraining}}', academicTraining)
.replace('{{img}}', imageBase64);

// Aqui começamos a usar o Puppeteer
const browser = await puppeteer.launch({
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH, // Usar o caminho do Chrome
headless: true, // Se quiser ver o navegador em ação, coloque como false
args: ['--no-sandbox', '--disable-setuid-sandbox'], // Adicionar flags
});

const file = { content: html };
const page = await browser.newPage();
await page.setContent(html);
const pdfBuffer = await page.pdf({ format: 'A4' });

const pdfBuffer = await html_to_pdf.generatePdf(file, { format: 'A4' });
await browser.close();

// Caminho do arquivo temporário para o PDF
const tempFilePath = path.join(__dirname, 'curriculo_temp.pdf');
fs.writeFileSync(tempFilePath, pdfBuffer);

const pdfPath = `aluno/${aluno.id}/curriculo.pdf`;
await uploadToMinio(bucketName, pdfPath, tempFilePath);

fs.unlinkSync(tempFilePath);
// Função de upload para o MinIO
try {
const pdfPath = `aluno/${aluno.rm}/curriculo.pdf`;
await this.uploadToMinio(bucketName, pdfPath, tempFilePath);
fs.unlinkSync(tempFilePath); // Remover o arquivo temporário após o upload

const url = await minioClient.presignedUrl('GET', bucketName, pdfPath, 24 * 60 * 60);
return { message: 'Currículo gerado com sucesso!', url };
} catch (error) {
console.error('Falha ao fazer upload do arquivo:', error);
throw new AppError("Falha ao fazer upload do arquivo no MinIO.");
}
}
}

const url = await minioClient.presignedUrl('GET', bucketName, pdfPath, 24 * 60 * 60);
return { message: 'Currículo gerado com sucesso!', url };
// Implementação da função de upload para o MinIO
async uploadToMinio(bucketName, objectName, filePath) {
try {
await minioClient.fPutObject(bucketName, objectName, filePath);
console.log(`Arquivo enviado com sucesso: ${objectName}`);
} catch (err) {
console.error('Error uploading file:', err);
throw new AppError('Erro ao fazer upload do arquivo', err); // Para tratamento de erros
}
}
}
}
3 changes: 1 addition & 2 deletions server/src/pdf/curriculum_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ <h2>Formação Acadêmica</h2>

<hr/>

<div class="box box-4">
<img src="" alt="">
<div class="box box-4">''
<p>🌐 https://boot.portfolioeducacionalrgs.com/aluno/profile/{{rm}}</p>
</div>

Expand Down

0 comments on commit 8d548f5

Please sign in to comment.