Skip to content

Commit

Permalink
Merge pull request #2 from parlemonde/feat/VIL-621
Browse files Browse the repository at this point in the history
feat(VIL-621): adding nopagination option to archive
  • Loading branch information
Lukasambry authored Nov 14, 2024
2 parents 4365530 + 20286ac commit 255dc59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Logs

.DS*Store
.idea
logs
*.log
npm-debug.log\_
Expand Down
14 changes: 13 additions & 1 deletion src/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ const SELECTORS = {
};

const PHASES = [1, 2, 3];
/**
* Récupère l'URL de l'archive. Ajoute le paramètre nopagination pour éviter la pagination.
* @param baseUrl
* @param pathName
*/
async function getArchiveUrl(baseUrl: string, pathName: string = ''): Promise<string> {
const url = new URL(`${baseUrl}/${pathName}`);
// Ajouter le paramètre nopagination
url.searchParams.append('nopagination', 'true');
return url.toString();
}

async function gotoWithRetry(page: Page, url: string, maxAttempts = 5): Promise<void> {
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
Expand Down Expand Up @@ -72,7 +83,8 @@ async function archivePage(dirPath: string, page: Page, ressources: Record<strin
visitedPages[pathName] = true;
logger.info(`Archiving ${villageName}, phase ${phase}, page: "/${pathName}"`);
await sleep(2000);
await gotoWithRetry(page, `${process.env.URL_TO_ARCHIVE}/${pathName}`);
const archiveUrl = await getArchiveUrl(process.env.URL_TO_ARCHIVE || '', pathName);
await gotoWithRetry(page, archiveUrl);
/**
* Gère la navigation entre les différentes phases d'un village.
* Ce bloc est exécuté uniquement pour la page d'accueil de chaque phase.
Expand Down

0 comments on commit 255dc59

Please sign in to comment.