8000 Support Video by takke · Pull Request #81 · uakihir0/kbsky · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support Video #81

8000
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

Merged
merged 7 commits into from
Sep 18, 2024
Merged

Support Video #81

merged 7 commits into from
Sep 18, 2024

Conversation

takke
Copy link
Contributor
@takke takke commented Sep 12, 2024

Support for playing and uploading videos.


動画の再生と投稿に対応しました。
再生は他とあまり変わりませんが、投稿についてはPDSと動画サーバが分かれているので連携がややこしいです。
PDS から getServiceAuth でトークンを生成し、それを動画サーバに渡すことで認証します。
uploadVideo はさらに url のパラメータに did とファイル名を含ませる必要があるなど、他とは色合いが違います。

サンプルがなくて申し訳ないです。

よろしくお願いします。

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced comprehensive video management capabilities, including video uploads, status checks, and retrieval of upload limits.
    • Added service authentication functionality for secure interactions with the server.
    • Enhanced embed functionality to support video content and aspect ratios, improving media representation.
  • Bug Fixes

    • Improved handling of content types in upload requests, ensuring correct file processing.
  • Documentation

    • Updated documentation to reflect new methods and classes related to video management and service authentication.

These updates significantly enhance user experience by providing robust video handling and secure service interactions within the application.

Copy link
coderabbitai bot commented Sep 12, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce new features and enhancements to the Bluesky API, focusing on video management and service authentication. Key additions include constants for video-related operations, a new VideoResource interface, and methods for handling video uploads and job status checks. Additionally, service authentication functionality is expanded with a new request and response structure, allowing clients to obtain authentication tokens for secure interactions.

Changes

Files Change Summary
core/src/commonMain/kotlin/work/socialhub/kbsky/BlueskyTypes.kt Added constants for video embedding and management: EmbedVideo, VideoGetJobStatus, VideoGetUploadLimits, VideoUploadVideo.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/app/bsky/VideoResource.kt Defined VideoResource interface with methods for managing video functionalities.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/com/atproto/ServerResource.kt Added getServiceAuth method for retrieving service authentication tokens.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetJobStatusRequest.kt Introduced VideoGetJobStatusRequest class for querying video job status.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetJobStatusResponse.kt Added VideoGetJobStatusResponse class for handling job status responses.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetUploadLimitsRequest.kt Created VideoGetUploadLimitsRequest class for retrieving upload limits.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetUploadLimitsResponse.kt Added VideoGetUploadLimitsResponse class for managing upload limits responses.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoUploadVideoRequest.kt Introduced VideoUploadVideoRequest class for video uploads.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoUploadVideoResponse.kt Added type alias VideoUploadVideoResponse for job status.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/com/atproto/server/ServerGetServiceAuthRequest.kt Created ServerGetServiceAuthRequest class for service authentication requests.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/com/atproto/server/ServerGetServiceAuthResponse.kt Added ServerGetServiceAuthResponse class for handling authentication responses.
core/src/commonMain/kotlin/work/socialhub/kbsky/internal/_Bluesky.kt Updated _Bluesky class to include VideoResource for video functionalities.
core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_VideoResource.kt Implemented _VideoResource class for managing video operations.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/video/JobStatus.kt Introduced JobStatus class for video processing job status representation.
core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/EmbedPolymorphicSerializer.kt Enhanced serializer to support EmbedVideo.
core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/EmbedViewPolymorphicSerializer.kt Updated serializer to handle EmbedVideoView.
core/src/jvmTest/kotlin/work/socialhub/kbsky/app/bsky/feed/PostTest.kt Added contentType parameter for image file creation in tests.
core/src/jvmTest/kotlin/work/socialhub/kbsky/com/atproto/repo/UploadBlobTest.kt Specified contentType for uploaded PNG images in tests.
core/src/jvmTest/kotlin/work/socialhub/kbsky/app/bsky/video/UploadVideoTest.kt Introduced UploadVideoTest class to test video upload functionalities and retrieval of upload limits.

Possibly related PRs

  • Add ATProtocolException.status #80: This PR involves modifications to the ATProtocolException class, which is directly related to the main PR's changes in the same file, enhancing error reporting capabilities.

