feat: pinterest fixes
This commit is contained in:
parent
2316a45388
commit
0b3328daeb
2 changed files with 18 additions and 5 deletions
|
|
@ -35,13 +35,18 @@ export default withProvider({
|
|||
CustomPreviewComponent: PinterestPreview,
|
||||
dto: PinterestSettingsDto,
|
||||
checkValidity: async ([firstItem, ...otherItems] = []) => {
|
||||
const isMp4 = firstItem?.find((item) => (item?.path?.indexOf?.('mp4') ?? -1) > -1);
|
||||
const isMp4 = firstItem?.find(
|
||||
(item) => (item?.path?.indexOf?.('mp4') ?? -1) > -1
|
||||
);
|
||||
const isPicture = firstItem?.find(
|
||||
(item) => (item?.path?.indexOf?.('mp4') ?? -1) === -1
|
||||
);
|
||||
if ((firstItem?.length ?? 0) === 0) {
|
||||
return 'Requires at least one media';
|
||||
}
|
||||
if ((firstItem?.length ?? 0) > 5) {
|
||||
return 'You can only have up to 5 media items';
|
||||
}
|
||||
if (isMp4 && firstItem?.length !== 2 && !isPicture) {
|
||||
return 'If posting a video you have to also include a cover image as second media';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import { Rules } from '@gitroom/nestjs-libraries/chat/rules.description.decorato
|
|||
import { hasExtension } from '@gitroom/helpers/utils/has.extension';
|
||||
|
||||
@Rules(
|
||||
'Pinterest requires at least one media, if posting a video, you must have two attachment, one for video, one for the cover picture, When posting a video, there can be only one'
|
||||
'Pinterest requires at least one media, if posting a video, you must have two attachment, one for video, one for the cover picture, When posting a video, there can be only one, if posting images, there can be maximum 5'
|
||||
)
|
||||
export class PinterestProvider
|
||||
extends SocialAbstract
|
||||
|
|
@ -51,6 +51,12 @@ export class PinterestProvider
|
|||
value: string;
|
||||
}
|
||||
| undefined {
|
||||
if (body.indexOf('constraint: maxItems=5') > -1) {
|
||||
return {
|
||||
type: 'bad-body' as const,
|
||||
value: 'You can upload a maximum of 5 images per post on Pinterest.',
|
||||
};
|
||||
}
|
||||
if (body.indexOf('cover_image_url or cover_image_content_type') > -1) {
|
||||
return {
|
||||
type: 'bad-body' as const,
|
||||
|
|
@ -185,8 +191,8 @@ export class PinterestProvider
|
|||
postDetails: PostDetails<PinterestSettingsDto>[]
|
||||
): Promise<PostResponse[]> {
|
||||
let mediaId = '';
|
||||
const findMp4 = postDetails?.[0]?.media?.find(
|
||||
(p) => hasExtension(p.path, 'mp4')
|
||||
const findMp4 = postDetails?.[0]?.media?.find((p) =>
|
||||
hasExtension(p.path, 'mp4')
|
||||
);
|
||||
const picture = postDetails?.[0]?.media?.find(
|
||||
(p) => !hasExtension(p.path, 'mp4')
|
||||
|
|
@ -292,7 +298,9 @@ export class PinterestProvider
|
|||
}
|
||||
: {
|
||||
source_type: 'multiple_image_urls',
|
||||
items: mapImages,
|
||||
items: mapImages.map((m) => ({
|
||||
url: m.path,
|
||||
})),
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue