Skip to content

Commit

Permalink
Merge pull request #1008 from parlemonde/feat/VIL-621
Browse files Browse the repository at this point in the history
feat(VIL-621): adding new archive mode
  • Loading branch information
Allanrdeau authored Nov 21, 2024
2 parents a81edc7 + ed3600c commit aea45b4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
22 changes: 10 additions & 12 deletions server/controllers/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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é.
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions server/middlewares/authenticate.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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') {
Expand Down
13 changes: 11 additions & 2 deletions src/components/accueil/Accueil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
10 changes: 9 additions & 1 deletion src/components/activities/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit aea45b4

Please sign in to comment.