mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-05 00:32:03 +00:00
Signed authenticated video urls work through digital ocean, just a simple example down for now
This commit is contained in:
parent
462011688f
commit
808a22dc09
1671
package-lock.json
generated
1671
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,8 @@
|
||||
"postinstall": "npx prisma generate"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.645.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.645.0",
|
||||
"@getalby/bitcoin-connect-react": "^3.5.3",
|
||||
"@getalby/lightning-tools": "^5.0.3",
|
||||
"@getalby/sdk": "^3.6.1",
|
||||
|
@ -61,8 +61,7 @@ const authorize = async (pubkey) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
export default NextAuth({
|
||||
export const authOptions = {
|
||||
adapter: PrismaAdapter(prisma),
|
||||
providers: [
|
||||
CredentialsProvider({
|
||||
@ -145,4 +144,6 @@ export default NextAuth({
|
||||
pages: {
|
||||
signIn: "/auth/signin",
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export default NextAuth(authOptions);
|
||||
|
45
src/pages/api/get-video-url.js
Normal file
45
src/pages/api/get-video-url.js
Normal file
@ -0,0 +1,45 @@
|
||||
import { getServerSession } from "next-auth/next"
|
||||
import { authOptions } from "./auth/[...nextauth]"
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
|
||||
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"
|
||||
|
||||
const s3Client = new S3Client({
|
||||
endpoint: "https://nyc3.digitaloceanspaces.com", // DigitalOcean Spaces endpoint
|
||||
region: "nyc3",
|
||||
credentials: {
|
||||
accessKeyId: process.env.DO_SPACES_KEY,
|
||||
secretAccessKey: process.env.DO_SPACES_SECRET,
|
||||
},
|
||||
})
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const session = await getServerSession(req, res, authOptions)
|
||||
|
||||
if (!session) {
|
||||
return res.status(401).json({ error: "Unauthorized" })
|
||||
}
|
||||
|
||||
console.log("Session:", session)
|
||||
|
||||
const { videoKey } = req.query
|
||||
|
||||
if (!videoKey) {
|
||||
return res.status(400).json({ error: "Video key is required" })
|
||||
}
|
||||
|
||||
try {
|
||||
const command = new GetObjectCommand({
|
||||
Bucket: "plebdevs-bucket",
|
||||
Key: videoKey,
|
||||
})
|
||||
|
||||
const signedUrl = await getSignedUrl(s3Client, command, {
|
||||
expiresIn: 10, // URL expires in 10 seconds
|
||||
})
|
||||
|
||||
res.status(200).json({ url: signedUrl })
|
||||
} catch (error) {
|
||||
console.error("Error generating signed URL:", error)
|
||||
res.status(500).json({ error: "Failed to generate video URL" })
|
||||
}
|
||||
}
|
25
src/pages/testr.js
Normal file
25
src/pages/testr.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
|
||||
async function getVideoUrl(videoKey = "testr.mp4") {
|
||||
const response = await fetch(`/api/get-video-url?videoKey=${encodeURIComponent(videoKey)}`)
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get video URL')
|
||||
}
|
||||
const data = await response.json()
|
||||
return data.url
|
||||
}
|
||||
|
||||
const VideoPlayer = ({ videoKey }) => {
|
||||
const [videoUrl, setVideoUrl] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
getVideoUrl(videoKey).then(setVideoUrl)
|
||||
}, [videoKey])
|
||||
|
||||
if (!videoUrl) return <div>Loading...</div>
|
||||
|
||||
return <video src={videoUrl} controls />
|
||||
}
|
||||
|
||||
export default VideoPlayer;
|
Loading…
x
Reference in New Issue
Block a user