support for subs on local files
This commit is contained in:
@@ -399,7 +399,6 @@ export async function downloadBook(request: FastifyRequest<{ Body: DownloadBookB
|
||||
}
|
||||
}
|
||||
|
||||
// NUEVO: Estado de descargas
|
||||
export async function getDownloadStatus(request: FastifyRequest, reply: FastifyReply) {
|
||||
try {
|
||||
const downloads = downloadService.getActiveDownloads();
|
||||
@@ -426,7 +425,6 @@ export async function getDownloadStatus(request: FastifyRequest, reply: FastifyR
|
||||
}
|
||||
}
|
||||
|
||||
// NUEVO: Streaming HLS para anime local
|
||||
export async function getAnimeStreamManifest(request: FastifyRequest, reply: FastifyReply) {
|
||||
try {
|
||||
const { type, id, unit } = request.params as any;
|
||||
@@ -454,7 +452,6 @@ export async function getAnimeStreamManifest(request: FastifyRequest, reply: Fas
|
||||
}
|
||||
}
|
||||
|
||||
// NUEVO: Servir archivos HLS
|
||||
export async function serveHLSFile(request: FastifyRequest, reply: FastifyReply) {
|
||||
try {
|
||||
const { hash, filename } = request.params as any;
|
||||
@@ -481,32 +478,4 @@ export async function serveHLSFile(request: FastifyRequest, reply: FastifyReply)
|
||||
console.error('Error serving HLS file:', err);
|
||||
return reply.status(500).send({ error: 'FAILED_TO_SERVE_HLS_FILE' });
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSubtitle(request: FastifyRequest, reply: FastifyReply) {
|
||||
try {
|
||||
const { id, unit, track } = request.params as any;
|
||||
|
||||
// Validar que el track sea un número
|
||||
const trackIndex = parseInt(track, 10);
|
||||
if (isNaN(trackIndex)) {
|
||||
return reply.status(400).send({ error: 'INVALID_TRACK_INDEX' });
|
||||
}
|
||||
|
||||
const subtitleStream = await service.extractSubtitleTrack(id, unit, trackIndex);
|
||||
|
||||
if (!subtitleStream) {
|
||||
return reply.status(404).send({ error: 'FILE_NOT_FOUND' });
|
||||
}
|
||||
|
||||
// Cabecera esencial para que el navegador entienda que son subtítulos
|
||||
reply.header('Content-Type', 'text/vtt');
|
||||
reply.header('Cache-Control', 'public, max-age=86400'); // Cachear por 1 día si quieres
|
||||
|
||||
return subtitleStream;
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error serving subtitles:', err);
|
||||
return reply.status(500).send({ error: 'FAILED_TO_SERVE_SUBTITLES' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user