image file info toegevoegd bij CMD+ENTER

This commit is contained in:
kodi
2026-03-13 11:37:27 +01:00
parent 05569576a7
commit 018c3dcd94
18 changed files with 726 additions and 0 deletions
@@ -32,6 +32,15 @@ THUMBNAIL_CONTENT_TYPES = {
".png": "image/png",
".webp": "image/webp",
}
IMAGE_CONTENT_TYPES = {
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".webp": "image/webp",
".gif": "image/gif",
".bmp": "image/bmp",
".avif": "image/avif",
}
VIDEO_CONTENT_TYPES = {
".mp4": "video/mp4",
".mkv": "video/x-matroska",
@@ -270,6 +279,8 @@ class FileOpsService:
content_type=metadata["content_type"],
owner=metadata["owner"],
group=metadata["group"],
width=metadata["width"],
height=metadata["height"],
)
def save(self, path: str, content: str, expected_modified: str) -> SaveResponse:
@@ -413,6 +424,39 @@ class FileOpsService:
"content": self._filesystem.stream_file(resolved_target.absolute),
}
def prepare_image_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 image",
status_code=409,
details={"path": resolved_target.relative},
)
content_type = self._image_content_type_for(resolved_target.absolute)
if content_type is None:
raise AppError(
code="unsupported_type",
message="File type is not supported for image 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),
}
def prepare_pdf_stream(self, path: str) -> dict:
resolved_target = self._path_guard.resolve_existing_path(path)
@@ -465,6 +509,10 @@ class FileOpsService:
def _thumbnail_content_type_for(path: Path) -> str | None:
return THUMBNAIL_CONTENT_TYPES.get(path.suffix.lower())
@staticmethod
def _image_content_type_for(path: Path) -> str | None:
return IMAGE_CONTENT_TYPES.get(path.suffix.lower())
@staticmethod
def _pdf_content_type_for(path: Path) -> str | None:
return PDF_CONTENT_TYPES.get(path.suffix.lower())