feat: pdf viewer toegevoegd

This commit is contained in:
kodi
2026-03-12 15:08:30 +01:00
parent ed34d6202f
commit fc22550e91
12 changed files with 382 additions and 1 deletions
@@ -35,6 +35,9 @@ VIDEO_CONTENT_TYPES = {
".mp4": "video/mp4",
".mkv": "video/x-matroska",
}
PDF_CONTENT_TYPES = {
".pdf": "application/pdf",
}
class FileOpsService:
@@ -409,6 +412,39 @@ class FileOpsService:
"content": self._filesystem.stream_file(resolved_target.absolute),
}
def prepare_pdf_stream(self, path: str) -> dict:
resolved_target = self._path_guard.resolve_existing_path(path)
if resolved_target.absolute.is_dir():
raise AppError(
code="type_conflict",
message="Source must be a file",
status_code=409,
details={"path": resolved_target.relative},
)
if not resolved_target.absolute.is_file():
raise AppError(
code="type_conflict",
message="Unsupported path type for pdf",
status_code=409,
details={"path": resolved_target.relative},
)
content_type = self._pdf_content_type_for(resolved_target.absolute)
if content_type is None:
raise AppError(
code="unsupported_type",
message="File type is not supported for pdf viewing",
status_code=409,
details={"path": resolved_target.relative},
)
return {
"headers": {"Content-Length": str(int(resolved_target.absolute.stat().st_size))},
"content_type": content_type,
"content": self._filesystem.stream_file(resolved_target.absolute),
}
@staticmethod
def _join_relative(base: str, name: str) -> str:
return f"{base}/{name}" if base else name
@@ -428,6 +464,10 @@ class FileOpsService:
def _thumbnail_content_type_for(path: Path) -> str | None:
return THUMBNAIL_CONTENT_TYPES.get(path.suffix.lower())
@staticmethod
def _pdf_content_type_for(path: Path) -> str | None:
return PDF_CONTENT_TYPES.get(path.suffix.lower())
def _record_history(
self,
*,