diff --git a/next.config.js b/next.config.js index d1907f919..56d4be959 100644 --- a/next.config.js +++ b/next.config.js @@ -6,6 +6,10 @@ const BUILD_VERSION = process.env.BUILD_VERSION; // eslint-disable-next-line no-undef module.exports = withTM({ + env: { + // eslint-disable-next-line no-undef + ARCHIVE_MODE: process.env.ARCHIVE_MODE || 'false', + }, distDir: './dist/next', poweredByHeader: false, webpack: (config) => { diff --git a/server/controllers/archive.ts b/server/controllers/archive.ts index 0d08f3019..57b5770b6 100644 --- a/server/controllers/archive.ts +++ b/server/controllers/archive.ts @@ -6,20 +6,18 @@ import { streamFile } from '../fileUpload/streamFile'; import { Controller } from './controller'; const archiveController = new Controller('/archives'); +const userType = UserType.SUPER_ADMIN || UserType.ADMIN || UserType.MEDIATOR; // get file -archiveController.get( - { path: '/*', userType: [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR] }, - async (req: Request, res: Response, next: NextFunction) => { - const url = decodeURI(req.url); - const key = `archives${url}${url.split('/').length === 2 ? '/index.html' : url.indexOf('.') === -1 ? '.html' : ''}`; - try { - streamFile(key, req, res, next); - } catch { - next(); - } - }, -); +archiveController.get({ path: '/*', userType: userType }, async (req: Request, res: Response, next: NextFunction) => { + const url = decodeURI(req.url); + const key = `archives${url}${url.split('/').length === 2 ? '/index.html' : url.indexOf('.') === -1 ? '.html' : ''}`; + try { + streamFile(key, req, res, next); + } catch { + next(); + } +}); /** * Liste les dossiers dans un préfixe S3 spécifié. diff --git a/server/controllers/controller.ts b/server/controllers/controller.ts index a76171e27..a86b6a164 100644 --- a/server/controllers/controller.ts +++ b/server/controllers/controller.ts @@ -11,7 +11,7 @@ import { diskStorage } from '../middlewares/multer'; type RouteOptions = { path: string; - userType?: UserType | UserType[]; + userType?: UserType; }; fs.ensureDir(path.join(__dirname, '../fileUpload/videos')).catch(); diff --git a/server/middlewares/authenticate.ts b/server/middlewares/authenticate.ts index 758938c33..548a85b1c 100644 --- a/server/middlewares/authenticate.ts +++ b/server/middlewares/authenticate.ts @@ -1,4 +1,4 @@ -import type { NextFunction, Request, RequestHandler, Response } from 'express'; +import type { NextFunction, Request, Response, RequestHandler } from 'express'; import jwt from 'jsonwebtoken'; import { getNewAccessToken } from '../authentication/lib/tokens'; @@ -10,7 +10,7 @@ import { AppDataSource } from '../utils/data-source'; const secret: string = process.env.APP_SECRET || ''; export function authenticate(userType: UserType | undefined = undefined): RequestHandler { - return async (req: Request, res: Response, next: NextFunction): Promise<void> => { + return async (req: Request, res: Response, next: NextFunction) => { let token: string; if (req.cookies && req.cookies['access-token']) { if (!req.isCsrfValid && req.method !== 'GET') { diff --git a/src/components/accueil/Accueil.tsx b/src/components/accueil/Accueil.tsx index d5037fb09..437250f52 100644 --- a/src/components/accueil/Accueil.tsx +++ b/src/components/accueil/Accueil.tsx @@ -27,10 +27,19 @@ export const Accueil = () => { const router = useRouter(); const [withPagination, setWithPagination] = React.useState(true); + //Check if the app is in archive mode React.useEffect(() => { + const isArchiveMode = process.env.NEXT_PUBLIC_ARCHIVE_MODE === 'true'; + if (isArchiveMode) { + setWithPagination(false); + return; + } + if (!router.isReady) return; - setWithPagination(!('nopagination' in router.query)); - }, [router.isReady, router.query]); + const urlParams = new URLSearchParams(window.location.search); + const noPagination = urlParams.has('nopagination'); + setWithPagination(!noPagination); + }, [router.isReady]); //TODO: redo conditions and switchs const filterCountries = React.useMemo(() => { diff --git a/src/components/activities/List.tsx b/src/components/activities/List.tsx index 01da6caa5..c81e86130 100644 --- a/src/components/activities/List.tsx +++ b/src/components/activities/List.tsx @@ -76,10 +76,18 @@ export const Activities = ({ activities, noButtons = false, withLinks = false, w const [usePagination, setUsePagination] = React.useState(withPagination); React.useEffect(() => { + const isArchiveMode = process.env.NEXT_PUBLIC_ARCHIVE_MODE === 'true'; + if (isArchiveMode) { + setUsePagination(false); + return; + } + if (!router.isReady) { return; } - setUsePagination(!('nopagination' in router.query)); + const urlParams = new URLSearchParams(window.location.search); + const noPagination = urlParams.has('nopagination'); + setUsePagination(!noPagination); }, [router.isReady, router.query, withPagination]); React.useEffect(() => {