Add support for external library locations and improve SMB handling#1
Merged
Conversation
Introduce support for multiple library locations (local and SMB) and admin management UI/API. Changes include: - DB migration: create library_locations and site_settings tables and seed builtin_sftp_enabled. - New libraries subsystem (src/lib/libraries/*): types, encrypted credential helpers (AES-256-GCM), path normalization, mount/unmount logic using CIFS, location store, resolution/refresh of library roots, and multi-library vehicle ID encoding. - Admin API endpoints for listing/creating/updating/deleting locations and toggling builtin SFTP (src/pages/api/admin/locations/*, library-settings.ts). - Frontend: settings overlay UI for managing locations and modal + client script for CRUD (SettingsOverlay.astro, settings-locations.ts). Settings page script updated to include builtin SFTP state. - Integrations: validate and aggregate across all libraries, vehicle listing and teslacam root resolution updated to use resolved libraries, and DB pool init triggers a libraries refresh. - Docker: add cifs-utils and util-linux to image, grant SYS_ADMIN capability in docker-compose, and add library_mounts volume for SMB mount points. This enables admins to add external NAS/DAS SMB shares or host bind-mounts as searchable libraries and keeps SMB credentials encrypted in the DB. Automated mounting/unmounting and cache refreshes are included.
Introduce a DEBUG env flag for local testing. Adds src/lib/debug.ts (isDebugMode + DEBUG_FOOTER_MESSAGE), updates config.env.example and README to document DEBUG, and updates the site layout to expose data-debug-mode, render a fixed warning footer, and include CSS when enabled. Authentication logic updated so securitySetupComplete() and the login POST handler skip passkey/TOTP gating when DEBUG is true to simplify local/dev testing. Intended for development only; do not enable in production.
Enhance SMB library mounts and the locations settings UI: add required Docker capabilities/security options (SYS_ADMIN, DAC_READ_SEARCH, unconfined seccomp/apparmor) to docker-compose; implement robust CIFS mounting in mount.ts with safe shell quoting, detailed error mapping, credential file creation (0600) and cleanup, multiple mount option attempts (ntlm/ntlmv2/guest), domain-aware username parsing, and improved umount handling. Update resolve/unmount callers to pass the new requiresCredentials flag. Update SettingsOverlay and settings-locations scripts/styles to hide/disable credential fields by default, add a hint for Windows SMB guest issues, and improve accessibility via aria-hidden and tabindex handling.
Update SMB path hint in SettingsOverlay to clarify host/share vs nested folder usage. Refactor SMB mounting: add splitSmbUnc to separate //host/share and subfolder, and use mountTarget/subfolder so deeper paths are resolved after mount. Replace previous credential handling with a secure writeCredFile helper, build mount attempts from a cred file, avoid the guest mount flag (which caused EINVAL on some kernels), and adjust mount options and error messages to include the mount target. Also validate and return the resolved root path (including subfolder) and ensure temporary credential files are cleaned up.
Replace direct calls to listVehicles/readVehicleCookie/resolveActiveVehicle with vehicleFromRequest in API and clip page. apiVehicleId now uses vehicleFromRequest to get the active vehicle and falls back to clipRootForVehicle when a raw ?vehicle query is present. syncVehicleCookieFromQuery validates the query via vehicleFromRequest before setting the cookie. Update clip/[type]/[id].astro to source vehicles and activeVehicle from vehicleFromRequest and remove legacy imports.
Set the active vehicle cookie and propagate vehicle id in index links so the selected vehicle is preserved when opening clips. Refactor player internals to use videoApiUrl, wait for camera videos to be ready before starting autoplay (with a 12s fallback), and add a robust segment-end fallback that checks timeupdate/duration to advance groups when the `ended` event doesn't fire. Also prevent duplicate group advances (segmentEndHandled), reset preloadedFor when advancing, and adjust when post-load prefetching is scheduled.
Separate first-segment warming from background body prefetch and add support for multi-segment groups. Key changes: - Add data-prefetch-groups to index.astro so homepage cards carry per-segment camera lists. - index-page: parse prefetch groups and split hover (warm first segment) vs click (start background prefetch of remaining segments). - prefetch.ts: introduce SegmentCams type, clipKey, segmentUrls, urlsForSegmentGroups, and explicit first vs remaining prefetch APIs (prefetchFirstSegment, prefetchRemainingSegments, scheduleCurrentClipPrefetch). - Implement configurable range-byte prefetching and a runPrefetchPool worker pool to fetch many URLs with visibility checks and pausing. - Increase warmed <video> pool size and adjust concurrency for in-player probing (runPool concurrency bump from 2 to 4). - Remove previous homepage/catalog bulk prefetch logic in favor of targeted clip body prefetching from clicks/player load. Why: reduce unnecessary background fetches while ensuring the first segment is warmed quickly on hover and remaining segments are fetched proactively on click or when viewing the player for faster playback continuity.
Improve player startup and prefetch behavior: show a loading overlay with progress bar and accessible aria-live text; disable video autoplay attributes and hide videos until loaded. Rework player preload logic to enumerate all camera files, load them (canplaythrough) via a pooled loader, apply measured durations, and block UI until the first group can play; include graceful fallback on error. Simplify index-page prefetching to only warm the first segment on hover/touch/mousedown (remove aggressive click/remaining-segments prefetch). Remove now-unused probing/prefetch helpers and adjust imports/styles accordingly.
Introduce a Cache-API based progressive streaming system and wire it into prefetch/player flows. - Add stream-cache.ts: implements range-based priming/upgrading (primeFast/primeStretch/upgradeFull), batch helpers (primeMany/stretchMany/upgradeMany), and waitVideoPlayable. Uses Cache API to store range requests and tracks per-file stream tier (idle/fast/stretch/full). - Add clip-stream.ts: ClipStreamCoordinator to orchestrate per-clip progressive loading (prime first segment, prime all fast, focusSegment, startBackgroundPipeline) and helpers to map player groups to URLs. - Update player.ts: integrate ClipStreamCoordinator, remove blob-based mediaCache and full-file warm decoder flow, probe durations via metadata, wait for playable state via waitVideoPlayable, streamline group switching with network-aware buffering UI and background priming. Start background pipeline and fast priming on boot. - Update prefetch.ts: simplify first-segment hover behavior to prime ranges via stream-cache and add prefetchClipFast for click-initiated fast priming; remove old byte-prefetch pool, warm element bookkeeping, and other deprecated helpers. Keep warmVideoElement but limit warm pool size. - Update index-page.ts: parse prefetch groups from dataset, trigger fast clip prefetch on mousedown/touchstart in addition to hover. Overall goal: faster startup and smoother seeks by warming meaningful byte ranges (head/tail/stretch) that the player can reuse across pages, while progressively fetching full files in background.
Introduce Cybertruck (CT) as a supported model: add CT to MODEL_CODES and MODEL_LABELS, include CT in the vehicle folder regex, and surface CT_NAME in UI/help text. Add static vehicle images under public/vehicleImages and a VEHICLE_IMAGES mapping, and refactor VehicleSilhouette to use those images (with an accessible sr-only label) instead of inline SVGs. Update site-config and README messaging to mention CT_Name. Small UI/CSS adjustments for image rendering were included.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.