🐰 In the meadow where videos play,
New features hop and dance all day.
With tokens and uploads, oh what a sight,
Bluesky shines, oh so bright!
Join the fun, let’s share and cheer,
For in this world, our joy is clear! 🌼


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 generate interesting stats about this repository and render them as a table.
    -- @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: 5

Outside diff range and nitpick comments (6)
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/com/atproto/server/ServerGetServiceAuthResponse.kt (1)

1-8: LGTM, but consider making the class immutable.

The code changes are approved. The class follows the naming convention, uses the @Serializable annotation correctly, and has a clear and descriptive property name.

However, consider making the class immutable by using a constructor parameter for the token property instead of lateinit. This ensures that the property is always initialized and prevents accidental reassignment.

Here's how you can refactor the class:

@Serializable
data class ServerGetServiceAuthResponse(val token: String)

Using a data class with a constructor parameter automatically generates a copy function, equals, hashCode, and toString methods, making the class more concise and easier to work with.

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedDefsAspectRatio.kt (1)

6-10: Add documentation comments to improve code readability.

To enhance the readability and maintainability of the code, consider adding documentation comments (/**...*/) to the class and its properties. This will help other developers understand the purpose and usage of the EmbedDefsAspectRatio class more easily.

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/video/JobStatus.kt (1)

10-11: Improve code documentation.

To enhance the code documentation, consider expanding the comment for the state property to provide more details about the possible states of a video processing job. You can include information about the meaning of each known state value and clarify what the other values represent when the job is in progress.

For example:

// The state of the video processing job.
// Known values:
// - "JOB_STATE_COMPLETED": The job has successfully completed.
// - "JOB_STATE_FAILED": The job has failed.
// All other values indicate that the job is currently in progress.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/com/atproto/server/ServerGetServiceAuthRequest.kt (1)

6-21: Add documentation comments and consider renaming properties for better clarity.

The ServerGetServiceAuthRequest class and its properties lack documentation comments explaining their purpose and usage. Consider adding documentation comments to help developers understand when and how to use this class.

Additionally, the property names aud, exp, and lxm are short and not very descriptive. Consider renaming them to more meaningful names or adding documentation comments to explain what they represent. For example:

/**
 * Represents a request to get service authentication.
 *
 * @property aud The audience (did) for the authentication token.
 * @property exp The expiration time for the authentication token.
 * @property lxm The lexicon version for the authentication token.
 */
class ServerGetServiceAuthRequest(
    accessJwt: String,
    val aud: String,
    val exp: Long? = null,
    val lxm: String? = null,
) : MapRequest, AuthRequest(accessJwt) {
    // ...
}

This will improve the readability and maintainability of the code.

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedVideoView.kt (1)

1-27: LGTM, but consider adding documentation comments.

The code changes look good and follow the necessary conventions. The class structure, property definitions, and serialization annotations are all implemented correctly.

To improve code readability and maintainability, consider adding documentation comments for the class and its properties. For example:

/**
 * Represents a video embed view.
 */
@Serializable
class EmbedVideoView : EmbedViewUnion() {
    // ...

    /**
     * The content identifier of the video.
     */
    lateinit var cid: String

    /**
     * The URI of the video playlist.
     */
    lateinit var playlist: String

    /**
     * The thumbnail URL of the video (optional).
     */
    var thumbnail: String? = null

    /**
     * The alternative text for the video (optional).
     */
    var alt: String? = null

    /**
     * The aspect ratio of the video (optional).
     */
    var aspectRatio: EmbedDefsAspectRatio? = null
}
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedVideo.kt (1)

12-29: LGTM, but address the TODO and add documentation.

The EmbedVideo class is correctly defined and follows the Kotlin conventions. However, please consider the following suggestions:

  1. Address the TODO comment about adding support for captions. If you plan to implement this feature in the future, consider creating a separate issue to track it.
  2. Add documentation for the properties to improve the readability and maintainability of the code. For example:
/**
 * The video blob.
 */
var video: Blob? = null

/**
 * The alternative text for the video.
 */
var alt: String? = null

/**
 * The aspect ratio of the video.
 */
var aspectRatio: EmbedDefsAspectRatio? = null
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f43cbe8 and 501ca0b.

