-
-
Notifications
You must be signed in to change notification settings - Fork 16
🛠️ DX: allow userRatings and userReviews to accept URLs #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { HTMLElement, parse } from 'node-html-parser'; | |||||||||||||||||
| import { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global'; | ||||||||||||||||||
| import { CSFDUserRatingConfig, CSFDUserRatings } from '../dto/user-ratings'; | ||||||||||||||||||
| import { fetchPage } from '../fetchers'; | ||||||||||||||||||
| import { sleep } from '../helpers/global.helper'; | ||||||||||||||||||
| import { extractId, sleep } from '../helpers/global.helper'; | ||||||||||||||||||
| import { | ||||||||||||||||||
| getUserRating, | ||||||||||||||||||
| getUserRatingColorRating, | ||||||||||||||||||
|
|
@@ -22,9 +22,14 @@ export class UserRatingsScraper { | |||||||||||||||||
| config?: CSFDUserRatingConfig, | ||||||||||||||||||
| options?: CSFDOptions | ||||||||||||||||||
| ): Promise<CSFDUserRatings[]> { | ||||||||||||||||||
| const id = extractId(user); | ||||||||||||||||||
| if (id === null || isNaN(id)) { | ||||||||||||||||||
| throw new Error('node-csfd-api: user must be a valid number or URL'); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+25
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strengthen user ID guard to positive integers only.
Suggested fix const id = extractId(user);
- if (id === null || isNaN(id)) {
+ if (id === null || !Number.isInteger(id) || id <= 0) {
throw new Error('node-csfd-api: user must be a valid number or URL');
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| let allMovies: CSFDUserRatings[] = []; | ||||||||||||||||||
| const pageToFetch = config?.page || 1; | ||||||||||||||||||
| const url = userRatingsUrl(user, pageToFetch > 1 ? pageToFetch : undefined, { | ||||||||||||||||||
| const url = userRatingsUrl(id, pageToFetch > 1 ? pageToFetch : undefined, { | ||||||||||||||||||
| language: options?.language | ||||||||||||||||||
| }); | ||||||||||||||||||
| const response = await fetchPage(url, { ...options?.request }); | ||||||||||||||||||
|
|
@@ -40,7 +45,7 @@ export class UserRatingsScraper { | |||||||||||||||||
| if (config?.allPages) { | ||||||||||||||||||
| for (let i = 2; i <= pages; i++) { | ||||||||||||||||||
| config.onProgress?.(i, pages); | ||||||||||||||||||
| const url = userRatingsUrl(user, i, { language: options?.language }); | ||||||||||||||||||
| const url = userRatingsUrl(id, i, { language: options?.language }); | ||||||||||||||||||
| const response = await fetchPage(url, { ...options?.request }); | ||||||||||||||||||
|
|
||||||||||||||||||
| const items = parse(response); | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalize path segments before numeric ID matching.
Line 20fails for URLs where the numeric segment includes query/hash suffixes (e.g.,/uzivatel/1000/?foo=bar). Strip?/#first so numeric URLs are parsed consistently.Suggested fix
🤖 Prompt for AI Agents