-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
638ddae
commit b49d7a7
Showing
6 changed files
with
127 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { revalidatePath } from 'next/cache'; | ||
import { type NextRequest } from "next/server"; | ||
import { getHeaders, CACHE_CONTROL_HEADERS } from "@/utils/helpers"; | ||
import { db } from "@cap/database"; | ||
import { videos } from "@cap/database/schema"; | ||
import { eq } from "drizzle-orm"; | ||
|
||
export async function POST(request: NextRequest) { | ||
const origin = request.headers.get("origin") as string; | ||
|
||
try { | ||
const { videoId } = await request.json(); | ||
|
||
if (!videoId) { | ||
return new Response( | ||
JSON.stringify({ error: "Missing videoId" }), | ||
{ | ||
status: 400, | ||
headers: { | ||
...getHeaders(origin), | ||
...CACHE_CONTROL_HEADERS, | ||
}, | ||
} | ||
); | ||
} | ||
|
||
const [video] = await db.select().from(videos).where(eq(videos.id, videoId)); | ||
|
||
if (!video) { | ||
return new Response( | ||
JSON.stringify({ error: "Video not found" }), | ||
{ | ||
status: 404, | ||
headers: { | ||
...getHeaders(origin), | ||
...CACHE_CONTROL_HEADERS, | ||
}, | ||
} | ||
); | ||
} | ||
|
||
// Revalidate the specific video page | ||
revalidatePath(`/s/${videoId}`); | ||
|
||
return new Response( | ||
JSON.stringify({ | ||
revalidated: true, | ||
now: Date.now(), | ||
path: `/s/${videoId}` | ||
}), | ||
{ | ||
headers: { | ||
...getHeaders(origin), | ||
...CACHE_CONTROL_HEADERS, | ||
}, | ||
} | ||
); | ||
} catch (err) { | ||
console.error("Revalidation error:", err); | ||
return new Response( | ||
JSON.stringify({ | ||
error: "Error revalidating", | ||
details: err instanceof Error ? err.message : String(err) | ||
}), | ||
{ | ||
status: 500, | ||
headers: { | ||
...getHeaders(origin), | ||
...CACHE_CONTROL_HEADERS, | ||
}, | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b49d7a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
cap-web – ./
cap-web-git-main-mc-ilroy.vercel.app
www.cap.so
cap-web-mc-ilroy.vercel.app
cap.so
cap-web-nu.vercel.app