feat: fix images have no path
This commit is contained in:
parent
b13a862b65
commit
1969226022
|
|
@ -577,14 +577,14 @@ export const MultiMediaComponent: FC<{
|
|||
<div className="cursor-pointer w-[40px] h-[40px] border-2 border-tableBorder relative flex">
|
||||
<div
|
||||
className="w-full h-full"
|
||||
onClick={() => window.open(mediaDirectory.set(media.path))}
|
||||
onClick={() => window.open(mediaDirectory.set(media?.path))}
|
||||
>
|
||||
{media.path.indexOf('mp4') > -1 ? (
|
||||
<VideoFrame url={mediaDirectory.set(media.path)} />
|
||||
{media?.path?.indexOf('mp4') > -1 ? (
|
||||
<VideoFrame url={mediaDirectory.set(media?.path)} />
|
||||
) : (
|
||||
<img
|
||||
className="w-full h-full object-cover"
|
||||
src={mediaDirectory.set(media.path)}
|
||||
src={mediaDirectory.set(media?.path)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,14 @@ export class MediaRepository {
|
|||
});
|
||||
}
|
||||
|
||||
getMediaById(id: string) {
|
||||
return this._media.model.media.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
deleteMedia(org: string, id: string) {
|
||||
return this._media.model.media.update({
|
||||
where: {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ export class MediaService {
|
|||
return this._mediaRepository.deleteMedia(org, id);
|
||||
}
|
||||
|
||||
getMediaById(id: string) {
|
||||
return this._mediaRepository.getMediaById(id);
|
||||
}
|
||||
|
||||
async generateImage(
|
||||
prompt: string,
|
||||
org: Organization,
|
||||
|
|
|
|||
|
|
@ -51,6 +51,17 @@ export class PostsRepository {
|
|||
});
|
||||
}
|
||||
|
||||
updateImages(id: string, images: string) {
|
||||
return this._post.model.post.update({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
data: {
|
||||
image: images,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
getPostUrls(orgId: string, ids: string[]) {
|
||||
return this._post.model.post.findMany({
|
||||
where: {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/cl
|
|||
import { timer } from '@gitroom/helpers/utils/timer';
|
||||
import { AuthTokenDetails } from '@gitroom/nestjs-libraries/integrations/social/social.integrations.interface';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import { MediaService } from '@gitroom/nestjs-libraries/database/prisma/media/media.service';
|
||||
dayjs.extend(utc);
|
||||
|
||||
type PostWithConditionals = Post & {
|
||||
|
|
@ -36,7 +37,8 @@ export class PostsService {
|
|||
private _notificationService: NotificationService,
|
||||
private _messagesService: MessagesService,
|
||||
private _stripeService: StripeService,
|
||||
private _integrationService: IntegrationService
|
||||
private _integrationService: IntegrationService,
|
||||
private _mediaService: MediaService
|
||||
) {}
|
||||
|
||||
async getPostsRecursively(
|
||||
|
|
@ -73,18 +75,63 @@ export class PostsService {
|
|||
return this._postRepository.getPosts(orgId, query);
|
||||
}
|
||||
|
||||
async updateMedia(id: string, imagesList: any[]) {
|
||||
let imageUpdateNeeded = false;
|
||||
const getImageList = (
|
||||
await Promise.all(
|
||||
imagesList.map(async (p: any) => {
|
||||
if (!p.path && p.id) {
|
||||
imageUpdateNeeded = true;
|
||||
return this._mediaService.getMediaById(p.id);
|
||||
}
|
||||
|
||||
return p;
|
||||
})
|
||||
)
|
||||
).map((m) => {
|
||||
return {
|
||||
...m,
|
||||
url:
|
||||
m.path.indexOf('http') === -1
|
||||
? process.env.FRONTEND_URL +
|
||||
'/' +
|
||||
process.env.NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY +
|
||||
m.path
|
||||
: m.path,
|
||||
type: 'image',
|
||||
path:
|
||||
m.path.indexOf('http') === -1
|
||||
? process.env.UPLOAD_DIRECTORY + m.path
|
||||
: m.path,
|
||||
};
|
||||
});
|
||||
|
||||
if (imageUpdateNeeded) {
|
||||
await this._postRepository.updateImages(id, JSON.stringify(getImageList));
|
||||
}
|
||||
|
||||
return getImageList;
|
||||
}
|
||||
|
||||
async getPost(orgId: string, id: string) {
|
||||
const posts = await this.getPostsRecursively(id, true, orgId, true);
|
||||
return {
|
||||
const list = {
|
||||
group: posts?.[0]?.group,
|
||||
posts: posts.map((post) => ({
|
||||
...post,
|
||||
image: JSON.parse(post.image || '[]'),
|
||||
})),
|
||||
posts: await Promise.all(
|
||||
posts.map(async (post) => ({
|
||||
...post,
|
||||
image: await this.updateMedia(
|
||||
post.id,
|
||||
JSON.parse(post.image || '[]')
|
||||
),
|
||||
}))
|
||||
),
|
||||
integrationPicture: posts[0]?.integration?.picture,
|
||||
integration: posts[0].integrationId,
|
||||
settings: JSON.parse(posts[0].settings || '{}'),
|
||||
};
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
async getOldPosts(orgId: string, date: string) {
|
||||
|
|
@ -280,25 +327,14 @@ export class PostsService {
|
|||
const publishedPosts = await getIntegration.post(
|
||||
integration.internalId,
|
||||
integration.token,
|
||||
newPosts.map((p) => ({
|
||||
id: p.id,
|
||||
message: p.content,
|
||||
settings: JSON.parse(p.settings || '{}'),
|
||||
media: (JSON.parse(p.image || '[]') as Media[]).map((m) => ({
|
||||
url:
|
||||
m.path.indexOf('http') === -1
|
||||
? process.env.FRONTEND_URL +
|
||||
'/' +
|
||||
process.env.NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY +
|
||||
m.path
|
||||
: m.path,
|
||||
type: 'image',
|
||||
path:
|
||||
m.path.indexOf('http') === -1
|
||||
? process.env.UPLOAD_DIRECTORY + m.path
|
||||
: m.path,
|
||||
})),
|
||||
})),
|
||||
await Promise.all(
|
||||
newPosts.map(async (p) => ({
|
||||
id: p.id,
|
||||
message: p.content,
|
||||
settings: JSON.parse(p.settings || '{}'),
|
||||
media: await this.updateMedia(p.id, JSON.parse(p.image || '[]')),
|
||||
}))
|
||||
),
|
||||
integration
|
||||
);
|
||||
|
||||
|
|
@ -802,7 +838,12 @@ export class PostsService {
|
|||
return this._postRepository.getComments(postId);
|
||||
}
|
||||
|
||||
createComment(orgId: string, userId: string, postId: string, comment: string) {
|
||||
createComment(
|
||||
orgId: string,
|
||||
userId: string,
|
||||
postId: string,
|
||||
comment: string
|
||||
) {
|
||||
return this._postRepository.createComment(orgId, userId, postId, comment);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export const VideoOrImage: FC<{
|
|||
isContain?: boolean;
|
||||
}> = (props) => {
|
||||
const { src, autoplay, isContain } = props;
|
||||
if (src.indexOf('mp4') > -1) {
|
||||
if (src?.indexOf('mp4') > -1) {
|
||||
return (
|
||||
<video
|
||||
src={src}
|
||||
|
|
|
|||
Loading…
Reference in New Issue