Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apps/web] Add video file preview #19

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/web/components/LocalVideo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useMemo } from "react";

interface LocalVideoProps extends React.ComponentPropsWithoutRef<"video"> {
path: string;
}

export default function LocalVideo({ path, ...props }: LocalVideoProps) {
const src = useMemo(() => `/api/files?path=${encodeURIComponent(path)}`, [path]);

return <video src={src} {...props} />;
}
7 changes: 2 additions & 5 deletions apps/web/src/app/_components/FilePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useLookupFile from "../../../hooks/useLookupFile";
import { LocalImage } from "../../../components/LocalImage";
import LocalVideo from "../../../components/LocalVideo";

interface FilePreviewProps {
path: string;
Expand Down Expand Up @@ -45,11 +46,7 @@ export function FilePreview({ path }: FilePreviewProps) {
}

if (data.startsWith("video")) {
return (
<div className="text-yellow-500 bg-yellow-100 rounded-xl border border-yellow-300 border-dashed p-2 w-full">
{data}
</div>
);
return <LocalVideo path={path} controls className="rounded-xl max-h-48" />;
}

return (
Expand Down
Binary file added demo/loop.mp4
Binary file not shown.
Binary file added demo/sub/loop.mp4
Binary file not shown.