Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: implement media drop functionality and update GitHub API integration

CristianOlivera151f8f6314569
diff --git a/.env.example b/.env.example
index df21db0..305c82b 100644
--- a/.env.example
+++ b/.env.example
@@ -5,8 +5,4 @@ PIXABAY_API_KEY=x.y.z
NEXT_PUBLIC_SUPABASE_URL=x.y.z
NEXT_PUBLIC_SUPABASE_ANON_KEY=x.y.z
NEXT_PUBLIC_SITE_URL=https://openvid.dev
-NEXT_PUBLIC_GITHUB_TOKEN=x.y.z
-
-# Supabase Configuration
-NEXT_PUBLIC_SUPABASE_URL=x.y.z
-NEXT_PUBLIC_SUPABASE_ANON_KEY=x.y.z
\ No newline at end of file
+GITHUB_TOKEN=x.y.z
\ No newline at end of file
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index 33c4626..2cf9789 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -605,6 +605,7 @@ export default function Editor() {
await handleImageUploadToCanvas(imageFile);
}
}, [isPhotoMode, handleImageUploadToCanvas]);
+
const selectCanvasElement = useCallback((id: string | null) => {
setSelectedElementId(id);
setSelectedZoomFragmentId(null);
@@ -1472,10 +1473,10 @@ export default function Editor() {
}
}, []);
- const handleVideoUpload = useCallback(async (file: File) => {
- const hasExistingClips = videoClipsRef.current.length > 0;
+ const handleVideoUpload = useCallback(async (file: File, options?: { forceReplace?: boolean }) => {
+ const forceReplace = options?.forceReplace ?? false;
+ const hasExistingClips = videoClipsRef.current.length > 0 && !forceReplace;
- // Add video to library first
let libraryVideo: Awaited<ReturnType<typeof addVideoToLibrary>> | null = null;
try {
libraryVideo = await addVideoToLibrary(file);
@@ -1492,8 +1493,7 @@ export default function Editor() {
return;
}
- // First video - add to track
- clearClipUrls(); videoBlobsRef.current.clear();
+ clearClipUrls();
videoBlobsRef.current.clear();
videoUrlsRef.current.clear();
activeClipIdRef.current = null;
@@ -1505,24 +1505,20 @@ export default function Editor() {
if (!originalHasAudio) setMuteOriginalAudio(true);
clipAudioStateRef.current.set(libraryVideo.id, libraryVideo.hasAudio !== false);
}
-
try {
await clearAllThumbnailCache();
} catch (error) {
console.warn("Failed to clear thumbnails:", error);
}
-
const uploadedData = await uploadVideo(file);
if (uploadedData && libraryVideo) {
lastLoadedVideoIdRef.current = uploadedData.videoId;
-
setVideoUrl(uploadedData.url);
setVideoId(uploadedData.videoId);
setVideoDuration(uploadedData.duration);
setTrimRange({ start: 0, end: uploadedData.duration });
setAspectRatio(uploadedData.aspectRatio);
setVideoDimensions({ width: uploadedData.width, height: uploadedData.height });
-
const newClip: VideoTrackClip = {
id: crypto.randomUUID(),
libraryVideoId: libraryVideo.id,
@@ -1540,16 +1536,23 @@ export default function Editor() {
activeClipDataRef.current = newClip;
setVideoClips([newClip]);
setSelectedVideoClipId(newClip.id);
-
const defaultFragments = generateDefaultZoomFragments(uploadedData.duration);
setZoomFragments(defaultFragments);
-
setCurrentTime(0);
setIsPlaying(false);
setTimeout(() => clearHistory(), 200);
}
}, [uploadVideo, clearHistory, showNewVideosBadge, clearClipUrls]);
+ const handleVideoDrop = useCallback(async (files: FileList | File[]) => {
+ if (isPhotoMode) return;
+ const fileArray = Array.from(files);
+ const videoFile = fileArray.find(f => f.type.startsWith('video/'));
+ if (videoFile) {
+ await handleVideoUpload(videoFile, { forceReplace: true });
+ }
+ }, [isPhotoMode, handleVideoUpload]);
+
const handleVideoUploadToLibrary = useCallback(async (file: File) => {
try {
await addVideoToLibrary(file);
@@ -2716,6 +2719,35 @@ export default function Editor() {
[zoomFragments, selectedZoomFragmentId]
);
+ const [copiedZoomFragment, setCopiedZoomFragment] = useState<Omit<ZoomFragment, 'id' | 'startTime' | 'endTime'> | null>(null);
+
+ const copySelectedZoomFragment = useCallback(() => {
+ if (!selectedZoomFragment) return;
+ const { id, startTime, endTime, ...config } = selectedZoomFragment;
+ setCopiedZoomFragment(config);
+ }, [selectedZoomFragment]);
+
+ const pasteZoomFragment = useCallback(() => {
+ if (!copiedZoomFragment) return;
+ const original = selectedZoomFragmentId
+ ? zoomFragmentsRef.current.find(f => f.id === selectedZoomFragmentId)
+ : null;
+ const duration = original ? original.endTime - original.startTime : DEFAULT_ZOOM_FRAGMENT_DURATION;
+ const hintTime = original ? original.endTime : currentTime;
+ const position = findValidFragmentPosition(hintTime, duration, zoomFragmentsRef.current, videoDuration);
+ if (!position) return;
+
+ const newFragment: ZoomFragment = {
+ ...copiedZoomFragment,
+ id: `zoom_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`,
+ startTime: position.startTime,
+ endTime: position.endTime,
+ };
+ setZoomFragments(prev => [...prev, newFragment].sort((a, b) => a.startTime - b.startTime));
+ setSelectedZoomFragmentId(newFragment.id);
+ setActiveTool("zoom");
+ }, [copiedZoomFragment, selectedZoomFragmentId, currentTime, videoDuration]);
+
// Calcular el CSS del background actual - memoized
const backgroundColorCss = useMemo((): string | undefined => {
if (backgroundTab === "color" && backgroundColorConfig) {
@@ -2769,13 +2801,25 @@ export default function Editor() {
return;
}
- if ((e.ctrlKey || e.metaKey) && e.key === 'c' && selectedElementId) {
- e.preventDefault();
- copySelectedElement();
- return;
+ if ((e.ctrlKey || e.metaKey) && e.key === 'c') {
+ if (selectedElementId) {
+ e.preventDefault();
+ copySelectedElement();
+ return;
+ }
+ if (selectedZoomFragmentId) {
+ e.preventDefault();
+ copySelectedZoomFragment();
+ return;
+ }
}
if ((e.ctrlKey || e.metaKey) && e.key === 'v') {
+ if (activeTool === 'zoom' && copiedZoomFragment) {
+ e.preventDefault();
+ pasteZoomFragment();
+ return;
+ }
if (isPhotoMode && !copiedElement) {
return;
}
@@ -2829,7 +2873,7 @@ export default function Editor() {
document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
- }, [selectedElementId, selectedZoomFragmentId, selectedAudioTrackId, selectedVideoClipId, deleteCanvasElement, handleDeleteZoomFragment, handleDeleteAudioTrack, handleDeleteVideoClip, copySelectedElement, pasteElement, isPhotoMode, copiedElement, textToolActive]);
+ }, [selectedElementId, selectedZoomFragmentId, selectedAudioTrackId, selectedVideoClipId, deleteCanvasElement, handleDeleteZoomFragment, handleDeleteAudioTrack, handleDeleteVideoClip, copySelectedElement, pasteElement, isPhotoMode, copiedElement, textToolActive, copySelectedZoomFragment, pasteZoomFragment, copiedZoomFragment, activeTool]);
const wasMobileRef = useRef<boolean | null>(null);
const otherSelectionActive = !!(selectedZoomFragmentId || selectedAudioTrackId || selectedVideoClipId);
@@ -3130,6 +3174,7 @@ export default function Editor() {
onVideoUpload={handleVideoUpload}
onImageUpload={handleImageUploadToCanvas}
onImageDrop={handleImageDrop}
+ onVideoDrop={handleVideoDrop}
isUploading={isUploading}
videoTransform={videoTransform}
onVideoTransformChange={setVideoTransform}
diff --git a/app/api/github/route.ts b/app/api/github/route.ts
new file mode 100644
index 0000000..fdac993
--- /dev/null
+++ b/app/api/github/route.ts
@@ -0,0 +1,24 @@
+import { NextResponse } from "next/server";
+
+export async function GET() {
+ try {
+ const res = await fetch("https://api.github.com/repos/CristianOlivera1/openvid", {
+ headers: {
+ "Authorization": `Bearer ${process.env.GITHUB_TOKEN}`,
+ "Accept": "application/vnd.github+json"
+ },
+ next: { revalidate: 3600 }
+ });
+
+ if (!res.ok) {
+ throw new Error("Error fetching GitHub API");
+ }
+
+ const data = await res.json();
+ return NextResponse.json({ stars: data.stargazers_count });
+
+ } catch (error) {
+ console.error("[GitHub API Route] Error:", error);
+ return NextResponse.json({ stars: null }, { status: 500 });
+ }
+}
\ No newline at end of file
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index 1ae2fd1..edc6a68 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -20,7 +20,6 @@ import { applyPerspective3D, disposePerspective3D } from "@/lib/perspective3d";
import { RotationHandleIcon } from "@/components/ui/RotationHandleIcon";
import { CanvasElementsLayer, ElementResizeStart } from "./CanvasElementsLayer";
import { EditorHoverTooltip } from "./EditorHoverTooltip";
-import DropImage from "@/components/ui/DropImage";
import { LayersPanel } from "./LayersPanel";
import { useMockup3dContext } from "@/app/contexts/Mockup3dContext";
import { PHONE_H, PHONE_W, DEVICE_3D_DIMENSIONS, DEVICE_VIEWER_DEFAULTS, PHONE_DEVICE_URLS, type ImageMaskConfigLike } from "@/lib/phone3d.utils";
@@ -32,6 +31,7 @@ import { applyGradientMaskToRegion, GetMediaMaskStyles } from "@/lib/media-mask.
import { MediaContent } from "@/components/ui/MediaContent";
import { RotationGuideLine } from "@/components/ui/RotationGuideLine";
import { drawCameraOverlayToCtx } from "@/lib/camera-overlay.utils";
+import DropMedia from "@/components/ui/DropMedia";
export type { VideoCanvasHandle, VideoCanvasProps };
@@ -100,6 +100,7 @@ function VideoCanvasInner({
onVideoUpload,
onImageUpload,
onImageDrop,
+ onVideoDrop,
isUploading = false,
videoTransform = { rotation: 0, translateX: 0, translateY: 0 },
onVideoTransformChange,
@@ -1208,33 +1209,32 @@ function VideoCanvasInner({
// Drag & drop handlers for images
const handleDragOver = (e: React.DragEvent) => {
- if (mediaType !== "image" || !onImageDrop) return;
+ const dropHandler = mediaType === "video" ? onVideoDrop : onImageDrop;
+ if (!dropHandler) return;
if (!e.dataTransfer.types.includes("Files")) return;
-
e.preventDefault();
e.stopPropagation();
setIsDraggingOver(true);
};
const handleDragLeave = (e: React.DragEvent) => {
- if (mediaType !== "image") return;
-
+ const dropHandler = mediaType === "video" ? onVideoDrop : onImageDrop;
+ if (!dropHandler) return;
e.preventDefault();
e.stopPropagation();
setIsDraggingOver(false);
};
const handleDrop = (e: React.DragEvent) => {
- if (mediaType !== "image" || !onImageDrop) return;
+ const dropHandler = mediaType === "video" ? onVideoDrop : onImageDrop;
+ if (!dropHandler) return;
if (!e.dataTransfer.types.includes("Files")) return;
-
e.preventDefault();
e.stopPropagation();
setIsDraggingOver(false);
-
const files = e.dataTransfer.files;
if (files && files.length > 0) {
- onImageDrop(files);
+ dropHandler(files);
}
};
@@ -2169,8 +2169,8 @@ function VideoCanvasInner({
setCanvasCtxMenu({ x: e.clientX, y: e.clientY, isVideo: isVideoTarget });
}}
>
- {mediaType === "image" && isDraggingOver && (
- <DropImage />
+ {isDraggingOver && (
+ <DropMedia mediaType={mediaType} />
)}
{canvasCtxMenu && (
@@ -2496,7 +2496,7 @@ function VideoCanvasInner({
transformStyle: mediaType === "image" && !apply3DToBackground ? 'preserve-3d' : undefined,
}}
>
- <EditorHoverTooltip show={isVideoHovered && !imagePhoneActive && mediaType === "image"} />
+ <EditorHoverTooltip show={isVideoHovered && !imagePhoneActive} />
</div>
</div>
</div>
@@ -2586,7 +2586,7 @@ function VideoCanvasInner({
pointerEvents: "none",
}}
>
- <EditorHoverTooltip show={isVideoHovered && mediaType === "image"} />
+ <EditorHoverTooltip show={isVideoHovered} />
</div>
</div>
diff --git a/components/ui/DropImage.tsx b/components/ui/DropImage.tsx
deleted file mode 100644
index 6acbda4..0000000
--- a/components/ui/DropImage.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-import { Icon } from "@iconify/react";
-import { useTranslations } from "next-intl";
-
-export default function DropImage() {
- const t = useTranslations("dropImage");
-
- return (
- <div className="absolute inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm pointer-events-none">
- <div className="flex flex-col items-center gap-4 text-white mask-[radial-gradient(circle,black_70%,transparent_99%)]">
- <Icon icon="hugeicons:image-upload" width="120" />
- <div className="text-3xl font-extrabold uppercase tracking-wider">
- {t("title")}
- </div>
- </div>
- </div>
- );
-}
diff --git a/components/ui/DropMedia.tsx b/components/ui/DropMedia.tsx
new file mode 100644
index 0000000..dbce0c5
--- /dev/null
+++ b/components/ui/DropMedia.tsx
@@ -0,0 +1,25 @@
+import { Icon } from "@iconify/react";
+import { useTranslations } from "next-intl";
+
+interface DropMediaProps {
+ mediaType: "image" | "video";
+}
+
+export default function DropMedia({ mediaType }: DropMediaProps) {
+ const t = useTranslations("dropMedia");
+ const isVideo = mediaType === "video";
+
+ return (
+ <div className="absolute inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm pointer-events-none">
+ <div className="flex flex-col items-center gap-4 text-white mask-[radial-gradient(circle,black_70%,transparent_99%)]">
+ <Icon
+ icon={isVideo ? "mage:video-upload" : "hugeicons:image-upload"}
+ width="120"
+ />
+ <div className="text-3xl font-extrabold uppercase tracking-wider">
+ {isVideo ? t("titleVideo") : t("titleImage")}
+ </div>
+ </div>
+ </div>
+ );
+}
\ No newline at end of file
diff --git a/components/ui/GitHubStars.tsx b/components/ui/GitHubStars.tsx
index 3a0eab5..bd8e858 100644
--- a/components/ui/GitHubStars.tsx
+++ b/components/ui/GitHubStars.tsx
@@ -7,17 +7,12 @@ export default function GitHubBadge() {
const [stars, setStars] = useState<number | null>(null);
useEffect(() => {
- fetch("https://api.github.com/repos/CristianOlivera1/openvid", {
- headers: {
- "Authorization": `Bearer ${process.env.NEXT_PUBLIC_GITHUB_TOKEN}`,
- "Accept": "application/vnd.github+json"
- }
- })
+ fetch("/api/github")
.then((res) => {
- if (!res.ok) throw new Error("GitHub Error");
+ if (!res.ok) throw new Error("Internal API Error");
return res.json();
})
- .then((data) => setStars(data?.stargazers_count ?? null))
+ .then((data) => setStars(data.stars))
.catch((err) => {
console.warn("[GitHubBadge] Failed to fetch stars:", err);
setStars(null);
@@ -29,7 +24,7 @@ export default function GitHubBadge() {
if (count >= 1000) {
return `${(count / 1000).toFixed(1)}K`;
}
- return count !== undefined ? count.toString() : "0";
+ return count.toString();
};
return (
@@ -56,4 +51,4 @@ export default function GitHubBadge() {
</div>
</a>
);
-}
+}
\ No newline at end of file
diff --git a/components/ui/Position3DPresetsEditor.tsx b/components/ui/Position3DPresetsEditor.tsx
index 451a006..28863cd 100644
--- a/components/ui/Position3DPresetsEditor.tsx
+++ b/components/ui/Position3DPresetsEditor.tsx
@@ -148,7 +148,6 @@ export function Position3DPresetsEditor({
</div>
)}
- {/* Tu nuevo diseño de badge para el texto del preset */}
<div className="absolute bottom-0 left-0 bg-black/60 border-t border-r border-white/10 px-1.5 py-0.5 text-[9px] font-semibold tracking-tight rounded-tr-md rounded-bl-lg z-30 max-w-[85%] truncate">
<span className={`transition-colors ${active ? "text-blue-400" : "text-white/80"}`}>
{preset.label}
diff --git a/messages/en.json b/messages/en.json
index 0a4a03e..7f70dff 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -1294,8 +1294,9 @@
}
}
},
- "dropImage": {
- "title": "Drop the image"
+ "dropMedia": {
+ "titleImage": "Drop the image",
+ "titleVideo": "Drop your video here"
},
"audioTrimModal": {
"title": "Trim audio",
diff --git a/messages/es.json b/messages/es.json
index 9c5f2df..1585087 100644
--- a/messages/es.json
+++ b/messages/es.json
@@ -1272,8 +1272,9 @@
}
}
},
- "dropImage": {
- "title": "Suelta la imagen"
+ "dropMedia": {
+ "titleImage": "Suelta la imagen",
+ "titleVideo": "Suelta tu video aquí"
},
"audioTrimModal": {
"title": "Recortar audio",
diff --git a/messages/ko.json b/messages/ko.json
index 5224b47..a784b44 100644
--- a/messages/ko.json
+++ b/messages/ko.json
@@ -1294,8 +1294,9 @@
}
}
},
- "dropImage": {
- "title": "이미지를 여기에 놓으세요"
+ "dropMedia": {
+ "titleImage": "이미지를 여기에 놓으세요",
+ "titleVideo": "여기에 비디오를 놓으세요"
},
"audioTrimModal": {
"title": "오디오 자르기",
diff --git a/messages/ru.json b/messages/ru.json
index d4cd4ec..bf72c52 100644
--- a/messages/ru.json
+++ b/messages/ru.json
@@ -1289,8 +1289,9 @@
}
}
},
- "dropImage": {
- "title": "Перетащите изображение"
+ "dropMedia": {
+ "titleImage": "Перетащите изображение",
+ "titleVideo": "Перетащите видео сюда"
},
"audioTrimModal": {
"title": "Обрезать аудио",
diff --git a/types/editor.types.ts b/types/editor.types.ts
index 243009d..b4b07bd 100644
--- a/types/editor.types.ts
+++ b/types/editor.types.ts
@@ -42,12 +42,12 @@ export interface EditorState {
export interface VideoCanvasHandle {
getExportCanvas: () => HTMLCanvasElement | null;
- drawFrame: (highQuality?: boolean, explicitTimelineTime?: number, frameOverride?: VideoFrame) => Promise<void>;
+ drawFrame: (highQuality?: boolean, explicitTimelineTime?: number, frameOverride?: VideoFrame) => Promise<void>;
getPreviewContainer: () => HTMLDivElement | null;
clearAllSelection: () => { multiIds: string[]; videoSelected: boolean };
restoreSelectionState: (state: { multiIds: string[]; videoSelected: boolean }) => void;
-
+
}
export interface VideoThumbnail {
@@ -104,6 +104,7 @@ export interface VideoCanvasProps {
onVideoUpload?: (file: File) => void;
onImageUpload?: (file: File) => void;
onImageDrop?: (files: FileList | File[]) => void;
+ onVideoDrop?: (files: FileList) => void;
isUploading?: boolean;
videoTransform?: VideoTransform;
onVideoTransformChange?: (transform: VideoTransform) => void;