mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-21 18:47:13 +02:00
fix(slicer): drop the legacy library:read from the slice gate (#2725)
The desktop handoff accepted library:read alongside read_all/read_own, on the reasoning that default groups do not carry it and requiring it would lock out Operators and Viewers. The permission grants nothing in that position: the slicer-token endpoint gates on require_ownership_permission(LIBRARY_READ_ALL, LIBRARY_READ_OWN), and neither that dependency nor User.has_permission expands the legacy name, so a group holding only library:read gets a 403 there. It cannot reach the File Manager to try, either - GET /library/folders gates on the same pair - and the library:read -> library:read_own migration in core/database.py runs only over the groups named in DEFAULT_GROUPS, so a custom role that still carries it stays stuck rather than being upgraded. custom role that still carries it stays stuck rather than being upgraded. Accepting it only enabled a menu item the server refuses, and the failure is indistinguishable from "no slicer installed" once the catch hands the unauthenticated URL over. Removed, with the comment recording the reason so the next reader does not re-add it, and a test that pins it. --- refactor(slicer): share one sliceable-file-type rule (#2725) The File Manager and the 3D preview decide the same thing about the same file and each held its own list of extensions - which is how they came to disagree, offering a desktop handoff for an STL whose own preview showed "Open in Slicer" greyed out. Making the two lists identical fixed the symptom and left the drift, so SLICEABLE_FILE_TYPES now lives in utils/slicer.ts with isSliceableFileType for a stored file_type and isSliceableFilename for a name. The filename form still rules out the compound extensions explicitly, since .gcode.3mf ends with .3mf; the type form does not need to, because classify_file_type stores that one whole. Both test files mocked the whole slicer module, which would have replaced the new predicates with undefined - switched to importOriginal so only openInSlicer is stubbed. That is the better shape regardless: the tests now exercise the rule the component runs instead of a copy declared beside them. Carries the rebuilt bundle. The CSS hash moves with it - the split button introduces Tailwind classes the previous build had no reason to emit.
This commit is contained in:
@@ -41,6 +41,43 @@ export function resolveDesktopSlicer(
|
||||
return openInSlicer ?? preferredSlicer ?? 'bambu_studio';
|
||||
}
|
||||
|
||||
/**
|
||||
* File types a slicer can be handed — both by the desktop URI handler and by
|
||||
* the in-app sidecar. Source geometry only: a sliced file is an output, and
|
||||
* neither slicer has anything to do with one.
|
||||
*
|
||||
* Lives here rather than beside either caller because both the File Manager
|
||||
* (which has a filename) and the 3D preview (which has a `LibraryFile.file_type`)
|
||||
* decide the same thing about the same file. They used to hold separate lists,
|
||||
* and the two disagreed — a card menu offered a desktop handoff for an STL
|
||||
* whose own 3D preview showed "Open in Slicer" greyed out.
|
||||
*/
|
||||
export const SLICEABLE_FILE_TYPES = ['3mf', 'stl', 'step', 'stp'] as const;
|
||||
|
||||
/**
|
||||
* Does a `LibraryFile.file_type` name a sliceable source file?
|
||||
*
|
||||
* The backend stores compound extensions whole — a sliced 3MF classifies as
|
||||
* `gcode.3mf`, not `3mf` (`classify_file_type` in `api/routes/library.py`) — so
|
||||
* membership alone is enough to exclude sliced output here.
|
||||
*/
|
||||
export function isSliceableFileType(fileType?: string | null): boolean {
|
||||
const normalized = (fileType || '').toLowerCase();
|
||||
return (SLICEABLE_FILE_TYPES as readonly string[]).includes(normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a filename name a sliceable source file?
|
||||
*
|
||||
* Checked against the name rather than a stored type, so the compound
|
||||
* extensions have to be ruled out explicitly: `.gcode.3mf` ends with `.3mf`.
|
||||
*/
|
||||
export function isSliceableFilename(filename: string): boolean {
|
||||
const lower = filename.toLowerCase();
|
||||
if (lower.endsWith('.gcode') || lower.endsWith('.gcode.3mf')) return false;
|
||||
return SLICEABLE_FILE_TYPES.some((ext) => lower.endsWith(`.${ext}`));
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect the user's operating system
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user