Skip to content

Commit

Permalink
Reverted regex logic for video URL
Browse files Browse the repository at this point in the history
  • Loading branch information
SujithThirumalaisamy committed Sep 11, 2024
1 parent c20657a commit 6912502
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions next-app/app/api/streams/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export async function POST(req: NextRequest) {
}

const isYt = data.url.match(YT_REGEX);
if (!isYt) {
const videoId = data.url ? data.url.match(YT_REGEX)?.[1] : null;
if (!isYt || !videoId) {
return NextResponse.json(
{
message: "Invalid YouTube URL format",
Expand All @@ -55,7 +56,6 @@ export async function POST(req: NextRequest) {
);
}

const videoId = data.url ? data.url.match(YT_REGEX)?.[1] : null;
const res = await youtubesearchapi.GetVideoDetails(videoId);

// Check if the user is not the creator
Expand Down Expand Up @@ -158,7 +158,7 @@ export async function POST(req: NextRequest) {
userId: data.creatorId,
addedBy: user.id,
url: data.url,
extractedId:videoId,
extractedId: videoId,
type: "Youtube",
title: res.title ?? "Can't find video",
smallImg:
Expand Down
2 changes: 1 addition & 1 deletion next-app/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export const YT_REGEX =
/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+?&v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
/^(?:https?:\/\/)?(?:www\.)?(?:m\.)?(?:youtube\.com\/(?:watch\?(?!.*\blist=)(?:.*&)?v=|embed\/|v\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})(?:[?&]\S+)?$/;

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
Expand Down

0 comments on commit 6912502

Please sign in to comment.