Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Select or deselect files inside the existing preview, with previous/next navigation across previewable files in table order, keyboard controls, pagination safeguards, and unsaved-edit protection. Selection stays in the table after closing. Adapted from @antonp2k's contribution in PR [#39](https://github.com/rgcsekaraa/brows3/pull/39), retaining the current image viewer and zoom controls.
- Local preview cache: previewed and prefetched images, PDFs and text files are kept on disk under `<profile>/<bucket>/<object key>`, mirroring the remote layout. A copy is reused only while its size, modification date and ETag match the remote object; otherwise a new copy is downloaded. When the server cannot be reached, the last copy is shown with an offline label. Configurable size limit with least-recently-used eviction and a Clear button in Settings.
- Saved local-folder-to-S3 sync jobs with manual runs or in-app interval schedules, explicit future-upload approval, filters, saved bandwidth limits, pause/resume, confirmed cancellation and deletion, and completion/failure notifications.
- Durable job recovery that pauses interrupted, failed, or missed-while-closed runs, prevents overlapping runs, and prevents multiple Brows3 instances from executing the same schedules. Jobs always compare fresh content and retain the existing guarded upload behavior.

Expand Down
35 changes: 35 additions & 0 deletions docs/PREVIEW_NAVIGATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@ At the end of the loaded sequence, Next can fetch additional listing pages. Each

Context identity guards prevent completed requests from navigating a closed preview or applying navigation to a different object, folder, sort, or search context.

## Prefetching

While a preview is open, the previous and next previewable files are loaded in advance so navigation shows them without a spinner. The window slides: opening a preview loads both neighbours after the visible file has loaded, Next loads one more next file, and Previous loads one more previous file. Files outside the window are evicted.

- Only neighbours smaller than 10 MB (by listing size) are prefetched. Larger files load when they become visible.
- Images, PDFs and text files are saved to the local preview cache (see below); images are also decoded in advance. Video and audio files get metadata and a signed URL only.
- Prefetching never loads additional listing pages.
- Signed URLs are reused for 50 minutes; text and local copies are rechecked against S3 after 5 minutes. Failed loads are not cached, and Retry always requests a fresh load.
- Closing the preview, saving, object cache invalidation, and profile, bucket, or text-limit changes discard prefetched content. Saving prefetched text remains ETag-guarded.

## Local preview cache

Images, PDFs and text files that are previewed or prefetched are stored on disk, in the app cache directory under `preview-cache/files/<profile id>/<bucket>/<object key>`. The folder structure mirrors the remote keys. Video and audio are always streamed from S3.

When a file is opened:

1. The app asks S3 for the object's size, `LastModified` and ETag (one HEAD request).
2. If a local copy exists and its size, modification date and ETag all match, the local copy is shown.
3. Otherwise the object is downloaded into the cache, pinned to the ETag it was checked against (`If-Match`). Its file modification time is set to the object's `LastModified`, and it replaces the old copy atomically.
4. If S3 cannot be reached and a local copy exists, that copy is shown with an "Offline copy" label. Offline results are rechecked after 30 seconds.

Details:

