diff --git a/app/src/components/FilePreview.js b/app/src/components/FilePreview.js
index 61502d8f..2d2b7450 100644
--- a/app/src/components/FilePreview.js
+++ b/app/src/components/FilePreview.js
@@ -1,8 +1,8 @@
import React from "react";
import _ from "lodash";
-import {Header as SHeader, Icon, Image,} from "semantic-ui-react";
+import {Button as SButton, Dropdown, Header as SHeader, Icon, Image,} from "semantic-ui-react";
import {TagsSelector} from "../Tags";
-import {encodeMediaPath, isSupportedArchive} from "./Common";
+import {encodeMediaPath, isSupportedArchive, useLocalStorage} from "./Common";
import {getFile, tagFileGroup, untagFileGroup} from "../api";
import {ArchivePreviewContent} from "./ArchivePreview";
import {CbzViewer} from "./CbzViewer";
@@ -43,6 +43,41 @@ function getDownloadPathURL(previewFile) {
}
}
+// PrusaSlicer is omitted because it only downloads from domains whitelisted by Prusa
+// (printables.com, thingiverse.com, cults3d.com), so it cannot fetch from a WROLPi.
+// Bambu Studio asks the user to confirm because a WROLPi is not one of its trusted sites.
+export const SLICERS = [
+ {key: 'orcaslicer', text: 'Orca Slicer', scheme: 'orcaslicer'},
+ {key: 'bambustudio', text: 'Bambu Studio', scheme: 'bambustudio'},
+ {key: 'cura', text: 'Cura', scheme: 'cura'},
+];
+
+export function getSlicerURL(previewFile, scheme) {
+ // Slicers register their own URL scheme and download the file themselves, so the
+ // file parameter must be an absolute URL reachable from the user's computer.
+ const absoluteURL = new URL(getMediaPathURL(previewFile), window.location.origin).href;
+ return `${scheme}://open?file=${encodeURIComponent(absoluteURL)}`;
+}
+
+function OpenInSlicerButton({previewFile}) {
+ // Browsers cannot report which slicers are installed, so remember the last one used.
+ const [slicerKey, setSlicerKey] = useLocalStorage('preferredSlicer', SLICERS[0].key);
+ const slicer = SLICERS.find(s => s.key === slicerKey) || SLICERS[0];
+ return
+
+ >}>
+
+ {SLICERS.map(s =>
+ setSlicerKey(s.key)}/>)}
+
+
+
+}
+
function getEpubViewerURL(previewFile) {
let url = previewFile['primary_path'] ?? previewFile['path'];
return `/epub/epub.html?url=/media/${encodeMediaPath(url)}`
@@ -457,7 +492,7 @@ export function FilePreviewProvider({children}) {
await localFetchFile();
}
- function setModalContent(content, url, downloadURL, path, taggable = true) {
+ function setModalContent(content, url, downloadURL, path, taggable = true, extraButtons = null) {
// All action buttons share `size='small'` and `icon` for consistent height across viewports.
// Close is handled by the Modal's `closeIcon` (X in the top-right corner) — no dedicated button.
const openButton = url
@@ -497,6 +532,7 @@ export function FilePreviewProvider({children}) {
{downloadButton}
{directoryButton}
+ {extraButtons}
{previewFile && previewFile['id'] &&
}
@@ -549,16 +585,20 @@ export function FilePreviewProvider({children}) {
} else if (mimetype.startsWith('image/')) {
setModalContent(getImagePreviewModal(previewFile), url, null, path, taggable);
} else if (mimetype.startsWith('model/stl')) {
- setModalContent(, null, downloadURL, path, taggable);
+ setModalContent(, null, downloadURL, path, taggable,
+ );
} else if (mimetype.startsWith('model/3mf')) {
- setModalContent(, null, downloadURL, path, taggable);
+ setModalContent(, null, downloadURL, path, taggable,
+ );
} else if (mimetype.startsWith('application/octet-stream') && lowerPath.endsWith('.mp3')) {
setModalContent(getAudioPreviewModal(previewFile), url, downloadURL, path, taggable);
} else if (mimetype.startsWith('application/octet-stream') && lowerPath.endsWith('.stl')) {
- setModalContent(, null, downloadURL, path, taggable);
+ setModalContent(, null, downloadURL, path, taggable,
+ );
} else if ((mimetype.startsWith('application/octet-stream') || mimetype === 'application/zip')
&& lowerPath.endsWith('.3mf')) {
- setModalContent(, null, downloadURL, path, taggable);
+ setModalContent(, null, downloadURL, path, taggable,
+ );
} else if (mimetype.includes('cbz') || mimetype.includes('cbr') || mimetype.includes('comicbook+zip') || mimetype.includes('comicbook-rar')
|| lowerPath.endsWith('.cbz') || lowerPath.endsWith('.cbr') || lowerPath.endsWith('.cbt') || lowerPath.endsWith('.cb7')) {
setModalContent(, null, downloadURL, path, taggable);
diff --git a/app/src/components/FilePreview.test.js b/app/src/components/FilePreview.test.js
new file mode 100644
index 00000000..f660e526
--- /dev/null
+++ b/app/src/components/FilePreview.test.js
@@ -0,0 +1,24 @@
+import {getSlicerURL, SLICERS} from "./FilePreview";
+
+describe('getSlicerURL', () => {
+ test('builds a slicer link with the absolute media URL encoded once', () => {
+ const previewFile = {path: '3d printing/benchy.stl'};
+ const url = getSlicerURL(previewFile, 'orcaslicer');
+ expect(url).toEqual(
+ `orcaslicer://open?file=${encodeURIComponent('http://localhost/media/3d%20printing/benchy.stl')}`);
+ });
+
+ test('prefers primary_path and encodes special characters', () => {
+ const previewFile = {
+ primary_path: 'models/Buckle #2 (v2)/buckle.3mf',
+ path: 'models/Buckle #2 (v2)/buckle.stl',
+ };
+ const url = getSlicerURL(previewFile, 'bambustudio');
+ expect(url).toEqual(
+ `bambustudio://open?file=${encodeURIComponent('http://localhost/media/models/Buckle%20%232%20(v2)/buckle.3mf')}`);
+ });
+
+ test('PrusaSlicer is not offered because it only downloads from whitelisted domains', () => {
+ expect(SLICERS.map(s => s.scheme)).not.toContain('prusaslicer');
+ });
+});