Skip to content

Commit

Permalink
fix: remoção do diretório com data no upload de imagem (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanRamos01 authored Mar 28, 2024
1 parent 751ae93 commit 88197f5
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/controllers/uploads-controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { renameSync, existsSync, mkdirSync } from 'fs';
import moment from 'moment-timezone';
import { join, extname } from 'path';

import { storage } from '../config/directory';
Expand Down Expand Up @@ -34,22 +33,15 @@ export const post = (request, response, next) => {
return TomboFoto.create(body, { transaction });
})
.then(foto => {
const subdiretorio = moment()
.format('YYYY-MM-DD');

const basediretorio = join(storage, subdiretorio);
if (!existsSync(basediretorio)) {
// @ts-ignore
mkdirSync(basediretorio, { recursive: true });
if (!existsSync(storage)) {
mkdirSync(storage, { recursive: true });
}

// @ts-ignore
const nomeArquivo = `HCF${String(foto.id).padStart(9, '0')}`;
// @ts-ignore
const numeroBarra = `${foto.id}.${''.padEnd(6, '0')}`;

const extensao = extname(file.originalname);
const caminho = join(subdiretorio, `${nomeArquivo}${extensao}`);
const caminho = `${nomeArquivo}${extensao}`;

const atualizacao = {
...foto,
Expand Down

0 comments on commit 88197f5

Please sign in to comment.