- ETags, sizes, dates and last-access times are kept in `preview-cache/index.json`. A copy whose file was changed on disk, or that is missing from the index, is never trusted.
- Key segments that are not valid file names on every platform are percent-encoded: `%`, `<>:"|?*\`, control characters, trailing dots or spaces, Windows device names such as `CON`, and empty, `.` or `..` segments. Keys that differ only in letter case never share a copy, even on case-insensitive file systems.
- An object whose name matches an existing cached folder (for example `photos` next to `photos/a.jpg`) is previewed from S3 without being cached.
- Objects over 100 MB, text over the text preview limit, and objects without a `LastModified` date are not cached.
- Above the size limit in Settings (default 1 GB), the least recently used copies are removed. Settings can also disable or clear the cache. Deleting a profile removes its cached files. Saving a text file removes its copy, so the next preview downloads the new version.
- On startup, orphaned files, index entries without intact files, and partial downloads older than one hour are removed.
- The webview loads cached files through Tauri's asset protocol, scoped to `$APPCACHE/preview-cache/files/**`.

## Controls and draft protection

- Left and Right move between previews; Space toggles file selection. Space on a focused button retains the button's native activation.
Expand All @@ -25,6 +56,10 @@ The existing image viewer and BaseDialog remain authoritative. Preserve their li
| Source | Responsibility |
| --- | --- |
| `src/hooks/usePreviewNavigation.ts` | Previewable sequence, boundaries, bounded pagination, retry feedback, and stale-result guards |
| `src/lib/previewPrefetch.ts` | Shared preview loader (local cache first, S3 fallback), prefetch size limit, and request cache with expiry |
| `src-tauri/src/preview_cache.rs` | On-disk layout, key encoding, version index, validation, eviction and cleanup |
| `src-tauri/src/commands/preview_cache.rs` | HEAD with offline fallback, ETag-pinned fill, cached text reads, usage and clearing |
| `src/hooks/usePreviewPrefetch.ts` | Sliding previous/next prefetch window and cache clearing |
| `src/lib/objectSort.ts` | Shared table and preview comparison for name, size, date, and storage class |
| `src/components/dialogs/ObjectPreviewDialog.tsx` | Mixed file previews, selection controls, keyboard exclusions, editing and discard protection |
| `src/components/dialogs/ImagePreviewViewer.tsx` | Existing image rendering, zoom and pan, plus selection and navigation controls |
Expand Down
7 changes: 7 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tauri-build = { version = "2.5.3", features = [] }

[dependencies]
# Tauri core
tauri = { version = "2.9.5", features = [] }
tauri = { version = "2.9.5", features = ["protocol-asset"] }
tauri-plugin-log = "2"
tauri-plugin-shell = "2"
tauri-plugin-dialog = "2"
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod cross_copy;
pub mod jobs;
pub mod objects;
pub mod operations;
pub mod preview_cache;
pub mod profiles;
pub mod sync;
pub mod transfer;
Expand Down
30 changes: 17 additions & 13 deletions src-tauri/src/commands/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MAX_SEARCH_REQUESTS: usize = 100;
const DEFAULT_MAX_TEXT_PREVIEW_BYTES: u64 = 2 * 1024 * 1024;
const MAX_TEXT_PREVIEW_BYTES: u64 = 100 * 1024 * 1024;

fn normalized_text_preview_limit(max_bytes: Option<u64>) -> u64 {
pub(crate) fn normalized_text_preview_limit(max_bytes: Option<u64>) -> u64 {
max_bytes
.unwrap_or(DEFAULT_MAX_TEXT_PREVIEW_BYTES)
.clamp(1, MAX_TEXT_PREVIEW_BYTES)
Expand Down Expand Up @@ -61,6 +61,21 @@ fn is_likely_binary_text_mismatch(bytes: &[u8]) -> bool {
control_count.saturating_mul(100) > bytes.len().saturating_mul(5)
}

/// Rejects binary and non-UTF-8 content before it reaches the text editor.
pub(crate) fn decode_preview_text(bytes: Vec<u8>) -> Result<String> {
if is_likely_binary_text_mismatch(&bytes) {
return Err(crate::error::AppError::InvalidContent(
"This object appears to contain binary data and cannot be edited safely in the text editor. Download it to inspect locally.".to_string(),
));
}
String::from_utf8(bytes).map_err(|_| {
crate::error::AppError::InvalidContent(
"This object is not readable as UTF-8 text. Download it to inspect locally."
.to_string(),
)
})
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ListObjectsResult {
pub objects: Vec<S3Object>,
Expand Down Expand Up @@ -1021,18 +1036,7 @@ pub async fn get_object_content(
bytes.extend_from_slice(&chunk);
}

if is_likely_binary_text_mismatch(&bytes) {
return Err(crate::error::AppError::InvalidContent(
"This object appears to contain binary data and cannot be edited safely in the text editor. Download it to inspect locally.".to_string(),
));
}

let content = String::from_utf8(bytes).map_err(|_| {
crate::error::AppError::InvalidContent(
"This object is not readable as UTF-8 text. Download it to inspect locally."
.to_string(),
)
})?;
let content = decode_preview_text(bytes)?;
Ok(ObjectText {
content,
e_tag,
Expand Down
Loading
Loading