Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: fix integrations + import option + reelfarm

Nevo David8c0307808682
diff --git a/apps/backend/src/api/routes/third-party.controller.ts b/apps/backend/src/api/routes/third-party.controller.ts
index 26f5b7946..eb4248610 100644
--- a/apps/backend/src/api/routes/third-party.controller.ts
+++ b/apps/backend/src/api/routes/third-party.controller.ts
@@ -14,6 +14,7 @@ import { Organization } from '@prisma/client';
import { AuthService } from '@gitroom/helpers/auth/auth.service';
import { UploadFactory } from '@gitroom/nestjs-libraries/upload/upload.factory';
import { MediaService } from '@gitroom/nestjs-libraries/database/prisma/media/media.service';
+import { ImportMediaDto } from '@gitroom/nestjs-libraries/dtos/third-party/import-media.dto';
@ApiTags('Third Party')
@Controller('/third-party')
@@ -121,6 +122,52 @@ export class ThirdPartyController {
);
}
+ @Post('/:id/import')
+ async importMedia(
+ @GetOrgFromRequest() organization: Organization,
+ @Param('id') id: string,
+ @Body() body: ImportMediaDto
+ ) {
+ const thirdParty = await this._thirdPartyManager.getIntegrationById(
+ organization.id,
+ id
+ );
+
+ if (!thirdParty) {
+ throw new HttpException('Integration not found', 404);
+ }
+
+ const thirdPartyInstance = this._thirdPartyManager.getThirdPartyByName(
+ thirdParty.identifier
+ );
+
+ if (!thirdPartyInstance) {
+ throw new HttpException('Invalid identifier', 400);
+ }
+
+ const downloadUrls = await thirdPartyInstance?.instance?.['importMedia']?.(
+ AuthService.fixedDecryption(thirdParty.apiKey),
+ body.items
+ );
+
+ if (!downloadUrls || !Array.isArray(downloadUrls)) {
+ throw new HttpException('Import not supported', 400);
+ }
+
+ const results = [];
+ for (const item of downloadUrls) {
+ const file = await this.storage.uploadSimple(item.url);
+ const saved = await this._mediaService.saveFile(
+ organization.id,
+ item.name || file.split('/').pop(),
+ file
+ );
+ results.push(saved);
+ }
+
+ return results;
+ }
+
@Post('/:identifier')
async addApiKey(
@GetOrgFromRequest() organization: Organization,
diff --git a/apps/frontend/public/icons/third-party/reelfarm.png b/apps/frontend/public/icons/third-party/reelfarm.png
new file mode 100644
index 000000000..583ad5a03
Binary files /dev/null and b/apps/frontend/public/icons/third-party/reelfarm.png differ
diff --git a/apps/frontend/src/components/media/media.component.tsx b/apps/frontend/src/components/media/media.component.tsx
index a0eb1b2f4..dac41d252 100644
--- a/apps/frontend/src/components/media/media.component.tsx
+++ b/apps/frontend/src/components/media/media.component.tsx
@@ -33,6 +33,7 @@ import { ReactSortable } from 'react-sortablejs';
import { MediaComponentInner } from '@gitroom/frontend/components/launches/helpers/media.settings.component';
import { AiVideo } from '@gitroom/frontend/components/launches/ai.video';
import { useModals } from '@gitroom/frontend/components/layout/new-modal';
+import { ThirdPartyMediaLibrary } from '@gitroom/frontend/components/third-parties/third-party.media-library';
import { Dashboard } from '@uppy/react';
import {
ChevronLeftIcon,
@@ -427,7 +428,12 @@ export const MediaBox: FC<{
className="hidden"
multiple={true}
/>
- {!isLoading && !!data?.results?.length && btn}
+ {!isLoading && !!data?.results?.length && (
+ <div className="flex gap-[8px]">
+ {btn}
+ <ThirdPartyMediaLibrary onImported={() => mutate()} />
+ </div>
+ )}
</div>
<div className="w-full pointer-events-none relative mt-[5px] mb-[5px]">
<div className="w-full h-[46px] overflow-hidden absolute left-0 bg-newBgColorInner uppyChange">
@@ -481,7 +487,10 @@ export const MediaBox: FC<{
'You can also drag & drop pictures.'
)}
</div>
- <div className="forceChange">{btn}</div>
+ <div className="forceChange flex gap-[8px]">
+ {btn}
+ <ThirdPartyMediaLibrary onImported={() => mutate()} />
+ </div>
</>
)}
{isLoading && (
diff --git a/apps/frontend/src/components/third-parties/third-party.component.tsx b/apps/frontend/src/components/third-parties/third-party.component.tsx
index e6f344bc9..056c3780c 100644
--- a/apps/frontend/src/components/third-parties/third-party.component.tsx
+++ b/apps/frontend/src/components/third-parties/third-party.component.tsx
@@ -150,7 +150,7 @@ export const ThirdPartyComponent = () => {
<div className="flex-1 flex flex-col gap-[14px]">
<div
className={clsx(
- 'gap-[16px] flex flex-col relative justify-center group/profile hover:bg-boxHover rounded-e-[8px]'
+ 'gap-[16px] flex flex-col relative justify-center rounded-e-[8px]'
)}
>
{!isLoading && !data?.length ? (
@@ -159,14 +159,14 @@ export const ThirdPartyComponent = () => {
data?.map((p: any) => (
<div
key={p.id}
- className={clsx('flex gap-[8px] items-center')}
+ className={clsx('flex gap-[8px] items-center group/profile hover:bg-boxHover')}
>
- <div className="h-full w-[4px] -ms-[12px] rounded-s-[3px] opacity-0 group-hover/profile:opacity-100 transition-opacity">
+ <div className="h-full w-[4px] rounded-s-[3px] opacity-0 group-hover/profile:opacity-100 transition-opacity">
<SVGLine />
</div>
<div
className={clsx(
- 'relative rounded-full flex justify-center items-center bg-fifth'
+ 'relative rounded-full flex justify-center items-center'
)}
data-tooltip-id="tooltip"
data-tooltip-content={p.title}
diff --git a/apps/frontend/src/components/third-parties/third-party.media-library.tsx b/apps/frontend/src/components/third-parties/third-party.media-library.tsx
new file mode 100644
index 000000000..9b02713f1
--- /dev/null
+++ b/apps/frontend/src/components/third-parties/third-party.media-library.tsx
@@ -0,0 +1,291 @@
+'use client';
+
+import React, { FC, useCallback, useState } from 'react';
+import { useFetch } from '@gitroom/helpers/utils/custom.fetch';
+import useSWR from 'swr';
+import { useT } from '@gitroom/react/translation/get.transation.service.client';
+import { useModals } from '@gitroom/frontend/components/layout/new-modal';
+import { useToaster } from '@gitroom/react/toaster/toaster';
+import clsx from 'clsx';
+import { VideoFrame } from '@gitroom/react/helpers/video.frame';
+import { Pagination } from '@gitroom/frontend/components/media/media.component';
+
+const ThirdPartyMediaLibraryBrowser: FC<{
+ integration: any;
+ onImported: () => void;
+}> = ({ integration, onImported }) => {
+ const fetch = useFetch();
+ const t = useT();
+ const toaster = useToaster();
+ const modals = useModals();
+ const [page, setPage] = useState(0);
+ const [selected, setSelected] = useState<any[]>([]);
+ const [importing, setImporting] = useState(false);
+
+ const loadMedia = useCallback(async () => {
+ return (
+ await fetch(
+ `/third-party/function/${integration.id}/listMedia`,
+ {
+ body: JSON.stringify({ page: page + 1 }),
+ method: 'POST',
+ }
+ )
+ ).json();
+ }, [integration.id, page]);
+
+ const { data, isLoading } = useSWR(
+ `media-library-${integration.id}-${page}`,
+ loadMedia,
+ {
+ revalidateOnFocus: false,
+ revalidateOnReconnect: false,
+ revalidateIfStale: false,
+ }
+ );
+
+ const toggleSelect = useCallback(
+ (item: any) => {
+ const exists = selected.find((s) => s.id === item.id);
+ if (exists) {
+ setSelected(selected.filter((s) => s.id !== item.id));
+ } else {
+ setSelected([...selected, item]);
+ }
+ },
+ [selected]
+ );
+
+ const importSelected = useCallback(async () => {
+ if (!selected.length) return;
+ setImporting(true);
+ try {
+ await fetch(`/third-party/${integration.id}/import`, {
+ method: 'POST',
+ body: JSON.stringify({
+ items: selected.map((s) => ({ url: s.url, name: s.name })),
+ }),
+ });
+ toaster.show(
+ t('media_imported_successfully', 'Media imported successfully'),
+ 'success'
+ );
+ onImported();
+ modals.closeCurrent();
+ } catch {
+ toaster.show(
+ t('media_import_failed', 'Failed to import media'),
+ 'warning'
+ );
+ } finally {
+ setImporting(false);
+ }
+ }, [selected, integration.id]);
+
+ return (
+ <div className="flex flex-col gap-[16px] h-full">
+ <div className="text-[14px] font-[600]">
+ {t('select_media_to_import', 'Select media to import from')}{' '}
+ {integration.title}: {integration.name}
+ </div>
+ <div className="flex-1 relative">
+ <div className="absolute left-0 top-0 w-full h-full overflow-x-hidden overflow-y-auto scrollbar scrollbar-thumb-newColColor scrollbar-track-newBgColorInner">
+ {isLoading && (
+ <div className="grid grid-cols-4 gap-[8px]">
+ {[...new Array(8)].map((_, i) => (
+ <div
+ key={i}
+ className="aspect-square bg-newSep rounded-[6px] animate-pulse"
+ />
+ ))}
+ </div>
+ )}
+ {!isLoading && (!data?.results || !data.results.length) && (
+ <div className="flex items-center justify-center h-full text-textColor/60">
+ {t('no_media_found', 'No media found')}
+ </div>
+ )}
+ {!isLoading && !!data?.results?.length && (
+ <div className="grid grid-cols-4 gap-[8px]">
+ {data.results.map((item: any) => {
+ const isSelected = !!selected.find((s) => s.id === item.id);
+ return (
+ <div
+ key={item.id}
+ onClick={() => toggleSelect(item)}
+ className="cursor-pointer aspect-square rounded-[6px] overflow-hidden relative group"
+ >
+ <div
+ className={clsx(
+ 'w-full h-full border-[4px] rounded-[6px]',
+ isSelected
+ ? 'border-[#612BD3]'
+ : 'border-transparent'
+ )}
+ >
+ {item.type === 'video' ? (
+ <VideoFrame url={item.thumbnail || item.url} />
+ ) : (
+ <img
+ className="w-full h-full object-cover rounded-[4px]"
+ src={item.thumbnail || item.url}
+ alt={item.name || ''}
+ />
+ )}
+ </div>
+ {isSelected && (
+ <div className="text-white flex z-[10] justify-center items-center text-[14px] font-[500] w-[24px] h-[24px] rounded-full bg-[#612BD3] absolute -bottom-[2px] -end-[2px]">
+ {selected.findIndex((s) => s.id === item.id) + 1}
+ </div>
+ )}
+ {item.name && (
+ <div className="absolute bottom-[4px] start-[4px] text-[10px] text-white bg-black/50 px-[4px] rounded truncate max-w-[90%]">
+ {item.name}
+ </div>
+ )}
+ </div>
+ );
+ })}
+ </div>
+ )}
+ </div>
+ </div>
+ {(data?.pages || 0) > 1 && (
+ <Pagination
+ current={page}
+ totalPages={data?.pages}
+ setPage={setPage}
+ />
+ )}
+ <div className="flex justify-end gap-[8px]">
+ <button
+ onClick={() => modals.closeCurrent()}
+ className="cursor-pointer h-[52px] px-[20px] items-center justify-center border border-newTextColor/10 flex rounded-[10px]"
+ >
+ {t('cancel', 'Cancel')}
+ </button>
+ <button
+ onClick={importSelected}
+ disabled={!selected.length || importing}
+ className="cursor-pointer text-white disabled:opacity-80 disabled:cursor-not-allowed h-[52px] px-[20px] items-center justify-center bg-[#612BD3] flex rounded-[10px] gap-[8px]"
+ >
+ {importing && (
+ <div className="animate-spin h-[16px] w-[16px] border-2 border-white border-t-transparent rounded-full" />
+ )}
+ {t('import_selected', 'Import Selected')} ({selected.length})
+ </button>
+ </div>
+ </div>
+ );
+};
+
+const ThirdPartyMediaLibraryPicker: FC<{
+ integrations: any[];
+ onImported: () => void;
+}> = ({ integrations, onImported }) => {
+ const [selected, setSelected] = useState<any>(null);
+ const t = useT();
+
+ if (selected) {
+ return (
+ <div className="flex flex-col h-full">
+ <div
+ className="cursor-pointer mb-[10px]"
+ onClick={() => setSelected(null)}
+ >
+ {'<'} {t('back', 'Back')}
+ </div>
+ <ThirdPartyMediaLibraryBrowser
+ integration={selected}
+ onImported={onImported}
+ />
+ </div>
+ );
+ }
+
+ return (
+ <div className="grid grid-cols-4 gap-[10px] justify-items-center justify-center">
+ {integrations.map((p: any) => (
+ <div
+ key={p.id}
+ onClick={() => setSelected(p)}
+ className="w-full h-full p-[20px] min-h-[100px] text-[14px] bg-newTableHeader hover:bg-newTableBorder rounded-[8px] transition-all text-textColor relative flex flex-col gap-[15px] cursor-pointer"
+ >
+ <div>
+ <img
+ className="w-[32px] h-[32px] rounded-full"
+ src={`/icons/third-party/${p.identifier}.png`}
+ />
+ </div>
+ <div className="whitespace-pre-wrap text-left text-lg">
+ {p.title}: {p.name}
+ </div>
+ <div className="whitespace-pre-wrap text-left">{p.description}</div>
+ </div>
+ ))}
+ </div>
+ );
+};
+
+export const ThirdPartyMediaLibrary: FC<{
+ onImported: () => void;
+}> = ({ onImported }) => {
+ const fetch = useFetch();
+ const t = useT();
+ const modals = useModals();
+
+ const loadThirdParties = useCallback(async () => {
+ return (await (await fetch('/third-party')).json()).filter(
+ (f: any) => f.position === 'media-library'
+ );
+ }, []);
+
+ const { data, isLoading } = useSWR(
+ 'third-party-media-library',
+ loadThirdParties,
+ {
+ revalidateOnFocus: false,
+ revalidateOnReconnect: false,
+ revalidateIfStale: false,
+ revalidateOnMount: true,
+ }
+ );
+
+ if (isLoading || !data?.length) {
+ return null;
+ }
+
+ return (
+ <button
+ onClick={() => {
+ modals.openModal({
+ title: t('import_from', 'Import From'),
+ fullScreen: true,
+ size: 'calc(100% - 80px)',
+ height: 'calc(100% - 80px)',
+ children: () => (
+ <ThirdPartyMediaLibraryPicker
+ integrations={data}
+ onImported={onImported}
+ />
+ ),
+ });
+ }}
+ className="cursor-pointer bg-btnSimple changeColor flex gap-[8px] h-[44px] px-[18px] justify-center items-center rounded-[8px]"
+ >
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"
+ fill="currentColor"
+ />
+ </svg>
+ <div>{t('import', 'Import')}</div>
+ </button>
+ );
+};
diff --git a/apps/frontend/src/components/third-parties/third-party.media.tsx b/apps/frontend/src/components/third-parties/third-party.media.tsx
index 59917fec8..252409259 100644
--- a/apps/frontend/src/components/third-parties/third-party.media.tsx
+++ b/apps/frontend/src/components/third-parties/third-party.media.tsx
@@ -102,7 +102,7 @@ export const ThirdPartyPopup: FC<{
setThirdParty(p);
}}
key={p.identifier}
- className="w-full h-full p-[20px] min-h-[100px] text-[14px] bg-third hover:bg-input transition-all text-textColor relative flex flex-col gap-[15px] cursor-pointer"
+ className="w-full h-full p-[20px] min-h-[100px] text-[14px] bg-newTableHeader hover:bg-newTableBorder rounded-[8px] transition-all text-textColor relative flex flex-col gap-[15px] cursor-pointer"
>
<div>
<img
diff --git a/libraries/nestjs-libraries/src/3rdparties/reelfarm/reelfarm.provider.ts b/libraries/nestjs-libraries/src/3rdparties/reelfarm/reelfarm.provider.ts
new file mode 100644
index 000000000..4a172e0be
--- /dev/null
+++ b/libraries/nestjs-libraries/src/3rdparties/reelfarm/reelfarm.provider.ts
@@ -0,0 +1,112 @@
+import {
+ ThirdParty,
+ ThirdPartyAbstract,
+} from '@gitroom/nestjs-libraries/3rdparties/thirdparty.interface';
+
+const BASE_URL = 'https://reel.farm/api/v1';
+
+@ThirdParty({
+ identifier: 'reelfarm',
+ title: 'Reel.Farm',
+ description:
+ 'Import UGC and greenscreen videos from your Reel.Farm account.',
+ position: 'media-library',
+ fields: [],
+})
+export class ReelFarmProvider extends ThirdPartyAbstract {
+ async checkConnection(
+ apiKey: string
+ ): Promise<false | { name: string; username: string; id: string }> {
+ const res = await fetch(`${BASE_URL}/videos?limit=1`, {
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ },
+ });
+
+ if (!res.ok) {
+ return false;
+ }
+
+ return {
+ name: 'Reel.Farm',
+ username: 'reelfarm',
+ id: apiKey.slice(-8),
+ };
+ }
+
+ async listMedia(
+ apiKey: string,
+ data?: { page?: number }
+ ): Promise<{
+ results: {
+ id: string;
+ url: string;
+ thumbnail?: string;
+ name: string;
+ type: 'video' | 'image';
+ }[];
+ pages: number;
+ }> {
+ const page = data?.page || 1;
+ const limit = 20;
+ const offset = (page - 1) * limit;
+
+ const allVideos = [];
+
+ for (const videoType of ['ugc', 'greenscreen']) {
+ const res = await fetch(
+ `${BASE_URL}/videos?video_type=${videoType}&status=completed&limit=${limit}&offset=${offset}`,
+ {
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ },
+ }
+ );
+
+ if (res.ok) {
+ const body = await res.json();
+ const videos = body.videos || body.data || [];
+ console.log(body);
+ allVideos.push(
+ ...videos.map((v: any) => ({
+ ...v,
+ _video_type: videoType,
+ }))
+ );
+ }
+ }
+
+ const total = allVideos.length;
+
+ console.log(allVideos);
+
+ return {
+ results: allVideos.slice(0, limit).map((v: any) => ({
+ id: String(v.id || v.video_id),
+ url: v.video_url || v.url || v.download_url || '',
+ thumbnail: v.thumbnail_url || v.thumbnail || v.preview_url || '',
+ name: `${v._video_type}`,
+ type: 'video' as const,
+ })),
+ pages: Math.max(1, Math.ceil(total / limit)),
+ };
+ }
+
+ async importMedia(
+ apiKey: string,
+ items: { url: string; name: string }[]
+ ): Promise<{ url: string; name: string }[]> {
+ return items
+ .filter((item) => item.url)
+ .map((item) => ({
+ url: item.url.split('#')[0].split('?')[0],
+ name: item.name || 'reelfarm-video',
+ }));
+ }
+
+ async sendData(): Promise<string> {
+ throw new Error(
+ 'ReelFarm media-library provider does not support sendData'
+ );
+ }
+}
diff --git a/libraries/nestjs-libraries/src/3rdparties/thirdparty.interface.ts b/libraries/nestjs-libraries/src/3rdparties/thirdparty.interface.ts
index 0f5d4780a..f94c03623 100644
--- a/libraries/nestjs-libraries/src/3rdparties/thirdparty.interface.ts
+++ b/libraries/nestjs-libraries/src/3rdparties/thirdparty.interface.ts
@@ -12,7 +12,7 @@ export interface ThirdPartyParams {
identifier: string;
title: string;
description: string;
- position: 'media' | 'webhook';
+ position: 'media' | 'media-library' | 'webhook';
fields: {
name: string;
description: string;
diff --git a/libraries/nestjs-libraries/src/3rdparties/thirdparty.module.ts b/libraries/nestjs-libraries/src/3rdparties/thirdparty.module.ts
index 0f435a966..d46a49bbf 100644
--- a/libraries/nestjs-libraries/src/3rdparties/thirdparty.module.ts
+++ b/libraries/nestjs-libraries/src/3rdparties/thirdparty.module.ts
@@ -1,10 +1,11 @@
import { Global, Module } from '@nestjs/common';
import { HeygenProvider } from '@gitroom/nestjs-libraries/3rdparties/heygen/heygen.provider';
+import { ReelFarmProvider } from '@gitroom/nestjs-libraries/3rdparties/reelfarm/reelfarm.provider';
import { ThirdPartyManager } from '@gitroom/nestjs-libraries/3rdparties/thirdparty.manager';
@Global()
@Module({
- providers: [HeygenProvider, ThirdPartyManager],
+ providers: [HeygenProvider, ReelFarmProvider, ThirdPartyManager],
get exports() {
return this.providers;
},
diff --git a/libraries/nestjs-libraries/src/dtos/third-party/import-media.dto.ts b/libraries/nestjs-libraries/src/dtos/third-party/import-media.dto.ts
new file mode 100644
index 000000000..501f696ff
--- /dev/null
+++ b/libraries/nestjs-libraries/src/dtos/third-party/import-media.dto.ts
@@ -0,0 +1,30 @@
+import { Type } from 'class-transformer';
+import {
+ ArrayMinSize,
+ IsDefined,
+ IsString,
+ ValidateNested,
+} from 'class-validator';
+import { IsSafeWebhookUrl } from '@gitroom/nestjs-libraries/dtos/webhooks/webhook.url.validator';
+
+export class ImportMediaItemDto {
+ @IsString()
+ @IsDefined()
+ @IsSafeWebhookUrl({
+ message:
+ 'URL must be a public HTTPS URL and cannot point to internal network addresses',
+ })
+ url: string;
+
+ @IsString()
+ @IsDefined()
+ name: string;
+}
+
+export class ImportMediaDto {
+ @ValidateNested({ each: true })
+ @Type(() => ImportMediaItemDto)
+ @ArrayMinSize(1)
+ @IsDefined()
+ items: ImportMediaItemDto[];
+}
diff --git a/libraries/nestjs-libraries/src/upload/cloudflare.storage.ts b/libraries/nestjs-libraries/src/upload/cloudflare.storage.ts
index 93050f09f..42f38004e 100644
--- a/libraries/nestjs-libraries/src/upload/cloudflare.storage.ts
+++ b/libraries/nestjs-libraries/src/upload/cloudflare.storage.ts
@@ -62,7 +62,9 @@ class CloudflareStorage implements IUploadProvider {
const contentType =
loadImage?.headers?.get('content-type') ||
loadImage?.headers?.get('Content-Type');
- const extension = getExtension(contentType)!;
+ const extension = getExtension(contentType) ||
+ path.split('?')[0].split('#')[0].split('.').pop() ||
+ 'bin';
const id = makeId(10);
const params = {
diff --git a/libraries/nestjs-libraries/src/upload/local.storage.ts b/libraries/nestjs-libraries/src/upload/local.storage.ts
index 3f6726257..a03c1bd96 100644
--- a/libraries/nestjs-libraries/src/upload/local.storage.ts
+++ b/libraries/nestjs-libraries/src/upload/local.storage.ts
@@ -11,7 +11,9 @@ export class LocalStorage implements IUploadProvider {
const contentType =
loadImage?.headers?.get('content-type') ||
loadImage?.headers?.get('Content-Type');
- const findExtension = mime.getExtension(contentType)!;
+ const findExtension = mime.getExtension(contentType) ||
+ path.split('?')[0].split('#')[0].split('.').pop() ||
+ 'bin';
const now = new Date();
const year = now.getFullYear();