Skip to content
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

feat: add upload logs button #169

Merged
merged 3 commits into from
Nov 6, 2024
Merged

feat: add upload logs button #169

merged 3 commits into from
Nov 6, 2024

Conversation

AyushSehrawat
Copy link
Member

@AyushSehrawat AyushSehrawat commented Nov 6, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a log upload functionality on the settings page, allowing users to upload logs directly from the interface.
    • Added confirmation dialog for log uploads, detailing upload limits and retention.
  • Bug Fixes

    • Improved user feedback mechanisms with toast notifications for upload success or failure.
  • Documentation

    • Enhanced schema definitions for OAuth functionality and log upload responses.
  • Refactor

    • Updated types to handle IDs as strings instead of numbers for consistency across the application.

@AyushSehrawat AyushSehrawat marked this pull request as ready for review November 6, 2024 17:17
Copy link

coderabbitai bot commented Nov 6, 2024

Warning

Rate limit exceeded

@AyushSehrawat has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 41 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d2cc15d and 2af21a0.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce several updates across multiple files, primarily enhancing schema definitions, service methods, and TypeScript types. Key modifications include the addition of OAuth-related properties, adjustments to ID types from integers to strings, and the introduction of new schemas for log uploads. A new method for uploading logs is added to the service class, along with corresponding type imports. Additionally, the Svelte component for the settings page is updated to facilitate log uploads through a user interface, providing user feedback and confirmation before proceeding with the upload.

Changes

File Path Change Summary
src/lib/client/schemas.gen.ts - Updated AppModelSchema version from 0.16.2 to 0.18.0.
- Added debug_database property to AppModelSchema.
- Updated ContentModelSchema to include oauth object.
- Changed ids type from integer to string in RemoveResponseSchema, ResetResponseSchema, and RetryResponseSchema.
- Added TraktOauthModelSchema for OAuth credentials.
- Added UploadLogsResponseSchema with success and url properties.
src/lib/client/services.gen.ts - Added uploadLogs method to DefaultService class.
- Updated imports to include UploadLogsError and UploadLogsResponse2.
src/lib/client/types.gen.ts - Added debug_database property to AppModel type.
- Changed ids type from number to string in RemoveResponse, ResetResponse, and RetryResponse types.
- Introduced TraktOauthModel type and updated TraktModel to include it.
- Added UploadLogsResponse and UploadLogsResponse2 types.
- Changed id and item_id properties from number to string in several types.
src/routes/settings/about/+page.svelte - Added uploadLogs asynchronous function for log upload.
- Integrated Tooltip and AlertDialog components for user interface enhancements.
src/lib/tmdb.ts - Updated parameter types for getMovieDetails, getTVDetails, and getTVSeasonDetails functions from number to string.
src/routes/[type=mediaType]/[id]/+page.ts - Updated getDetails function to accept id as a string instead of a number.
src/routes/[type=mediaType]/[id]/[season]/+page.ts - Updated getDetails, mediaDetails, and getMediaItemDetails functions to accept tvID as a string instead of a number.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant Service
    participant API

    User->>UI: Click "Upload Logs"
    UI->>AlertDialog: Show confirmation dialog
    User->>AlertDialog: Confirm upload
    AlertDialog->>UI: Call uploadLogs()
    UI->>Service: Call uploadLogs()
    Service->>API: POST /api/v1/upload_logs
    API-->>Service: Response (success/error)
    Service-->>UI: Return response
    UI->>User: Show success/error notification
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 385ca25 and 9d501a7.

📒 Files selected for processing (4)
  • src/lib/client/schemas.gen.ts (10 hunks)
  • src/lib/client/services.gen.ts (2 hunks)
  • src/lib/client/types.gen.ts (9 hunks)
  • src/routes/settings/about/+page.svelte (3 hunks)
🔇 Additional comments (12)
src/routes/settings/about/+page.svelte (1)

8-10: LGTM: Imports are properly structured.

The new imports are correctly organized and necessary for the log upload feature implementation.

src/lib/client/services.gen.ts (1)

4-4: LGTM: Import statement correctly updated

The new types UploadLogsError and UploadLogsResponse2 are properly imported following the existing pattern.

src/lib/client/types.gen.ts (6)

14-14: LGTM: Optional debug property addition

The addition of the optional debug_database boolean property to AppModel is well-typed and follows TypeScript conventions.


519-519: LGTM: OAuth integration for Trakt

The addition of the optional oauth property to TraktModel properly integrates with the new OAuth functionality.


