From de7dec827c23c0ad893a0743ef35c577bd64b329 Mon Sep 17 00:00:00 2001 From: vmaubert Date: Wed, 9 Mar 2022 10:46:05 +0100 Subject: [PATCH] =?UTF-8?q?fix(fichiers):=20ajoute=20automatiquement=20les?= =?UTF-8?q?=20dossiers=20utilis=C3=A9s=20pour=20stocker=20les=20fichiers?= =?UTF-8?q?=20(#913)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/files.ts | 10 +++++++ src/index.ts | 72 ++++++++++++++++++++++----------------------- src/types.ts | 8 ++++- 3 files changed, 52 insertions(+), 38 deletions(-) create mode 100644 src/config/files.ts diff --git a/src/config/files.ts b/src/config/files.ts new file mode 100644 index 000000000..fd9558e7e --- /dev/null +++ b/src/config/files.ts @@ -0,0 +1,10 @@ +import dirCreate from '../tools/dir-create' +import { DOCUMENTS_REPERTOIRES } from '../types' + +export const filesInit = async () => { + await dirCreate('files').catch() + + for (const documentsRepertoire of DOCUMENTS_REPERTOIRES) { + await dirCreate(`files/${documentsRepertoire}`).catch() + } +} diff --git a/src/index.ts b/src/index.ts index 168d0f628..a73468c92 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,51 +28,49 @@ import { databaseInit } from './database/init' import { consoleOverride, appLogger } from './config/logger' import cookieParser from 'cookie-parser' +import { filesInit } from './config/files' consoleOverride(appLogger) -databaseInit().then(() => { - const app = express() +filesInit().then(() => { + databaseInit().then(() => { + const app = express() - if (process.env.SENTRY_DSN) { - Sentry.init({ - dsn: process.env.SENTRY_DSN, - environment: process.env.ENV === 'prod' ? 'production' : process.env.ENV - }) - app.use(Sentry.Handlers.requestHandler()) - } + if (process.env.SENTRY_DSN) { + Sentry.init({ + dsn: process.env.SENTRY_DSN, + environment: process.env.ENV === 'prod' ? 'production' : process.env.ENV + }) + app.use(Sentry.Handlers.requestHandler()) + } - app.use( - cors({ credentials: true, exposedHeaders: ['Content-disposition'] }), - compression(), - cookieParser(), - authJwt, - authJwtError, - authBasic - ) - app.use(rest) + app.use( + cors({ credentials: true, exposedHeaders: ['Content-disposition'] }), + compression(), + cookieParser(), + authJwt, + authJwtError, + authBasic + ) + app.use(rest) - app.use('/televersement', uploadAllowedMiddleware, restUpload()) + app.use('/televersement', uploadAllowedMiddleware, restUpload()) - app.use('/', graphqlUpload, graphql) + app.use('/', graphqlUpload, graphql) - if (process.env.SENTRY_DSN) { - // test sentry - // app.get('/', (req, res) => { - // console.info('broke') - // throw new Error('Broke!') - // }) - app.use(Sentry.Handlers.errorHandler()) - } + if (process.env.SENTRY_DSN) { + app.use(Sentry.Handlers.errorHandler()) + } - app.listen(port, () => { - console.info('') - console.info('URL:', url) - console.info('ENV:', process.env.ENV) - console.info('NODE_ENV:', process.env.NODE_ENV) + app.listen(port, () => { + console.info('') + console.info('URL:', url) + console.info('ENV:', process.env.ENV) + console.info('NODE_ENV:', process.env.NODE_ENV) - if (process.env.NODE_DEBUG === 'true') { - console.warn('NODE_DEBUG:', process.env.NODE_DEBUG) - } - console.info('') + if (process.env.NODE_DEBUG === 'true') { + console.warn('NODE_DEBUG:', process.env.NODE_DEBUG) + } + console.info('') + }) }) }) diff --git a/src/types.ts b/src/types.ts index 888de675b..577430658 100644 --- a/src/types.ts +++ b/src/types.ts @@ -321,7 +321,13 @@ interface IDevise { ordre: number } -type IDocumentRepertoire = 'demarches' | 'activites' | 'entreprises' | 'tmp' +export const DOCUMENTS_REPERTOIRES = [ + 'demarches', + 'activites', + 'entreprises', + 'tmp' +] as const +type IDocumentRepertoire = typeof DOCUMENTS_REPERTOIRES[number] interface IDocumentType { id: string