Skip to content

Commit 19415cf

Browse files
committed
fix: avoid regex, properly paginate
1 parent 8c61a02 commit 19415cf

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

angular-ngrx-scss/src/app/repository/services/repository.service.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export class RepositoryService {
102102
url += `+sort:${params.sort}`;
103103
}
104104

105+
if (params?.page) {
106+
url += `&page=${params.page}`;
107+
}
108+
105109
return this.http
106110
.get(url, {
107111
observe: 'response',
@@ -387,20 +391,22 @@ export class RepositoryService {
387391
return 0;
388392
}
389393

390-
// Find the link with rel="last"
391-
const lastLinkPattern = /<([^>]+?)>; rel="last"/;
392-
const lastLinkMatch = linkHeader.match(lastLinkPattern);
394+
// Split the linkHeader by commas to separate individual links
395+
const links = linkHeader.split(',');
393396

394-
if (!lastLinkMatch) {
397+
// Find the last link in the header
398+
const lastLink = links
399+
.find((link) => link.includes('rel="last"'))
400+
?.split(';')[0]
401+
?.trim()
402+
.slice(1, -1);
403+
404+
if (!lastLink) {
395405
return 0;
396406
}
397407

398-
const lastLink = lastLinkMatch[1];
399-
400-
// Parse as a URL
401408
const url = new URL(lastLink);
402409

403-
// Extract query parameters
404410
const queryParams = new URLSearchParams(url.search);
405411
const page = parseInt(queryParams.get('page') || '', 10);
406412

0 commit comments

Comments
 (0)