526-532: Consider security implications of OAuth credentials

The TraktOauthModel type includes sensitive OAuth credentials. Ensure:

  1. These credentials are properly encrypted at rest
  2. Not logged or exposed in client-side errors
  3. Transmitted securely over HTTPS
#!/bin/bash
# Check for potential credential logging
echo "Checking for potential credential logging..."
rg "console\.(log|error|info|debug)" --type ts | rg -i "oauth|token|secret"

# Check for HTTPS usage in API calls
echo "Checking for secure API calls..."
rg "fetch|axios|http" --type ts | rg -i "trakt"

545-551: LGTM: Well-documented logs upload response type

The UploadLogsResponse type is well-structured with clear documentation about size limits and retention period. The alias type maintains API versioning compatibility.

#!/bin/bash
# Check for proper error handling in log upload implementations
echo "Checking for error handling in log upload..."
rg "uploadLogs|UploadLogsResponse" -A 5 --type ts

Also applies to: 629-631


672-672: Verify ID type handling in API requests

The change from number to string for various id and item_id properties in API request types is a breaking change. Ensure:

  1. All API endpoints handle string IDs correctly
  2. All API clients are updated to send string IDs
#!/bin/bash
# Search for API calls using these endpoints
echo "Checking API client implementations..."
rg "GetItem|GetItemStreams|BlacklistStream|UnblacklistStream" -A 5 --type ts

# Search for potential number type assumptions
echo "Checking for number type assumptions..."
rg "parseInt|Number\(" --type ts

Also applies to: 729-729, 739-739, 750-750


341-341: Verify handling of string IDs in response consumers

The change from number[] to string[] for the ids property in response types is a breaking change. Ensure all consumers of these responses are updated to handle string IDs.

Also applies to: 346-346, 351-351

src/lib/client/schemas.gen.ts (4)

802-808: OAuth implementation follows security best practices.

The OAuth configuration is well-structured with:

  • Empty string defaults for sensitive fields
  • Clear separation of client credentials and tokens
  • Standard OAuth 2.0 fields (client_id, client_secret, access_token, refresh_token)

Also applies to: 2966-2996


2298-2298: ID type change improves flexibility.

The change from integer to string for IDs in response schemas allows for more flexible ID formats and aligns with best practices for unique identifiers.

Also applies to: 2317-2317, 2336-2336


3046-3064: Well-structured schema for log upload response.

The new UploadLogsResponse schema is well-defined with:

  • Appropriate URL validation constraints
  • Clear documentation of file size limits (50M) and retention policy (180 days)
  • Required field marking for both success and url properties

35-35: Verify version compatibility with dependent systems.

The version has been updated from 0.16.2 to 0.18.0, and a new debug database flag has been added. While the changes look good, this is a significant version bump that may require updates in dependent systems.

Also applies to: 47-51

✅ Verification successful

Version update is safe and aligned with project changes

The version update from 0.16.2 to 0.18.0 is consistent with the project's changelog and recent releases. The CHANGELOG.md shows a proper version progression through 0.16.3, 0.17.0, and now 0.18.0, with each version including documented features and fixes. The version is only used as a default value in schema definitions and doesn't impact runtime compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for version-dependent code that might need updates
rg -l "0.16.2" 

Length of output: 27


Script:

#!/bin/bash
# Check CHANGELOG.md content for version update context
cat CHANGELOG.md

# Search for any version checks or comparisons in the codebase
rg "version|Version" -A 2 -B 2

Length of output: 49756

src/routes/settings/about/+page.svelte Outdated Show resolved Hide resolved
src/routes/settings/about/+page.svelte Outdated Show resolved Hide resolved
src/routes/settings/about/+page.svelte Outdated Show resolved Hide resolved
src/lib/client/services.gen.ts Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range comments (2)
src/routes/[type=mediaType]/[id]/+page.ts (1)

Line range hint 19-33: Address TODO comment and optimize data fetching.

The function fetches multiple fields (credits, external_ids, recommendations, similar, videos, keywords) with a TODO comment indicating some might be unnecessary. Consider:

  1. Auditing which fields are actually used in the UI
  2. Implementing field selection based on usage requirements
  3. Adding field documentation for future maintenance

Example optimization:

