fix(tiktok): extract endopoint method outside of post()

This commit is contained in:
Keiwan Mosaddegh 2025-01-23 10:29:50 +01:00
parent 81eacbe6d5
commit aa3ffac193
1 changed files with 11 additions and 12 deletions

View File

@ -218,6 +218,16 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
}
}
private postingMethod(method: TikTokDto["content_posting_method"]): string {
switch (method) {
case 'UPLOAD':
return '/inbox/video/init/';
case 'DIRECT_POST':
default:
return '/video/init/';
}
}
async post(
id: string,
accessToken: string,
@ -225,22 +235,11 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
integration: Integration
): Promise<PostResponse[]> {
const [firstPost, ...comments] = postDetails;
const endpoint: string = (() => {
switch (firstPost.settings.content_posting_method) {
case 'UPLOAD':
return '/inbox/video/init/';
case 'DIRECT_POST':
default:
return '/video/init/';
}
})();
const {
data: { publish_id },
} = await (
await this.fetch(
`https://open.tiktokapis.com/v2/post/publish${endpoint}`,
`https://open.tiktokapis.com/v2/post/publish${this.postingMethod(firstPost.settings.content_posting_method)}`,
{
method: 'POST',
headers: {