-
Notifications
You must be signed in to change notification settings - Fork 2
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
efc0d1f
commit 81f65c2
Showing
26 changed files
with
1,466 additions
and
115 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
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,36 @@ | ||
import type { NextRequest } from 'next/server'; | ||
import { NextResponse } from "next/server"; | ||
|
||
const ERROR_MESSAGES = { | ||
UNAUTHORIZED: "Authentication required", | ||
INVALID_RESPONSE: "Invalid stream status response from Gateway", | ||
INTERNAL_ERROR: "An unexpected error occurred", | ||
} as const; | ||
|
||
export async function GET(request: NextRequest, | ||
{ params }: { params: Promise<{ id: string }> } | ||
) { | ||
const streamId = (await params).id; | ||
const userId = request.headers.get("x-user-id"); | ||
if (!userId) { | ||
return createErrorResponse(401, ERROR_MESSAGES.UNAUTHORIZED); | ||
} | ||
|
||
try { | ||
const response = await fetch(`${process.env.NEXT_PUBLIC_STREAM_STATUS_ENDPOINT_URL}/${streamId}`); | ||
if (!response.ok) { | ||
return createErrorResponse(200, ERROR_MESSAGES.INVALID_RESPONSE + ` - [${response.status}] ${response.statusText}`); | ||
} | ||
const data = await response.json(); | ||
return NextResponse.json({ success: true, error: null, data: data }, { status: 200 }); | ||
} catch (error) { | ||
return createErrorResponse(500, ERROR_MESSAGES.INTERNAL_ERROR + " - " + error); | ||
} | ||
} | ||
|
||
function createErrorResponse(status: number, message: unknown) { | ||
return NextResponse.json({ success: false, error: message }, { status }); | ||
} | ||
|
||
|
||
|
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,33 @@ | ||
"use server"; | ||
|
||
import { createServerClient } from "@repo/supabase"; | ||
import { Livepeer } from "livepeer"; | ||
|
||
export async function deleteStream(streamId: string) { | ||
const supabase = await createServerClient(); | ||
const { data, error } = await supabase | ||
.from("streams") | ||
.delete() | ||
.eq('id', streamId); | ||
if(!error){ | ||
deleteLivepeerStream(streamId); | ||
} | ||
return { data, error: error?.message }; | ||
} | ||
|
||
export const deleteLivepeerStream = async (name: string) => { | ||
try{ | ||
|
||
const livepeer = new Livepeer({ | ||
serverURL: "https://livepeer.monster/api", | ||
apiKey: process.env.NEXT_PUBLIC_LIVEPEER_STUDIO_API_KEY, | ||
}); | ||
|
||
const { error } = await livepeer.stream.delete(name); | ||
|
||
return { error }; | ||
}catch(e: any){ | ||
console.error("Error deleting livepeer stream:", e); | ||
return {stream: null, error: e.message}; | ||
} | ||
}; |
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,13 @@ | ||
"use server"; | ||
|
||
import { createServerClient } from "@repo/supabase"; | ||
|
||
export async function getAllStreams(userId: string) { | ||
const supabase = await createServerClient(); | ||
|
||
const { data, error } = await supabase.from("streams").select("*").eq("user_id", userId); | ||
|
||
if (error) throw new Error(error.message); | ||
|
||
return data; | ||
} |
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,77 @@ | ||
"use server"; | ||
|
||
import { createServerClient } from "@repo/supabase"; | ||
|
||
export async function getStream(streamId: string) { | ||
const supabase = await createServerClient(); | ||
const { data, error } = await supabase | ||
.from("streams") | ||
.select(` | ||
id, | ||
name, | ||
stream_key, | ||
output_stream_url, | ||
pipeline_params, | ||
created_at, | ||
pipeline_id, | ||
output_playback_id, | ||
author, | ||
pipelines!inner ( | ||
id, | ||
name, | ||
config | ||
) | ||
`) | ||
.eq('id', streamId) | ||
.single(); | ||
return { data, error: error?.message }; | ||
} | ||
|
||
|
||
export async function getStreams(userId: string, page: number = 1, limit: number = 10) { | ||
const supabase = await createServerClient(); | ||
const offset = (page - 1) * limit; | ||
|
||
const { data, error } = await supabase | ||
.from("streams") | ||
.select(` | ||
id, | ||
name, | ||
stream_key, | ||
output_stream_url, | ||
pipeline_params, | ||
created_at, | ||
pipeline_id, | ||
output_playback_id, | ||
pipelines!inner ( | ||
id, | ||
name | ||
) | ||
`) | ||
.eq('author', userId) | ||
.order('created_at', { ascending: false }) | ||
.range(offset, offset + limit - 1); | ||
|
||
if (error) { | ||
console.error("Error fetching Streams:", error); | ||
throw new Error("Could not fetch Streams"); | ||
} | ||
|
||
const totalCountQuery = await supabase | ||
.from("streams") | ||
.select('*', { count: 'exact', head: true }) | ||
.eq('author', userId); | ||
|
||
if (totalCountQuery.error) { | ||
console.error("Error fetching total count:", totalCountQuery.error); | ||
throw new Error("Could not fetch total count"); | ||
} | ||
|
||
const total = totalCountQuery.count || 0; | ||
const totalPages = Math.ceil(total / limit); | ||
|
||
return { | ||
data, | ||
totalPages, | ||
}; | ||
} |
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
Oops, something went wrong.