feat: mewe
This commit is contained in:
parent
92abb07712
commit
71833f3f39
3 changed files with 38 additions and 13 deletions
|
|
@ -8,12 +8,25 @@ import { FC } from 'react';
|
|||
import { MeweDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/mewe.dto';
|
||||
import { MeweGroupSelect } from '@gitroom/frontend/components/new-launch/providers/mewe/mewe.group.select';
|
||||
import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values';
|
||||
import { Select } from '@gitroom/react/form/select';
|
||||
import { useWatch } from 'react-hook-form';
|
||||
|
||||
const MeweComponent: FC = () => {
|
||||
const form = useSettings();
|
||||
const postType = useWatch({ control: form.control, name: 'postType' });
|
||||
|
||||
return (
|
||||
<div>
|
||||
<MeweGroupSelect {...form.register('group')} />
|
||||
<Select
|
||||
label="Post To"
|
||||
{...form.register('postType')}
|
||||
>
|
||||
<option value="timeline">My Timeline</option>
|
||||
<option value="group">Group</option>
|
||||
</Select>
|
||||
{postType === 'group' && (
|
||||
<MeweGroupSelect {...form.register('group')} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
import { IsDefined, IsString, MinLength } from 'class-validator';
|
||||
import { IsIn, IsOptional, IsString, MinLength, ValidateIf } from 'class-validator';
|
||||
import { JSONSchema } from 'class-validator-jsonschema';
|
||||
|
||||
export class MeweDto {
|
||||
@IsIn(['timeline', 'group'])
|
||||
@JSONSchema({
|
||||
description: 'Where to post: timeline or group',
|
||||
})
|
||||
postType: 'timeline' | 'group';
|
||||
|
||||
@ValidateIf((o) => o.postType === 'group')
|
||||
@MinLength(1)
|
||||
@IsDefined()
|
||||
@IsString()
|
||||
@JSONSchema({
|
||||
description: 'Group must be an id',
|
||||
})
|
||||
group: string;
|
||||
@IsOptional()
|
||||
group?: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,6 +239,7 @@ export class MeweProvider extends SocialAbstract implements SocialProvider {
|
|||
integration: Integration
|
||||
): Promise<PostResponse[]> {
|
||||
const [firstPost] = postDetails;
|
||||
const postType = firstPost.settings.postType || 'group';
|
||||
const groupId = firstPost.settings.group;
|
||||
|
||||
// Upload photos if present (exclude videos)
|
||||
|
|
@ -257,15 +258,17 @@ export class MeweProvider extends SocialAbstract implements SocialProvider {
|
|||
postBody.uploadedPhotoIds = uploadedPhotoIds;
|
||||
}
|
||||
|
||||
const postUrl =
|
||||
postType === 'timeline'
|
||||
? `${this.meweHost}/api/dev/me/post`
|
||||
: `${this.meweHost}/api/dev/group/${groupId}/post`;
|
||||
|
||||
// MeWe post endpoint may return 204 (no content), so use raw fetch
|
||||
const postResponse = await fetch(
|
||||
`${this.meweHost}/api/dev/group/${groupId}/post`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: this.authHeaders(accessToken),
|
||||
body: JSON.stringify(postBody),
|
||||
}
|
||||
);
|
||||
const postResponse = await fetch(postUrl, {
|
||||
method: 'POST',
|
||||
headers: this.authHeaders(accessToken),
|
||||
body: JSON.stringify(postBody),
|
||||
});
|
||||
|
||||
if (!postResponse.ok) {
|
||||
const errorText = await postResponse.text();
|
||||
|
|
@ -285,11 +288,13 @@ export class MeweProvider extends SocialAbstract implements SocialProvider {
|
|||
postId = makeId(12);
|
||||
}
|
||||
|
||||
const releaseURL = `${this.meweHost}/post/show/${postId}`;
|
||||
|
||||
return [
|
||||
{
|
||||
id: firstPost.id,
|
||||
postId,
|
||||
releaseURL: `${this.meweHost}/group/${groupId}`,
|
||||
releaseURL,
|
||||
status: 'success',
|
||||
},
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue