Resource Versioning
Resources track file changes through content-addressable versioning. Each upload creates a new version record while deduplicating storage by SHA1 hash.
How Versioning Works
When you upload a new version of a resource:
- Stores the new file using content-addressable storage (files are stored by their SHA1 hash)
- Creates a version record with metadata (file size, dimensions, content type, etc.)
- Updates the resource to point to the new version
- Regenerates thumbnails and previews automatically
- Preserves all previous versions for comparison and restoration
Content Deduplication
Files are stored by hash, meaning identical files are only stored once regardless of how many versions reference them. This saves disk space when:
- You restore a previous version (creates a new version record but reuses the existing file)
- Multiple resources share the same file content
- A version is deleted but other versions still reference the same file
Edits That Create Versions
Uploading a new file is not the only way to add a version. The in-place editing operations on the resource detail page also produce a new version, so the result appears in the version history and the previous content is preserved:
- Rotate an image
- Crop an image (when its Save as choice is left on New version)
- Trim a video to a time range
Each of these stores the edited file as a new version, makes it the current version, and clears cached thumbnails. See Managing Resources for how to run them. (Uploading a custom thumbnail does not create a version -- it only replaces the stored preview.)
A crop saved as a New resource instead produces no version at all: the source is untouched and the crop becomes its own resource, with its own version 1.
Version History Panel

The resource detail page includes a Versions panel listing all versions of the file.
For each version, you can see:
- Version number (v1, v2, v3, etc.)
- Creation date
- File size
- Comment (optional description of what changed)
- Current badge for the Current Version
- Image thumbnail that opens that version in the viewer; video versions have a clickable film icon
Actions Available
| Action | Description |
|---|---|
| Download | Download that specific version's file |
| Restore | Create a new version from an older one, making it current |
| Delete | Remove a version (cannot delete the current version or the last remaining version) |
| Upload New | Add a new version with an optional comment |
Versions in the Media Viewer
Choose Versions in the viewer toolbar, or press H, to open the version strip above the media. It shows every Resource Version, with the Current Version marked as current. Select an image or video to view its content. Other file types remain visible in the history but cannot be selected. Dates and sizes appear on wider screens; each entry's tooltip carries its comment.
The Displayed Version changes only the media and its dimensions. Info and Edit Tags continue to describe and edit the Resource. While a Historical Version is displayed, a Version N of M badge remains visible even if you close the strip. Choose Back to current to return to the Current Version. Rotate and Crop are disabled until you return.
Navigating to another Resource or closing the viewer resets the Displayed Version. Press Escape to close the viewer. Restore, Download, and Compare remain on the resource page, linked from the strip.
Comparing Versions
Select two versions to compare by clicking the Compare button in the version panel, then checking two versions and clicking Compare Selected.
When a resource has exactly two versions, clicking Compare automatically selects both of them, so Compare Selected is ready immediately -- no checkbox clicks required.

