Skip to content

Commit b8e3f53

Browse files
committed
feat: fix tiktok for photos
1 parent 894cb33 commit b8e3f53

File tree

4 files changed

+102
-12
lines changed

4 files changed

+102
-12
lines changed

apps/frontend/src/components/new-launch/providers/tiktok/tiktok.provider.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { useCustomProviderFunction } from '@gitroom/frontend/components/launches
1919
import { Checkbox } from '@gitroom/react/form/checkbox';
2020
import clsx from 'clsx';
2121
import { useT } from '@gitroom/react/translation/get.transation.service.client';
22+
import { useIntegration } from '@gitroom/frontend/components/launches/helpers/use.integration';
23+
import { Input } from '@gitroom/react/form/input';
2224

2325
const CheckTikTokValidity: FC<{
2426
picture: string;
@@ -85,9 +87,14 @@ const CheckTikTokValidity: FC<{
8587
const TikTokSettings: FC<{
8688
values?: any;
8789
}> = (props) => {
88-
const { watch, register, formState, control } = useSettings();
90+
const { watch, register } = useSettings();
91+
const { value } = useIntegration();
8992
const t = useT();
9093

94+
const isTitle = useMemo(() => {
95+
return value?.[0].image.some((p) => p.path.indexOf('mp4') === -1);
96+
}, [value]);
97+
9198
const disclose = watch('disclose');
9299
const brand_organic_toggle = watch('brand_organic_toggle');
93100
const brand_content_toggle = watch('brand_content_toggle');
@@ -142,6 +149,9 @@ const TikTokSettings: FC<{
142149
return (
143150
<div className="flex flex-col">
144151
<CheckTikTokValidity picture={props?.values?.[0]?.image?.[0]?.path} />
152+
{isTitle && (
153+
<Input label="Title" {...register('title')} maxLength={90} />
154+
)}
145155
<Select
146156
label={t('label_who_can_see_this_video', 'Who can see this video?')}
147157
hideErrors={true}

libraries/nestjs-libraries/src/dtos/posts/providers-settings/tiktok.dto.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { IsBoolean, IsDefined, IsIn, IsString } from 'class-validator';
1+
import { IsBoolean, ValidateIf, IsIn, IsString, MaxLength } from 'class-validator';
22

33
export class TikTokDto {
4+
@ValidateIf(p => p.title)
5+
@MaxLength(90)
6+
title: string;
7+
48
@IsIn([
59
'PUBLIC_TO_EVERYONE',
610
'MUTUAL_FOLLOW_FRIENDS',
@@ -32,10 +36,6 @@ export class TikTokDto {
3236
@IsBoolean()
3337
brand_organic_toggle: boolean;
3438

35-
// @IsIn(['true'])
36-
// @IsDefined()
37-
// isValidVideo: boolean;
38-
3939
@IsIn(['DIRECT_POST', 'UPLOAD'])
4040
@IsString()
4141
content_posting_method: 'DIRECT_POST' | 'UPLOAD';

libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
6666
};
6767
}
6868

69+
if (body.indexOf('1404006') > -1) {
70+
return {
71+
type: 'bad-body' as const,
72+
value: "We couldn't post your comment, A security check in facebook required to proceed.",
73+
};
74+
}
75+
6976
if (body.indexOf('1404102') > -1) {
7077
return {
7178
type: 'bad-body' as const,

libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,63 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
6363
};
6464
}
6565

66-
// Spam/Policy errors
66+
if (body.indexOf('file_format_check_failed') > -1) {
67+
return {
68+
type: 'bad-body' as const,
69+
value: 'File format is invalid, please check video specifications',
70+
};
71+
}
72+
73+
if (body.indexOf('duration_check_failed') > -1) {
74+
return {
75+
type: 'bad-body' as const,
76+
value: 'Video duration is invalid, please check video specifications',
77+
};
78+
}
79+
80+
if (body.indexOf('frame_rate_check_failed') > -1) {
81+
return {
82+
type: 'bad-body' as const,
83+
value: 'Video frame rate is invalid, please check video specifications',
84+
};
85+
}
86+
87+
if (body.indexOf('video_pull_failed') > -1) {
88+
return {
89+
type: 'bad-body' as const,
90+
value: 'Failed to pull video from URL, please check the URL',
91+
};
92+
}
93+
94+
if (body.indexOf('photo_pull_failed') > -1) {
95+
return {
96+
type: 'bad-body' as const,
97+
value: 'Failed to pull photo from URL, please check the URL',
98+
};
99+
}
100+
101+
if (body.indexOf('spam_risk_user_banned_from_posting') > -1) {
102+
return {
103+
type: 'bad-body' as const,
104+
value:
105+
'Account banned from posting, please check TikTok account status',
106+
};
107+
}
108+
109+
if (body.indexOf('spam_risk_text') > -1) {
110+
return {
111+
type: 'bad-body' as const,
112+
value: 'TikTok detected potential spam in the post text',
113+
};
114+
}
115+
116+
if (body.indexOf('spam_risk') > -1) {
117+
return {
118+
type: 'bad-body' as const,
119+
value: 'TikTok detected potential spam',
120+
};
121+
}
122+
67123
if (body.indexOf('spam_risk_too_many_posts') > -1) {
68124
return {
69125
type: 'bad-body' as const,
@@ -125,14 +181,21 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
125181
}
126182

127183
// Server errors
128-
if (body.indexOf('internal_error') > -1) {
184+
if (body.indexOf('internal') > -1) {
129185
return {
130186
type: 'bad-body' as const,
131-
value: 'TikTok server error, please try again later',
187+
value: 'There is a problem with TikTok servers, please try again later',
132188
};
133189
}
134190

135191
// Generic TikTok API errors
192+
if (body.indexOf('picture_size_check_failed') > -1) {
193+
return {
194+
type: 'bad-body' as const,
195+
value: 'Picture size is invalid',
196+
};
197+
}
198+
136199
if (body.indexOf('TikTok API error') > -1) {
137200
return {
138201
type: 'bad-body' as const,
@@ -358,8 +421,9 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
358421
postDetails: PostDetails<TikTokDto>[],
359422
integration: Integration
360423
): Promise<PostResponse[]> {
361-
const [firstPost, ...comments] = postDetails;
424+
const [firstPost] = postDetails;
362425

426+
const isPhoto = (firstPost?.media?.[0]?.path?.indexOf('mp4') || -1) === -1;
363427
const {
364428
data: { publish_id },
365429
} = await (
@@ -379,8 +443,17 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
379443
'DIRECT_POST') === 'DIRECT_POST'
380444
? {
381445
post_info: {
382-
title: firstPost.message,
383-
privacy_level: firstPost.settings.privacy_level || 'PUBLIC_TO_EVERYONE',
446+
...((firstPost?.settings?.title && isPhoto) ||
447+
(firstPost.message && !isPhoto)
448+
? {
449+
title: isPhoto
450+
? firstPost.settings.title
451+
: firstPost.message,
452+
}
453+
: {}),
454+
...(isPhoto ? { description: firstPost.message } : {}),
455+
privacy_level:
456+
firstPost.settings.privacy_level || 'PUBLIC_TO_EVERYONE',
384457
disable_duet: !firstPost.settings.duet || false,
385458
disable_comment: !firstPost.settings.comment || false,
386459
disable_stitch: !firstPost.settings.stitch || false,

0 commit comments

Comments
 (0)