The download endpoint served files under their internal uuid-based storage name; it now builds the Content-Disposition filename from the probed video title (persisted on submit) with the original extension, falling back to the old behavior when no title is available. The status page also gets an always-visible link back to the homepage. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
30 lines
927 B
TypeScript
30 lines
927 B
TypeScript
import { prisma } from './prisma'
|
|
import { config } from '../../config/app.config'
|
|
|
|
export async function createToken(downloadId: string): Promise<string> {
|
|
const expiresAt = new Date(
|
|
Date.now() + config.DOWNLOAD_LINK_TTL_HOURS * 60 * 60 * 1000
|
|
)
|
|
const record = await prisma.downloadToken.create({
|
|
data: { downloadId, expiresAt },
|
|
})
|
|
return record.token
|
|
}
|
|
|
|
export async function validateToken(
|
|
token: string
|
|
): Promise<{ downloadId: string; filePath: string; title: string | null } | null> {
|
|
const record = await prisma.downloadToken.findUnique({
|
|
where: { token },
|
|
include: { download: { select: { id: true, filePath: true, title: true } } },
|
|
})
|
|
if (!record) return null
|
|
if (record.expiresAt < new Date()) return null
|
|
if (!record.download.filePath) return null
|
|
return {
|
|
downloadId: record.download.id,
|
|
filePath: record.download.filePath,
|
|
title: record.download.title,
|
|
}
|
|
}
|