+ // Define required fields based on UI requirements
+ const requiredFields = [
+   'credits',        // Used for cast/crew display
+   'external_ids',   // Used for external links
+   'videos',         // Used for trailers
+   // Add or remove fields based on actual usage
+ ].join(',');
+
 async function getDetails(type: string, id: string) {
   switch (type) {
     case 'movie':
-      // TODO: Remove the ones that are not needed in future
       return await getMovieDetails(
         fetch,
         'en-US',
-        'credits,external_ids,recommendations,similar,videos,keywords',
+        requiredFields,
         id
       );
     case 'tv':
       return await getTVDetails(
         fetch,
         'en-US',
-        'credits,external_ids,recommendations,similar,videos,keywords',
+        requiredFields,
         id
       );
   }
 }
src/routes/[type=mediaType]/[id]/[season]/+page.ts (1)

Line range hint 25-39: Consider improving type safety by replacing any types.

The function uses any types which reduces type safety. Consider defining proper interfaces for the API response and season data.

interface Season {
  number: number;
  episodes: Episode[];
}

interface Episode {
  // Add relevant episode properties
}

async function getMediaItemDetails(tvID: string): Promise<Episode[]> {
  const { data } = await ItemsService.getItem({
    path: { id: tvID },
    query: { use_tmdb_id: true }
  });
  
  if (!data) return [];
  
  const seasons = (data as { seasons: Season[] }).seasons;
  return seasons.find(season => season.number === season)?.episodes ?? [];
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 9d501a7 and d2cc15d.

📒 Files selected for processing (3)
  • src/lib/tmdb.ts (3 hunks)
  • src/routes/[type=mediaType]/[id]/+page.ts (2 hunks)
  • src/routes/[type=mediaType]/[id]/[season]/+page.ts (1 hunks)
🔇 Additional comments (7)
src/routes/[type=mediaType]/[id]/+page.ts (1)

8-8: Verify consistent ID handling across the application.

The change from Number() to String() for ID conversion aligns with the shift to string-based identifiers. However, let's verify that this change is consistently implemented across all TMDB-related functionality.

src/routes/[type=mediaType]/[id]/[season]/+page.ts (2)

16-16: LGTM: Consistent type changes across helper functions.

The tvID parameter type has been consistently updated from number to string across all helper functions, maintaining type consistency with the route parameter change.

Also applies to: 21-21, 25-25


9-9: Verify route parameter type change impact.

The change from Number to String for params.id aligns with the broader changes in the codebase. However, we should ensure all route handlers and client-side links are updated to handle string IDs.

src/lib/tmdb.ts (4)

Line range hint 118-126: Verify the impact of string ID in getMovieDetails.

The function now expects a string ID, but verify that:

  1. All callers are passing string IDs
  2. The TMDB API accepts string IDs in the URL

Let's check the usage:

#!/bin/bash
# Description: Find all calls to getMovieDetails
# Expected: Verify string conversion at call sites

rg -A 3 "getMovieDetails\(" --type ts
🧰 Tools
🪛 Biome

[error] 116-116: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


Line range hint 193-201: Verify the impact of string ID in getTVDetails.

The function now expects a string ID, but verify that:

  1. All callers are passing string IDs
  2. The TMDB API accepts string IDs in the URL

Let's check the usage:

#!/bin/bash
# Description: Find all calls to getTVDetails
# Expected: Verify string conversion at call sites

rg -A 3 "getTVDetails\(" --type ts
🧰 Tools
🪛 Biome

[error] 191-191: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


Line range hint 212-225: Verify the impact of string ID in getTVSeasonDetails.

The function now expects a string ID, but verify that:

  1. All callers are passing string IDs
  2. The TMDB API accepts string IDs in the URL

Let's check the usage:

#!/bin/bash
# Description: Find all calls to getTVSeasonDetails
# Expected: Verify string conversion at call sites

rg -A 3 "getTVSeasonDetails\(" --type ts
🧰 Tools
🪛 Biome

[error] 210-210: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


118-118: ⚠️ Potential issue

Inconsistent ID type usage across TMDB API functions.

The changes convert movieId and tvId parameters from number to string in some functions, but similar ID parameters in other functions still use the number type:

  • getTVEpisodeDetails: tvId: number
  • getExternalID: tmdb_id: number
  • getCollection: collectionId: number
  • getCredits: mediaId: number
  • getPerson: personId: number

This inconsistency could lead to type conversion issues and make the API harder to use correctly.

Let's verify the TMDB API documentation and usage:

Also applies to: 193-193, 212-212

@AyushSehrawat AyushSehrawat merged commit f0a50eb into main Nov 6, 2024
5 checks passed
@AyushSehrawat AyushSehrawat deleted the feat/add-upload-logs branch November 6, 2024 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant