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(tiktok): add content posting method alternatives (direct post vs upload) #573

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

keiwanmosaddegh
Copy link

@keiwanmosaddegh keiwanmosaddegh commented Jan 23, 2025

What kind of change does this PR introduce?

This PR adds the option to pick between direct post and upload on the TikTok posting API.

Why was this change needed?

The current TikTok provider is based on the Direct Post API. The way to extend this and enable TikTok Draft Uploads is by introducing a new TikTok provider variant.

Checklist:

Put a "X" in the boxes below to indicate you have followed the checklist;

  • I have read the CONTRIBUTING guide.
  • I checked that there were not similar issues or PRs already open for this.
  • This PR fixes just ONE issue (do not include multiple issues or types of change in the same PR) For example, don't try and fix a UI issue and include new dependencies in the same PR.

Summary by CodeRabbit

  • New Features

    • Introduced a selection for TikTok content posting methods, allowing users to choose between direct posting and uploading without posting.
    • Added descriptive guidance above the selection to assist users in understanding their options.
  • Improvements

    • Enhanced TikTok integration by accommodating different content posting strategies based on user selection.
    • Adjusted the posting process to dynamically handle content based on the chosen posting method.

Copy link

vercel bot commented Jan 23, 2025

@keiwanmosaddegh is attempting to deploy a commit to the Listinai Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Jan 23, 2025

Walkthrough

The changes introduce a new feature for TikTok content posting methods, allowing users to choose between directly posting content or uploading content without posting. This functionality is implemented across multiple files, including the frontend component, data transfer object (DTO), and TikTok integration provider. The modification enables more flexible content management by adding a content_posting_method option that can be set to either 'DIRECT_POST' or 'UPLOAD'.

Changes

File Change Summary
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx Added contentPostingMethod constant, new <Select> element for content posting method selection, and descriptive text above the <Select> in TikTokSettings component.
libraries/nestjs-libraries/src/dtos/posts/providers-settings/tiktok.dto.ts Introduced content_posting_method property with 'DIRECT_POST' or 'UPLOAD' values in TikTokDto class.
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts Modified post method to handle different endpoint URLs and request body based on content posting method, added postingMethod private method.

Possibly related PRs

  • Add instagram as a standalone without a business #522: The changes in the main PR, which involve the addition of a new constant and a <Select> element for content posting methods in the TikTokSettings component, are related to the modifications in the retrieved PR that introduce a new property content_posting_method in the TikTokDto class, as both involve the handling of content posting methods for TikTok.

Poem

🐰 A TikTok tale of posting might,
Direct or upload, now set just right!
With methods two, the choice is clear,
Rabbit's code brings flexibility near!
Hop along the social media stream,
Where content flows with coding dream! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e888dc5 and 2e75212.

📒 Files selected for processing (1)
  • apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (1)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1)

229-237: Simplify the endpoint selection logic.

The switch statement can be simplified since 'DIRECT_POST' case and default return the same value.

-    const endpoint: string = (() => {
-      switch (firstPost.settings.content_posting_method) {
-        case 'UPLOAD':
-          return '/inbox/video/init/';
-        case 'DIRECT_POST':
-        default:
-          return '/video/init/';
-      }
-    })();
+    const endpoint = firstPost.settings.content_posting_method === 'UPLOAD'
+      ? '/inbox/video/init/'
+      : '/video/init/';
🧰 Tools
🪛 Biome (1.9.4)

[error] 233-233: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc60ed4 and 81eacbe.

📒 Files selected for processing (3)
  • apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (2 hunks)
  • libraries/nestjs-libraries/src/dtos/posts/providers-settings/tiktok.dto.ts (1 hunks)
  • libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts

[error] 233-233: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

🔇 Additional comments (4)
libraries/nestjs-libraries/src/dtos/posts/providers-settings/tiktok.dto.ts (1)

36-38: LGTM! Property is well-defined and properly validated.

The new content_posting_method property is correctly implemented with appropriate validation decorators and type restrictions.

libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1)

251-261: LGTM! Clean conditional request body construction.

The post_info object is correctly included only for DIRECT_POST method, maintaining a clean separation between posting methods.

apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (2)

36-45: LGTM! Well-defined options with clear labels.

The content posting method options are clearly defined with descriptive labels that help users understand the difference between the two posting methods.


140-152: LGTM! Select component is properly integrated.

The Select component is well-implemented with:

  • Clear labeling
  • Proper form registration
  • Sensible default value ('DIRECT_POST')

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

