π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: fix images have no path
Nevo David196922602222
diff --git a/apps/frontend/src/components/media/media.component.tsx b/apps/frontend/src/components/media/media.component.tsxindex 0e9d6f959..82fdea13a 100644--- a/apps/frontend/src/components/media/media.component.tsx+++ b/apps/frontend/src/components/media/media.component.tsx@@ -577,14 +577,14 @@ export const MultiMediaComponent: FC<{<div className="cursor-pointer w-[40px] h-[40px] border-2 border-tableBorder relative flex"><divclassName="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)} />) : (<imgclassName="w-full h-full object-cover"- src={mediaDirectory.set(media.path)}+ src={mediaDirectory.set(media?.path)}/>)}</div>diff --git a/libraries/nestjs-libraries/src/database/prisma/media/media.repository.ts b/libraries/nestjs-libraries/src/database/prisma/media/media.repository.tsindex 06696e125..a2b5da582 100644--- a/libraries/nestjs-libraries/src/database/prisma/media/media.repository.ts+++ b/libraries/nestjs-libraries/src/database/prisma/media/media.repository.ts@@ -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: {diff --git a/libraries/nestjs-libraries/src/database/prisma/media/media.service.ts b/libraries/nestjs-libraries/src/database/prisma/media/media.service.tsindex 53840fa0a..921ebc117 100644--- a/libraries/nestjs-libraries/src/database/prisma/media/media.service.ts+++ b/libraries/nestjs-libraries/src/database/prisma/media/media.service.ts@@ -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,diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.tsindex 9f4c8523d..3b0d25ed7 100644--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts@@ -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: {diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.tsindex 5265ed887..d6d2155e0 100644--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts@@ -20,6 +20,7 @@ import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/climport { 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);}}diff --git a/libraries/react-shared-libraries/src/helpers/video.or.image.tsx b/libraries/react-shared-libraries/src/helpers/video.or.image.tsxindex 47e6b5a89..7cbded76d 100644--- a/libraries/react-shared-libraries/src/helpers/video.or.image.tsx+++ b/libraries/react-shared-libraries/src/helpers/video.or.image.tsx@@ -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 (<videosrc={src}