-
-
Notifications
You must be signed in to change notification settings - Fork 16
π οΈ DX: Support full URLs and slugs as input for API methods #187
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 { CSFDUserReviews, CSFDUserReviewsConfig } from '../dto/user-reviews'; | ||||||||||||
| import { fetchPage } from '../fetchers'; | ||||||||||||
| import { sleep } from '../helpers/global.helper'; | ||||||||||||
| import { extractId, sleep } from '../helpers/global.helper'; | ||||||||||||
| import { | ||||||||||||
| getUserReviewColorRating, | ||||||||||||
| getUserReviewDate, | ||||||||||||
|
|
@@ -24,9 +24,10 @@ export class UserReviewsScraper { | |||||||||||
| config?: CSFDUserReviewsConfig, | ||||||||||||
| options?: CSFDOptions | ||||||||||||
| ): Promise<CSFDUserReviews[]> { | ||||||||||||
| const id = extractId(user) ?? user; | ||||||||||||
|
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. Silent fallback on invalid input is inconsistent with other services.
π‘οΈ Proposed fix to align with the throwing pattern- const id = extractId(user) ?? user;
+ const id = extractId(user);
+ if (!id) {
+ throw new Error('node-csfd-api: user must be a valid number, slug, or URL');
+ }π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||
| let allReviews: CSFDUserReviews[] = []; | ||||||||||||
| const pageToFetch = config?.page || 1; | ||||||||||||
| const url = userReviewsUrl(user, pageToFetch > 1 ? pageToFetch : undefined, { | ||||||||||||
| const url = userReviewsUrl(id, pageToFetch > 1 ? pageToFetch : undefined, { | ||||||||||||
| language: options?.language | ||||||||||||
| }); | ||||||||||||
| const response = await fetchPage(url, { ...options?.request }); | ||||||||||||
|
|
@@ -42,7 +43,7 @@ export class UserReviewsScraper { | |||||||||||
| if (config?.allPages) { | ||||||||||||
| for (let i = 2; i <= pages; i++) { | ||||||||||||
| config.onProgress?.(i, pages); | ||||||||||||
| const url = userReviewsUrl(user, i, { language: options?.language }); | ||||||||||||
| const url = userReviewsUrl(id, i, { language: options?.language }); | ||||||||||||
| const response = await fetchPage(url, { ...options?.request }); | ||||||||||||
|
|
||||||||||||
| const items = parse(response); | ||||||||||||
|
|
@@ -64,7 +65,10 @@ export class UserReviewsScraper { | |||||||||||
| const films: CSFDUserReviews[] = []; | ||||||||||||
| if (config) { | ||||||||||||
| if (config.includesOnly?.length && config.excludes?.length) { | ||||||||||||
| console.warn(`${LIB_PREFIX} Both 'includesOnly' and 'excludes' were provided. 'includesOnly' takes precedence:`, config.includesOnly); | ||||||||||||
| console.warn( | ||||||||||||
| `${LIB_PREFIX} Both 'includesOnly' and 'excludes' were provided. 'includesOnly' takes precedence:`, | ||||||||||||
| config.includesOnly | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
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.
Same silent-fallback inconsistency as
user-reviews.service.ts.extractId(user) ?? usersilently falls back to the raw string on invalid input rather than throwing early. Apply the same guard pattern used increator.service.tsandmovie.service.ts.π‘οΈ Proposed fix
π Committable suggestion
π€ Prompt for AI Agents