🧹 Nitpick comments (1)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1)

221-229: Enhance type safety and simplify switch statement.

The method implementation can be improved for better type safety and readability:

- private postingMethod(method: TikTokDto["content_posting_method"]): string {
-     switch (method) {
-       case 'UPLOAD':
-         return '/inbox/video/init/';
-       case 'DIRECT_POST':
-       default:
-       return '/video/init/';
-   }
- }
+ private postingMethod(method: TikTokDto["content_posting_method"]): string {
+     return method === 'UPLOAD' 
+       ? '/inbox/video/init/' 
+       : '/video/init/';
+ }

The refactor:

  1. Simplifies the logic by using a ternary operator
  2. Removes the redundant case clause flagged by static analysis
🧰 Tools
🪛 Biome (1.9.4)

[error] 225-225: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81eacbe and aa3ffac.

📒 Files selected for processing (1)
  • libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts

[error] 225-225: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

🔇 Additional comments (1)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1)

242-242: Document posting method behaviors and add validation.

The conditional inclusion of post_info only for 'DIRECT_POST' needs clarification:

  1. Please add JSDoc comments to document the behavioral differences between posting methods:
/**
 * Posts content to TikTok using either direct post or upload method.
 * @param id - The user's ID
 * @param accessToken - The access token
 * @param postDetails - Array of post details where the first item contains posting configuration
 * @param integration - Integration details
 * 
 * @remarks
 * - DIRECT_POST: Includes post_info in the request for immediate publishing
 * - UPLOAD: Excludes post_info to support draft uploads
 */
  1. Consider adding validation to ensure required fields are present based on the posting method:
if (firstPost.settings.content_posting_method === 'DIRECT_POST' && !firstPost.message) {
  throw new Error('Title is required for direct posts');
}
  1. Run this script to verify the API behavior for both posting methods:

Also applies to: 250-260

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

🧹 Nitpick comments (1)
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (1)

141-142: Fix unescaped single quotes.

Replace the single quotes with their HTML entity equivalents to resolve the ESLint warnings.

-        Choose upload without posting if you want to review and edit your content within TikTok's app before publishing.
-        This gives you access to TikTok's built-in editing tools and lets you make final adjustments before posting.
+        Choose upload without posting if you want to review and edit your content within TikTok&apos;s app before publishing.
+        This gives you access to TikTok&apos;s built-in editing tools and lets you make final adjustments before posting.
🧰 Tools
🪛 eslint

[error] 141-141: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


[error] 142-142: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa3ffac and 1df0b98.

📒 Files selected for processing (1)
  • apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (2 hunks)
🧰 Additional context used
🪛 eslint
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx

[error] 141-141: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


[error] 142-142: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)

🔇 Additional comments (4)
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (4)

36-45: LGTM! Well-structured options for content posting methods.

The constant follows the established pattern and provides clear, descriptive labels for each option.


140-143: Great addition of explanatory text!

The explanation effectively addresses why users might choose to upload without posting, providing clear benefits of this option.

🧰 Tools
🪛 eslint

[error] 141-141: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


[error] 142-142: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


144-156: LGTM! Well-implemented Select component.

The component follows the established pattern, properly integrates with form state, and maintains backward compatibility with the default 'DIRECT_POST' value.


146-148: Verify backend handling of the default value.

Ensure that the backend properly handles the default 'DIRECT_POST' value for existing posts and migrations if necessary.

✅ Verification successful

Backend handling of 'DIRECT_POST' value is properly implemented

The backend codebase shows proper type definitions and handling of the 'DIRECT_POST' value:

  • Defined as a valid option in tiktok.dto.ts
  • Actively used in conditional logic in tiktok.provider.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for backend handling of content_posting_method
rg -t ts "content_posting_method.*DIRECT_POST" -g "!*test*"

Length of output: 338


Script:

#!/bin/bash
# Search for migrations or schema definitions related to content_posting_method
rg -t ts "content_posting_method" -g "*migration*" -g "*schema*" -g "*entity*"

Length of output: 78

@keiwanmosaddegh
Copy link
Author

@nevo-david ready for your 👀 when you are!

Copy link

@A1exKH A1exKH left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link

@A1exKH A1exKH left a comment

Choose a reason for hiding this comment

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

@egelhaus
Copy link
Collaborator

egelhaus commented Jan 31, 2025

