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

[BDGR-117] Direct media download links in Server UI #227

Merged
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
32 changes: 32 additions & 0 deletions server/app/media/download/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { requirePermission } from "@/lib/auth";
import { db } from "@/lib/db";
import { getPresignedURL } from "@/lib/s3";
import { notFound } from "next/navigation";
import { NextRequest, NextResponse } from "next/server";

export async function GET(
req: NextRequest,
{ params }: { params: { id: string } },
) {
await requirePermission("Basic");
const media = await db.media.findUnique({
where: {
id: parseInt(params.id),
},
});
if (!media) {
notFound();
}
if (media.state !== "Ready" && media.state !== "ReadyWithWarnings") {
return new NextResponse("This media item is not ready yet.", {
status: 400,
});
}
if (!media.path) {
return new NextResponse("This media item has no path.", { status: 400 });
}
const url = await getPresignedURL(media.path, 3600);
return NextResponse.redirect(url, {
status: 303,
});
}
11 changes: 11 additions & 0 deletions server/components/MediaState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
PopoverTrigger,
} from "@badger/components/popover";
import { MediaSelectOrUploadDialog, PastShowsMedia } from "./MediaSelection";
import Link from "next/link";

export interface CompleteMedia extends Media {
tasks: MediaProcessingTask[];
Expand Down Expand Up @@ -180,6 +181,16 @@ function MediaProcessingState({
>
Replace
</Button>
{(media.state === MediaState.Ready ||
media.state === MediaState.ReadyWithWarnings) && (
<Link
href={`/media/download/${media.id}`}
target="_blank"
className="text-sm"
>
Download
</Link>
)}
</div>
</PopoverContent>
</Popover>
Expand Down
Loading