The comparison page shows:
Metadata Comparison Table
A side-by-side table displaying:
- Content type (with match/mismatch indicator)
- File size (with delta showing increase or decrease)
- Dimensions (for images)
- Hash match status
- Creation dates
- Comments
Content Comparison
Different comparison modes are available depending on file type:
Image Comparison
Two image versions are compared in an embedded image comparison with six modes. Choose a mode with the buttons above the image:
- Side-by-Side shows the two versions in panes next to each other. Zooming or panning one pane moves the other with it, and a crosshair marks the same point in both.
- Toggle shows one version at a time. Click or tap the image, or press
SpaceorEnterwhile it has focus, to switch to the other. Blink switches between them on its own, at up to 3 switches per second. It starts stopped on every visit, and it is unavailable when your system asks for reduced motion (and stops if that preference turns on while it runs). - Fade crossfades from one version to the other with a slider.
- Wipe puts a divider across the image: the Base version shows on the left of it and the Compare version on the right. Drag its grip, tap or click the image where you want the divider, or Tab to the divider and move it with the arrow keys (
Shiftfor bigger steps,HomeandEndfor the edges). - Onion lays one version over the other with an opacity slider, and Color Tint colours them warm and cool to tell them apart.
- Diff shows the difference between the versions. Black means no difference and any other colour means they differ there; with Invert on, white means no difference instead. Gain brightens small differences. The Diff Breakdown disclosure describes in words where the changes are.
Zoom with the buttons, Ctrl or ⌘ with the scroll wheel, or a pinch, and pan by dragging. Press Keyboard shortcuts and help (? while the image has focus) for every shortcut.
Swap exchanges which version is Base and which is Compare in place and keeps the alignment: nothing moves or rescales. In Side-by-Side the two panes trade places, in Wipe the two versions trade sides of the divider, and in Fade and Onion the slider value mirrors. This is different from the page's swap button beside the version pickers, which reloads the page with the sides exchanged and resets the alignment.
Transform & Align lines the two versions up. Its fit buttons decide how each version is sized: Actual (the default) shows each version at its real size against the other, so a version scanned at twice the resolution is drawn twice as large; Contain and Cover scale both to the same frame, Stretch distorts each onto it, and 4-Corner Warp lets you drag each corner of a version onto the matching point of the other. It also holds the 9-point anchor, the reference size (by default the larger of the two, so neither is cropped), single-pixel offsets, and a pan pad.
Changed pixels
The comparison banner's Changed pixels is the share of the compared area where the two versions differ at all. Where only one version covers an area, that area is compared against black, so a black pixel facing uncovered area does not count as changed. Large images are compared on a reduced grid, shown as ~12.3% (sampled); when that reduced comparison finds no difference at all it says Sampled ~0% (inconclusive), because finer differences may remain.
- It appears once you open Diff and both versions can be measured (a format the browser cannot display, or a failed load, leaves it hidden). It measures the Base and Compare pair, not whatever image Blink happens to show.
- It stays while it still describes what is on screen. Any change to the measured pair or the alignment, Swap included, hides it until Diff measures again.
- For animated images it describes the paused frames Diff compares, not the current playback.
Text Comparison
For text files (plain text, code, markdown, etc.):
| Mode | Description |
|---|---|
| Unified | Single view with additions (green) and deletions (red) marked |
| Side-by-side | Two columns showing each version with changes highlighted |
The comparison also shows statistics: lines added and lines removed. The toolbar carries three further controls:
- Previous change and Next change, which jump between changed regions and report the position as "n of m changes"
- Expand all, which opens the unchanged regions the diff folds away by default
- Copy diff, which puts the diff on the clipboard as a patch
PDF Comparison
PDFs get their own panel. It shows a document icon, the file size and a download link for each side, with a Load in viewer button that swaps in two inline frames rendering the two documents side by side.
Binary and Other Files
For files that are neither image, text, nor PDF, you can:
- See thumbnails (if available)
- View file metadata
- Download both versions for local comparison
Cross-Resource Comparison
You can also compare versions between different resources. This is useful when:
- Finding which version of two similar files is newer
- Comparing files that may be related but stored separately
- Investigating potential duplicates
To compare across resources, use the resource picker on the comparison page to select different resources for each side.
Dynamic Side Labels
The compare header labels change based on context:
- Same-resource comparisons: labels show version numbers (e.g.,
v1,v5). If one of the selected versions is the current one, that side is labeledCurrent. If neither is current and they differ, the higher-numbered version is labeledNewerand the lowerOlder. - Cross-resource comparisons: labels show each resource's name (with its ID when the two names would otherwise read the same).
Merge Panel
When comparing two different resources (cross-resource), and both sides are set to their respective current versions, a Merge panel appears at the bottom of the comparison page.
The merge panel includes:
- A Keep loser as older version of winner checkbox (
KeepAsVersion). When checked, the losing resource's file is saved as an older version on the winner before the loser is deleted. - ← Left Wins: merges the right resource into the left, redirecting to the left resource.
- Right Wins →: merges the left resource into the right, redirecting to the right resource.
Restoring a Version
To restore a previous version:
- Navigate to the resource's detail page
- Open the Versions panel
- Find the version you want to restore
- Click Restore
Restoring creates a new version with the content of the old version. It does not overwrite history - you can always see the full version timeline.
The restore action:
- Creates a new version (e.g., if current is v5 and you restore v2, you get v6 with v2's content)
- Updates the resource to use the restored content
- Regenerates thumbnails
- Logs the action with a default comment: "Restored from version X"
Uploading New Versions
To upload a new version:
- Navigate to the resource's detail page
- Open the Versions panel
- Use the file input at the bottom
- Optionally add a comment describing the changes
- Click Upload New Version
Add a comment describing the change (e.g., "Fixed typo in title", "Higher resolution scan").
Storage Implications
Disk Space
Each unique file is stored once. Version records are small -- roughly a few hundred bytes of metadata each -- so the main storage cost is the actual file content.
To estimate storage needs:
- Count unique file content (not versions)
- Consider that restored versions reuse existing files
- Deleting versions may or may not free space depending on references
Database Growth
Each version adds one row to the resource_versions table. For large databases with millions of resources, this can add up. Consider periodic cleanup of old versions.
Cleanup Options
Two cleanup modes are available:
Per-resource cleanup:
- Keep only the last N versions
- Delete versions older than X days
- Dry-run mode to preview what would be deleted
Bulk cleanup:
- Clean versions across many resources at once. Supplying an owner group scopes the cleanup to resources owned by that group; with no owner scope it runs across every resource in the database
- Same criteria options (keep last N, older than X days)
- Dry-run mode is strongly recommended before an unscoped run
Version deletion is permanent. Always use dry-run mode first to verify what will be deleted.
API Endpoints
| Method | Path | Description |
|---|---|---|
GET | /v1/resource/versions?resourceId={resourceId} | List all versions for a Resource |
GET | /v1/resource/version?id={versionId} | Get a single version by ID |
GET | /v1/resource/version/file?versionId={versionId} | Download a version's file |
POST | /v1/resource/versions?resourceId={resourceId} | Upload a new version (multipart: file, comment) |
POST | /v1/resource/version/restore | Restore a previous version (resourceId, versionId, comment) |
DELETE | /v1/resource/version | Delete a version (resourceId, versionId) |
POST | /v1/resource/version/delete | Delete a version (POST alias for DELETE) |
POST | /v1/resource/versions/cleanup | Cleanup old versions for a single Resource (JSON body) |
POST | /v1/resources/versions/cleanup | Bulk cleanup across Resources |
GET | /v1/resource/versions/compare | Compare two versions side-by-side |
Migration from Older Databases
On startup, a background migration automatically creates actual v1 records for Resources created before version was introduced:
- Finds Resources with no
current_version_id - Processes in batches of 500 (with 10ms sleep between batches)
- Creates a v1 record from the current Resource state
- Logs progress every 10,000 Resources
A second pass then syncs each Resource's hash, location, content type, dimensions and size from its current version, in batches of 100, repairing Resources whose fields have drifted. -skip-version-migration skips both passes.
The migration does not block startup. For databases with millions of Resources, skip it and run during a maintenance window:
| Flag | Env Variable | Default |
|---|---|---|
-skip-version-migration | SKIP_VERSION_MIGRATION=1 | false |
./mahresources -skip-version-migration -db-type=SQLITE -db-dsn=./mahresources.db -file-save-path=./files