Hey, I don't think this is really needed, because Postiz was made to schedule a post to directly post it, with this Feature, you can just upload it yourself, this doesn't require Postiz.

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1df0b98 and e888dc5.

📒 Files selected for processing (1)
  • apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (7 hunks)
🧰 Additional context used
🪛 ESLint
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx

[error] 145-145: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


[error] 146-146: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)

🔇 Additional comments (6)
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (6)

36-45: New Constant contentPostingMethod Defined
The new constant cleanly defines the available posting methods. For improved maintainability, consider adding a brief inline comment explaining its purpose and usage in relation to the posting options.


123-123: Watching the Posting Method Value
The hook call using watch('content_posting_method') correctly retrieves the form value for the posting method.


125-125: Determining Upload Mode
The boolean isUploadMode is correctly set based on whether the posting method equals 'UPLOAD'. This variable is then used to conditionally disable dependent fields.


Line range hint 132-140: Conditional Disabling of Privacy Level Select
Disabling the privacy level <Select> when in upload mode is consistent with the intended business logic, assuming privacy settings are not applicable during a draft upload.


144-147: Descriptive Text for Upload Option (Addressing Prior Feedback & ESLint Warnings)
The newly added text explains why a user might choose the upload option, effectively addressing the previous comment about providing context. However, ESLint reports unescaped apostrophes on these lines. Consider replacing apostrophes with HTML entities (e.g., &rsquo;) or refactoring the text to avoid the warning.

🧰 Tools
🪛 ESLint

[error] 145-145: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


[error] 146-146: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


168-176: Conditional Disabling of Feature Checkboxes
Disabling the "Duet", "Stitch", and "Comments" checkboxes when in upload mode enforces the intended restrictions. This use of disabled={isUploadMode} maintains consistency with the form behavior.

Comment on lines +148 to +161
<Select
label="Content posting method"
disabled={isUploadMode}
{...register('content_posting_method', {
value: 'DIRECT_POST',
})}
>
<option value="">Select</option>
{contentPostingMethod.map((item) => (
<option key={item.value} value={item.value}>
{item.label}
</option>
))}
</Select>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Review the 'Content Posting Method' Select Disabled Prop
The <Select> element for choosing the content posting method is currently disabled when isUploadMode is true. This behavior will lock the selection to 'UPLOAD' once chosen, preventing the user from toggling back to 'DIRECT_POST'. It is likely that the posting method control should remain enabled at all times to allow switching.

Proposed change:

-      <Select
-        label="Content posting method"
-        disabled={isUploadMode}
-        {...register('content_posting_method', {
-          value: 'DIRECT_POST',
-        })}
-      >
+      <Select
+        label="Content posting method"
+        {...register('content_posting_method', {
+          value: 'DIRECT_POST',
+        })}
+      >
📝 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
<Select
label="Content posting method"
disabled={isUploadMode}
{...register('content_posting_method', {
value: 'DIRECT_POST',
})}
>
<option value="">Select</option>
{contentPostingMethod.map((item) => (
<option key={item.value} value={item.value}>
{item.label}
</option>
))}
</Select>
<Select
label="Content posting method"
{...register('content_posting_method', {
value: 'DIRECT_POST',
})}
>
<option value="">Select</option>
{contentPostingMethod.map((item) => (
<option key={item.value} value={item.value}>
{item.label}
</option>
))}
</Select>

@keiwanmosaddegh
Copy link
Author

@egelhaus I had a discussion with @nevo-david about this in #off-topic (sorry about that hehe).

The reason why there is a need for this is because you can't add TikTok sounds to a video through the direct posting API. However, if you push the videos to TikTok draft you can edit them before posting.

I know it isn't scheduled and posted directly to the public, however it's scheduled and posted to the TikTok platform where there is someone who processes the video and ultimately posts it.

Does that make sense to you?

@egelhaus
Copy link
Collaborator

egelhaus commented Feb 2, 2025

Hey, Yes it does make sense to me that the TikTok Editor is better than ours. It still defeats the Scheduling Putpose, but alright, this will make sense in a specific Scenario probably.

@keiwanmosaddegh
Copy link
Author

keiwanmosaddegh commented Feb 2, 2025 via email

@egelhaus
Copy link
Collaborator

egelhaus commented Feb 2, 2025

Hey, no this PR can be still opened, I only said that to get the Opinion of you on why this is needed, but it could be used to just upload it one time and then have it on all Platforms including on TikTok, without having to upload it again and just edit it.

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.

4 participants