-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Ephemeral sidecar system #2930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jamiepine
wants to merge
2
commits into
main
Choose a base branch
from
cursor/ephemeral-sidecar-system-7bd6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,464
−10
Open
Ephemeral sidecar system #2930
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| //! List ephemeral sidecars query | ||
| //! | ||
| //! Returns all sidecars (thumbnails, previews, etc.) for a specific ephemeral | ||
| //! entry. Scans the temp directory to find what derivatives exist. | ||
| use crate::{ | ||
| context::CoreContext, | ||
| infra::query::{CoreQuery, QueryResult}, | ||
| }; | ||
| use serde::{Deserialize, Serialize}; | ||
| use specta::Type; | ||
| use std::{path::PathBuf, sync::Arc}; | ||
| use uuid::Uuid; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. |
||
| /// Input for listing ephemeral sidecars | ||
| #[derive(Debug, Clone, Serialize, Deserialize, Type)] | ||
| pub struct ListEphemeralSidecarsInput { | ||
| /// Entry UUID to list sidecars for | ||
| pub entry_uuid: Uuid, | ||
| /// Library ID | ||
| pub library_id: Uuid, | ||
| } | ||
|
|
||
| /// Information about a single ephemeral sidecar | ||
| #[derive(Debug, Clone, Serialize, Deserialize, Type)] | ||
| pub struct EphemeralSidecarInfo { | ||
| /// Sidecar kind (e.g., "thumb", "preview", "transcript") | ||
| pub kind: String, | ||
| /// Sidecar variant (e.g., "grid@1x", "detail@2x") | ||
| pub variant: String, | ||
| /// File format (e.g., "webp", "mp4", "txt") | ||
| pub format: String, | ||
| /// File size in bytes | ||
| pub size: u64, | ||
| /// Relative path within temp directory (for debugging) | ||
| pub path: String, | ||
| } | ||
|
|
||
| /// Output containing ephemeral sidecar information | ||
| #[derive(Debug, Clone, Serialize, Deserialize, Type)] | ||
| pub struct ListEphemeralSidecarsOutput { | ||
| /// List of sidecars found for this entry | ||
| pub sidecars: Vec<EphemeralSidecarInfo>, | ||
| /// Total number of sidecars | ||
| pub total: usize, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize, Type)] | ||
| pub struct ListEphemeralSidecarsQuery { | ||
| input: ListEphemeralSidecarsInput, | ||
| } | ||
|
|
||
| impl CoreQuery for ListEphemeralSidecarsQuery { | ||
| type Input = ListEphemeralSidecarsInput; | ||
| type Output = ListEphemeralSidecarsOutput; | ||
|
|
||
| fn from_input(input: Self::Input) -> QueryResult<Self> { | ||
| Ok(Self { input }) | ||
| } | ||
|
|
||
| async fn execute( | ||
| self, | ||
| context: Arc<CoreContext>, | ||
| _session: crate::infra::api::SessionContext, | ||
| ) -> QueryResult<Self::Output> { | ||
| let cache = context.ephemeral_cache(); | ||
| let sidecar_cache = cache.get_sidecar_cache(self.input.library_id); | ||
|
|
||
| // Get the entry directory | ||
| let entry_dir = sidecar_cache.compute_entry_dir(&self.input.entry_uuid); | ||
|
|
||
| if !tokio::fs::try_exists(&entry_dir).await? { | ||
| return Ok(ListEphemeralSidecarsOutput { | ||
| sidecars: Vec::new(), | ||
| total: 0, | ||
| }); | ||
| } | ||
|
|
||
| let mut sidecars = Vec::new(); | ||
|
|
||
| // Scan the entry directory for sidecar kind directories | ||
| let mut read_dir = tokio::fs::read_dir(&entry_dir).await?; | ||
| while let Some(kind_entry) = read_dir.next_entry().await? { | ||
| let kind_name = kind_entry.file_name().to_string_lossy().to_string(); | ||
|
|
||
| // Convert plural back to singular (thumbs -> thumb, etc.) | ||
| let kind = if kind_name == "transcript" { | ||
| kind_name.clone() | ||
| } else { | ||
| kind_name.trim_end_matches('s').to_string() | ||
| }; | ||
|
|
||
| // Scan files within the kind directory | ||
| let mut files_dir = tokio::fs::read_dir(kind_entry.path()).await?; | ||
| while let Some(file_entry) = files_dir.next_entry().await? { | ||
| let filename = file_entry.file_name().to_string_lossy().to_string(); | ||
|
|
||
| // Parse filename as "variant.format" | ||
| if let Some((variant, format)) = filename.rsplit_once('.') { | ||
| let metadata = file_entry.metadata().await?; | ||
| let relative_path = file_entry | ||
| .path() | ||
| .strip_prefix(sidecar_cache.temp_root()) | ||
| .unwrap_or(&file_entry.path()) | ||
| .to_string_lossy() | ||
| .to_string(); | ||
|
|
||
| sidecars.push(EphemeralSidecarInfo { | ||
| kind: kind.clone(), | ||
| variant: variant.to_string(), | ||
| format: format.to_string(), | ||
| size: metadata.len(), | ||
| path: relative_path, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let total = sidecars.len(); | ||
|
|
||
| Ok(ListEphemeralSidecarsOutput { sidecars, total }) | ||
| } | ||
| } | ||
|
|
||
| crate::register_core_query!(ListEphemeralSidecarsQuery, "core.ephemeral_sidecars.list"); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| //! Ephemeral sidecar operations | ||
| //! | ||
| //! Queries and actions for managing ephemeral sidecars (thumbnails, previews, | ||
| //! etc.) for ephemeral entries. Unlike managed sidecars which are persistent | ||
| //! and database-tracked, ephemeral sidecars live in temp storage and are | ||
| //! queried directly from the filesystem. | ||
|
|
||
| pub mod list_query; | ||
| pub mod request_action; | ||
|
|
||
| pub use list_query::{ListEphemeralSidecarsInput, ListEphemeralSidecarsOutput}; | ||
| pub use request_action::{RequestEphemeralThumbnailsInput, RequestEphemeralThumbnailsOutput}; |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directory traversal check ineffective on non-canonicalized paths
The
serve_ephemeral_sidecarfunction usesstarts_withon a non-canonicalized path to prevent directory traversal, but this check is ineffective. URL path segments likeentry_uuidorvariant_and_extcan contain..sequences (URL-encoded as%2E%2E). Thestarts_withmethod compares path components literally, so a path like/tmp/.../entry/../../../etc/passwdpasses the check because its first components matchtemp_root, even thoughFile::openwill resolve the..components and access files outside the intended directory. An attacker could read arbitrary files accessible to the server process.