feat: thumbnails added
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -25,6 +25,12 @@ SPECIAL_TEXT_FILENAMES = {
|
||||
"dockerfile": "text/plain",
|
||||
"containerfile": "text/plain",
|
||||
}
|
||||
THUMBNAIL_CONTENT_TYPES = {
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".png": "image/png",
|
||||
".webp": "image/webp",
|
||||
}
|
||||
VIDEO_CONTENT_TYPES = {
|
||||
".mp4": "video/mp4",
|
||||
".mkv": "video/x-matroska",
|
||||
@@ -370,6 +376,39 @@ class FileOpsService:
|
||||
"content": self._filesystem.stream_file_range(resolved_target.absolute, start, end),
|
||||
}
|
||||
|
||||
def prepare_thumbnail_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 thumbnail",
|
||||
status_code=409,
|
||||
details={"path": resolved_target.relative},
|
||||
)
|
||||
|
||||
content_type = self._thumbnail_content_type_for(resolved_target.absolute)
|
||||
if content_type is None:
|
||||
raise AppError(
|
||||
code="unsupported_type",
|
||||
message="File type is not supported for thumbnail",
|
||||
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
|
||||
@@ -385,6 +424,10 @@ class FileOpsService:
|
||||
def _video_content_type_for(path: Path) -> str | None:
|
||||
return VIDEO_CONTENT_TYPES.get(path.suffix.lower())
|
||||
|
||||
@staticmethod
|
||||
def _thumbnail_content_type_for(path: Path) -> str | None:
|
||||
return THUMBNAIL_CONTENT_TYPES.get(path.suffix.lower())
|
||||
|
||||
def _record_history(
|
||||
self,
|
||||
*,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from backend.app.api.schemas import SettingsResponse, SettingsUpdateRequest
|
||||
from backend.app.db.settings_repository import SettingsRepository
|
||||
|
||||
|
||||
class SettingsService:
|
||||
def __init__(self, repository: SettingsRepository):
|
||||
self._repository = repository
|
||||
|
||||
def get_settings(self) -> SettingsResponse:
|
||||
values = self._repository.get_settings()
|
||||
return SettingsResponse(show_thumbnails=self._as_bool(values.get("show_thumbnails"), default=False))
|
||||
|
||||
def update_settings(self, request: SettingsUpdateRequest) -> SettingsResponse:
|
||||
self._repository.set_setting("show_thumbnails", "true" if request.show_thumbnails else "false")
|
||||
return self.get_settings()
|
||||
|
||||
@staticmethod
|
||||
def _as_bool(value: str | None, default: bool) -> bool:
|
||||
if value is None:
|
||||
return default
|
||||
return value.strip().lower() in {"1", "true", "yes", "on"}
|
||||
Reference in New Issue
Block a user