Files selected for processing (29)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/ATProtocolTypes.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/Bluesky.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/BlueskyTypes.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/app/bsky/VideoResource.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/com/atproto/ServerResource.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetJobStatusRequest.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetJobStatusResponse.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetUploadLimitsRequest.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetUploadLimitsResponse.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoUploadVideoRequest.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoUploadVideoResponse.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/com/atproto/repo/RepoUploadBlobRequest.kt (1 8000 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/com/atproto/server/ServerGetServiceAuthRequest.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/com/atproto/server/ServerGetServiceAuthResponse.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/share/AuthRequest.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/_Bluesky.kt (3 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_VideoResource.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/com/atproto/_RepoResource.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/com/atproto/_ServerResource.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedDefsAspectRatio.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedUnion.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedVideo.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedVideoView.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedViewUnion.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/video/JobStatus.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/EmbedPolymorphicSerializer.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/EmbedViewPolymorphicSerializer.kt (2 hunks)
  • core/src/jvmTest/kotlin/work/socialhub/kbsky/app/bsky/feed/PostTest.kt (1 hunks)
  • core/src/jvmTest/kotlin/work/socialhub/kbsky/com/atproto/repo/UploadBlobTest.kt (1 hunks)
Files skipped from review due to trivial changes (1)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoUploadVideoResponse.kt
Additional comments not posted (34)
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedDefsAspectRatio.kt (1)

1-10: LGTM!

The code follows Kotlin naming conventions and is properly annotated with @Serializable. The class structure is clear and concise.

core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetUploadLimitsRequest.kt (1)

1-7: LGTM!

The code changes in this new file are approved. The VideoGetUploadLimitsRequest class is defined correctly, extending the AuthRequest class and taking an accessJwt parameter in its constructor. The class name and package structure follow the conventions of the project.

The purpose of this class is clear, representing a request for getting video upload limits. It doesn't contain any additional functionality beyond extending the AuthRequest class, which is appropriate for its intended use.

Overall, the code is clean, well-structured, and follows the project's conventions.

core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetJobStatusResponse.kt (1)

1-9: LGTM!

The code in this file follows Kotlin conventions and best practices. The VideoGetJobStatusResponse class is well-structured and serves a clear purpose within the context of the video-related functionality. The use of @Serializable annotation and the lateinit keyword for the jobStatus property is appropriate.

Overall, the code changes in this file are approved.

core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/com/atproto/repo/RepoUploadBlobRequest.kt (1)

9-9: Approve the addition of contentType but consider a more generic default value and missing parameters.

The addition of the contentType property is a good change as it allows specifying the media type of the uploaded blob, enhancing the functionality of the request.

However, the default value of "image/jpeg" might not be suitable for all use cases, especially for uploading videos as mentioned in the PR objectives. Consider using a more generic default value like "application/octet-stream" to support various media types.

-var contentType: String = "image/jpeg",
+var contentType: String = "application/octet-stream",

Also, the PR objectives mention that the uploadVideo function requires specific parameters in the URL, including the device ID (did) and the filename. These parameters are not reflected in the RepoUploadBlobRequest class. Could you please clarify how these parameters are being handled and if they need to be added to this class?

core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetUploadLimitsResponse.kt (1)

1-12: LGTM!

The code changes are approved. The VideoGetUploadLimitsResponse data class is well-defined with clear and descriptive property names. The use of nullable types for optional properties and the @Serializable annotation are appropriate.

core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoGetJobStatusRequest.kt (1)

1-16: LGTM!

The code changes are approved. The VideoGetJobStatusRequest class is correctly implemented with the following observations:

  • The package declaration and imports are correctly defined.
  • The class is correctly declared with the appropriate name, constructor parameters, and inheritance.
  • The toMap function is correctly overridden to return a map representation of the request.
  • The code follows the Kotlin coding conventions, is properly formatted, and follows the naming conventions.
  • The code does not have any error handling, concurrency, or security issues as it is a simple data class.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/video/JobStatus.kt (1)

1-17: LGTM!

The JobStatus data class is well-defined and follows the project's conventions. The properties are appropriately typed, and the use of nullable types for optional properties is correct. The @Serializable annotation ensures proper serialization support.

Great job!

core/src/commonMain/kotlin/work/socialhub/kbsky/Bluesky.kt (2)

8-8: LGTM!

The import statement is necessary to use the VideoResource class and aligns with the PR objective of implementing video-related functionality.


17-17: LGTM!

The addition of the video() function to the Bluesky interface expands its functionality to support video-related resources, which aligns with the PR objective. The function signature is also consistent with the other resource functions in the interface.

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedUnion.kt (2)

10-10: LGTM!

The documentation comment is correctly updated to reference EmbedVideo, which is consistent with the addition of the asVideo property.


21-21: LGTM!

The addition of the asVideo property to the EmbedUnion class is a valid change that enhances its functionality by providing an additional way to interact with video embeds, similar to the existing properties for other embed types. The implementation using the safe cast operator is correct and consistent with the existing code. This change aligns well with the PR objectives of implementing video functionality within the application.

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedViewUnion.kt (2)

10-10: LGTM!

The new KDoc comment is consistent with the existing comments and provides a clear reference to the EmbedVideoView class.


21-21: LGTM!

The new asVideo property is implemented consistently with the existing properties for other embed view types. It allows instances of EmbedViewUnion to be safely cast to EmbedVideoView, which aligns with the class's purpose and behavior.

core/src/jvmTest/kotlin/work/socialhub/kbsky/com/atproto/repo/UploadBlobTest.kt (1)

25-25: LGTM!

The code change is approved. Adding the contentType parameter with the value "image/png" is a good practice as it helps the server correctly handle the uploaded PNG image file.

core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/share/AuthRequest.kt (2)

28-28: LGTM!

The change to return the entire Jwt object instead of just the sub field is approved. It allows for greater flexibility without introducing any breaking changes or new issues.


14-17: LGTM, but verify jwt.sub is always non-null.

The change to make did non-nullable and retrieve its value from jwt.sub is approved as it enforces a more robust design. However, please ensure that jwt.sub will always have a value. If jwt.sub can be null, it will result in a runtime exception when accessing did.

Run the following script to verify that jwt.sub is always non-null:

Verification successful

Verification successful: jwt.sub is always non-null.

The jwt.sub property is declared as lateinit var sub: String, which ensures it is initialized before use and cannot be null. Additionally, there are no assignments of null to sub in the AuthRequest.kt file. This confirms that the change to make did non-nullable is safe and robust.

  • jwt.sub is declared as lateinit var sub: String, ensuring non-nullability.
  • No null assignments to sub were found.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `jwt.sub` is always non-null.

# Test 1: Search for nullable declarations of `sub` in `Jwt` class. Expect: No results.
rg --type kotlin $'lateinit var sub: String\?' -g AuthRequest.kt

# Test 2: Search for assignments of null to `sub` in `Jwt` class. Expect: No results.
rg --type kotlin $'sub = null' -g AuthRequest.kt

Length of output: 227

core/src/commonMain/kotlin/work/socialhub/kbsky/api/app/bsky/VideoResource.kt (2)

19-21: LGTM!

The code changes are approved. The function signature follows the naming convention and takes the appropriate request and response types.


26-28: LGTM!

The code changes are approved. The function signature follows the naming convention and takes the appropriate request and response types.

core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/EmbedPolymorphicSerializer.kt (2)

13-13: LGTM!

The code changes are approved.


26-26: LGTM!

The code changes are approved. The addition of the EmbedVideo case in the when expression is consistent with the existing pattern and is necessary to support deserialization of the EmbedVideo type.

core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/EmbedViewPolymorphicSerializer.kt (2)

11-11: LGTM!

The code changes are approved.


26-26: LGTM!

The code changes are approved. The new case correctly handles the EmbedVideoView type and enhances the functionality of the EmbedViewPolymorphicSerializer.

core/src/commonMain/kotlin/work/socialhub/kbsky/internal/_Bluesky.kt (3)

10-10: LGTM!

The imports are necessary to use the VideoResource and _VideoResource classes in the _Bluesky class.

Also applies to: 17-17


29-29: LGTM!

The addition of the video property is consistent with the other resource properties in the _Bluesky class. The initialization of the video property with an instance of _VideoResource class is also consistent with the initialization of other resource properties.


57-60: LGTM!

The addition of the video() method is consistent with the other resource methods in the _Bluesky class. The video() method correctly overrides an existing method and returns the video property.

core/src/commonMain/kotlin/work/socialhub/kbsky/api/com/atproto/ServerResource.kt (1)

55-62: LGTM!

The code changes are approved for the following reasons:

  • The function signature and return type are consistent with the provided specification.
  • The KDoc comment provides sufficient context about the purpose and usage of the function.
  • The function is essential for the video upload feature, as mentioned in the PR objectives.
core/src/commonMain/kotlin/work/socialhub/kbsky/ATProtocolTypes.kt (1)

48-48: LGTM!

The addition of the ServerGetServiceAuth constant to the ATProtocolTypes object is consistent with the existing pattern and naming convention. It aligns with the PR objective of implementing a getServiceAuth method for generating authentication tokens from the PDS.

The code changes are approved.

core/src/commonMain/kotlin/work/socialhub/kbsky/BlueskyTypes.kt (1)

26-26: LGTM!

The code changes are approved for the following reasons:

  • The constants are correctly defined and follow the naming convention used in the file.
  • The constants are public, which is consistent with the other constants in the file.
  • The constants are grouped under the "Video" category, which is a new category in the file.
  • The constants are consistent with the PR objectives, which mention the implementation of video playback and upload functionality.

Also applies to: 78-81

core/src/commonMain/kotlin/work/socialhub/kbsky/internal/com/atproto/_RepoResource.kt (1)

130-130: LGTM!

The code change is approved. Replacing the hardcoded "Content-Type" value with a dynamic value derived from request.contentType enhances the flexibility of the HTTP request handling and aligns with the PR objective of supporting video playback and upload functionality.

core/src/commonMain/kotlin/work/socialhub/kbsky/internal/com/atproto/_ServerResource.kt (1)

75-88: LGTM!

The code changes are approved. The new getServiceAuth function is correctly implemented and follows the existing pattern of other functions in the class. It enhances the functionality of the _ServerResource class by allowing it to handle service authentication, which was not previously implemented.

The function uses good practices such as:

  • Using the proceed function to handle the response.
  • Using the runBlocking function to perform the HTTP request.
  • Using the toMap function to convert the request parameters to a map.
  • Using the xrpc function to construct the URL.
  • Using the accept function to specify the expected response format.
  • Using the header function to add the authorization header.
core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_VideoResource.kt (4)

29-46: LGTM!

The getJobStatus function looks good. It follows the necessary steps to retrieve the video job status by obtaining a video token from the PDS and making an HTTP request to the video service endpoint with the required headers and parameters.


48-64: LGTM!

The getUploadLimits function looks good. It follows a similar pattern to getJobStatus and correctly retrieves the upload limits by obtaining a video token from the PDS and making an HTTP request to the video service endpoint with the required headers.


66-101: LGTM!

The uploadVideo function looks good. It follows the necessary steps to upload a video by obtaining a video token from the PDS with the required aud and lxm parameters and making an HTTP POST request to the video service endpoint with the necessary headers, parameters, and the video file.


103-116: LGTM!

The getVideoTokenFromPds helper function looks good. It correctly handles the process of obtaining a video token from the PDS by making a request to the _ServerResource with the provided parameters and extracting the bearer token from the response.

Comment on lines +8 to +9
var width: Int = 1
var height: Int = 1
Copy link

Choose a reason for hiding this comment

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

Consider adding validation for positive values.

To ensure that the width and height properties always have positive values, consider adding validation in the constructor or setter methods. This can help prevent unexpected behavior if negative values are assigned.


Consider making the properties immutable if the aspect ratio shouldn't change.

If the aspect ratio is not expected to change once set, consider declaring the width and height properties as val instead of var. This will make the properties immutable and prevent accidental modifications after the object is created.

Comment on lines +5 to +10
class VideoUploadVideoRequest(
accessJwt: String,
var bytes: ByteArray,
var name: String = "data.mp4",
var contentType: String = "video/mp4",
) : AuthRequest(accessJwt)
Copy link

Choose a reason for hiding this comment

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

Make constructor parameters immutable and add validation.

Consider the following suggestions to improve the VideoUploadVideoRequest class:

  1. Make bytes, name, and contentType vals instead of vars to ensure immutability. This will prevent unexpected modifications to these properties after the object is created.

  2. Add validation for the bytes parameter to ensure that it's not empty. This will help catch invalid requests early and provide better error messages to the caller.

  3. Add validation for the contentType parameter to ensure that it's a valid MIME type for videos. This will help catch invalid requests early and provide better error messages to the caller.

Apply this diff to make the suggested changes:

 class VideoUploadVideoRequest(
     accessJwt: String,
-    var bytes: ByteArray,
-    var name: String = "data.mp4",
-    var contentType: String = "video/mp4",
+    val bytes: ByteArray,
+    val name: String = "data.mp4",
+    val contentType: String = "video/mp4",
 ) : AuthRequest(accessJwt) {
+    init {
+        require(bytes.isNotEmpty()) { "bytes must not be empty" }
+        require(contentType.startsWith("video/")) { "contentType must be a valid video MIME type" }
+    }
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class VideoUploadVideoRequest(
accessJwt: String,
var bytes: ByteArray,
var name: String = "data.mp4",
var contentType: String = "video/mp4",
) : AuthRequest(accessJwt)
class VideoUploadVideoRequest(
accessJwt: String,
val bytes: ByteArray,
val name: String = "data.mp4",
val contentType: String = "video/mp4",
) : AuthRequest(accessJwt) {
init {
require(bytes.isNotEmpty()) { "bytes must not be empty" }
require(contentType.startsWith("video/")) { "contentType must be a valid video MIME type" }
}
}

Comment on lines +33 to +35
fun uploadVideo(
request: VideoUploadVideoRequest
): Response<VideoUploadVideoResponse>
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Missing did parameter in VideoUploadVideoRequest.

The VideoUploadVideoRequest class does not contain the did parameter as required by the PR objectives. The name parameter might serve as the filename, but this should be confirmed. Please verify how the did parameter is handled or consider adding it to the request class.

  • Location of VideoUploadVideoRequest class: core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/video/VideoUploadVideoRequest.kt
Analysis chain

LGTM, but verify the request parameters.

The code changes are approved. The function signature follows the naming convention and takes the appropriate request and response types.

However, the PR objectives mention that the uploadVideo function requires specific parameters in the URL, including the device ID (did) and the filename. Please verify that the VideoUploadVideoRequest class contains these parameters.

Run the following script to verify the request parameters:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the `VideoUploadVideoRequest` class contains the required parameters.

# Test: Search for the class definition. Expect: The class definition with the required parameters.
ast-grep --lang kotlin --pattern $'data class VideoUploadVideoRequest(
  $$$
  val did: String,
  val filename: String,
  $$$
)'

Length of output: 129


Script:

#!/bin/bash
# Description: Search for the `VideoUploadVideoRequest` class definition to confirm its existence and inspect its properties.

# Search for the class definition without specifying parameter names.
ast-grep --lang kotlin --pattern $'data class VideoUploadVideoRequest($$$)'

Length of output: 76


Script:

#!/bin/bash
# Description: Search for occurrences of `VideoUploadVideoRequest` in the codebase to find its definition or references.

# Search for any occurrences of `VideoUploadVideoRequest`.
rg 'VideoUploadVideoRequest' -A 5

Length of output: 3517

@@ -44,6 +44,7 @@ class PostTest : AbstractTest() {
accessJwt = accessJwt,
name = "icon.png",
bytes = stream.readBytes(),
contentType = "image/jpeg"
Copy link

Choose a reason for hiding this comment

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

Inconsistent file extension and content type.

The file being uploaded is named "icon.png", which suggests it's a PNG image. However, the contentType parameter is set to "image/jpeg", indicating a JPEG image. This inconsistency could lead to issues if the server or client relies on the content type for processing the image.

Consider using the correct content type that matches the file extension:

-contentType = "image/jpeg"
+contentType = "image/png"

Alternatively, rename the file to match the specified content type:

-name = "icon.png",
+name = "icon.jpg",
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and ha 8000 s no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
contentType = "image/jpeg"
contentType = "image/png"

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 and nitpick comments (4)
core/src/jvmTest/kotlin/work/socialhub/kbsky/app/bsky/video/UploadVideoTest.kt (4)

19-20: Use a configuration file or environment variable for the video file path.

The video file path is hard-coded in the test method. Consider using a configuration file or environment variable to specify the video file path. This will make the test more flexible and easier to maintain.


36-57: Use a configuration file or environment variable for the job timeout.

The job timeout is hard-coded to 60 seconds. Consider using a configuration file or environment variable to specify the job timeout. This will make the test more flexible and easier to maintain.


60-62: Handle job failures and timeouts gracefully.

The method throws an exception if the job fails or times out. Consider handling job failures and timeouts gracefully instead of throwing an exception. For example, you could log an error message and fail the test using an assertion.


94-98: Add assertions to validate the response data.

The method only prints the response data and does not perform any assertions on the response. Consider adding assertions to validate the response data. For example, you could assert that the canUpload field is true, the remainingDailyVideos and remainingDailyBytes fields are greater than or equal to 0, and the message and error fields are null.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 501ca0b and 890707c.

Files ignored due to path filters (2)
  • core/src/jvmTest/resources/video/heavy.mp4 is excluded by !**/*.mp4
  • core/src/jvmTest/resources/video/light.mp4 is excluded by !**/*.mp4
Files selected for processing (10)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/ATProtocolException.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/BlueskyConfig.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/share/ErrorResponse.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_VideoResource.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/com/atproto/_ServerResource.kt (3 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/share/_InternalUtility.kt (3 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedVideo.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/plc/DIDDetails.kt (0 hunks)
  • core/src/jvmTest/kotlin/work/socialhub/kbsky/app/bsky/feed/PostTest.kt (4 hunks)
  • core/src/jvmTest/kotlin/work/socialhub/kbsky/app/bsky/video/UploadVideoTest.kt (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/plc/DIDDetails.kt
Files skipped from review as they are similar to previous changes (4)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_VideoResource.kt
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/com/atproto/_ServerResource.kt
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/embed/EmbedVideo.kt
  • core/src/jvmTest/kotlin/work/socialhub/kbsky/app/bsky/feed/PostTest.kt
Additional context used
Learnings (1)
core/src/commonMain/kotlin/work/socialhub/kbsky/ATProtocolException.kt (1)
Learnt from: uakihir0
PR: uakihir0/kbsky#67
File: core/src/commonMain/kotlin/work/socialhub/kbsky/internal/_ATProtocol.kt:12-18
Timestamp: 2024-07-04T10:09:32.037Z
Learning: The `_ATProtocol` class now uses `ATProtocolConfig` in its constructor instead of a URI string. Ensure all instances of `_ATProtocol` are updated accordingly.
Additional comments not posted (10)
core/src/commonMain/kotlin/work/socialhub/kbsky/BlueskyConfig.kt (3)

3-3: LGTM!

The class declaration is syntactically correct. Extending ATProtocolConfig is a design decision that cannot be evaluated without additional context.


5-5: LGTM!

The property declaration is syntactically correct, and the default value aligns with the PR objectives.


6-6: LGTM!

The property declaration is syntactically correct, and the default value aligns with the PR objectives.

core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/share/ErrorResponse.kt (1)

10-12: LGTM!

The messageForDisplay function is a nice addition to the ErrorResponse class. It enhances the usability by providing a user-friendly way to retrieve error messages, ensuring that a meaningful message is always displayed, either from message or error.

The implementation is concise and accurate, using the ifBlank function to check if the message property is blank and falling back to the error property if needed.

core/src/commonMain/kotlin/work/socialhub/kbsky/ATProtocolException.kt (3)

8-9: LGTM!

The addition of status and body properties to the ATProtocolException class is a good enhancement. It allows the exception to carry more context about the error, which can be helpful for debugging and error handling. The nullable nature of the properties ensures that the exception can still be used even if the status code or response body is not available.


16-16: LGTM!

The modification to the secondary constructor is necessary to accommodate the new properties added to the primary constructor. By passing null for status and body, the constructor maintains its original behavior of creating an exception with only a message.


17-17: LGTM!

The modification to the secondary constructor is necessary to accommodate the new properties added to the primary constructor. By passing null for status and body, the constructor maintains its original behavior of creating an exception with only an exception.

core/src/commonMain/kotlin/work/socialhub/kbsky/internal/share/_InternalUtility.kt (3)

70-70: LGTM!

Passing the response.status to the handleError function is a good change. It provides additional context about the error state, which can aid in diagnosing issues more effectively.


96-96: LGTM!

Adding the optional status parameter to the handleError function is a good change. It allows the function to capture and propagate the HTTP response status code when an error occurs, enhancing the error handling by providing more context about the error.


108-111: LGTM!

Including the status parameter in the ATProtocolException instantiation is a good change. It further enriches the exception with relevant information, which is in line with the overall improvement to the error handling mechanism.

@uakihir0 uakihir0 merged commit f15c859 into uakihir0:main Sep 18, 2024
@takke takke deleted the add_video branch September 18, 2024 02:53
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.

2 participants
0