DSH workspaces usually need to manage files through specific API calls. The dock-files plugin provides file browsing for DSH workspaces and is maintained by AKS1st. It solves the cumbersome problem of developers having to operate on files one by one via the command line or APIs when no native file manager is available.
Installation and Dependencies¶
Installing dock-files depends on the dock-base plugin.
dsh plugin --profile web add dock-base
dsh plugin --profile web add dock-files
Environment requirements:
* DSH Web environment: >=0.1.3-alpha.2
* dock-base: >=0.2.0
* Framework: cordis ^4.0.0-rc.7
* Rendering: react ^18.2.0 (optional, used to render the UI)
Core Features¶
Directory Tree Browsing¶
The plugin provides a VSCode-style file tree interface. Directories are expanded recursively and lazily. The sorting logic places directories first and is case-insensitive (consistent with the VSCode Explorer). The interface includes color-coded type icons, tree guide lines, a toolbar (refresh / collapse all), and hover action buttons.
Session Isolation and Security¶
All operations are bounded by the session working directory. Paths are normalized with realpath and must remain inside the workspace; out-of-bounds paths return a 403 error. Host routes only accept requests from trusted sources (loopback addresses / trustedHosts + same-origin).
File Opening and Dispatch¶
When a file is clicked, the plugin dispatches it via ctx.files.open to a registered file viewer (such as dock-editor), opening it in a floating window.
Open Source Mode¶
Configure dock-files.open-source in settings (default: dock):
* dock mode: Recognizes dsh-resource://file/session/... and file/absolute/... paths, decodes them according to b67 rules, and passes the file to the Workbench.
* harness mode: Does not wrap sidebarRight.openResource(), fully preserving native behavior.
File Management¶
The right-click menu provides complete file management operations:
1. New: Create a new file/folder (automatic duplicate name avoidance; after creation, inline rename is started).
2. Rename: Inline editing; press Enter to confirm / Esc to cancel.
3. Copy/Cut/Paste: Copied items can be pasted repeatedly; cut items are grayed out; the clipboard is cleared after pasting.
4. Paste Image: Detects the system clipboard and is shown only when it contains an image; automatically names and deduplicates by MIME type.
5. Delete: Recursively deletes; will not overwrite files with the same name.
6. Other: Copy path, refresh, download in browser.
* Right-clicking on blank areas can perform new, paste, and other operations on the root directory.
Drag and Drop and Paste¶
- System drag-in: Drag system files into the browser to import them into the target folder (automatic duplicate name avoidance using the original name).
- In-tree move: Drag files/folders to another folder or blank area (treated as the root directory) to move them.
- Ctrl+V: After copying files in the system, click the panel to give it focus, then press
Ctrl+Vto paste and import.
Transfer Task Center¶
Regular files use chunked upload to support large files. All transfer tasks enter a global in-memory task center, where progress can be viewed in the floating window, status bar, or bottom area. Tasks support pause, resume, and cancel. Note: task state is not preserved across restarts.
Multi-language and Extension¶
UI text follows DSH language settings (zh/en), and the default names for new files/folders switch accordingly. The plugin provides the ctx.files service, allowing other plugins to register file viewers (registerFileViewer) and icons (registerFileIcon).
Typical Usage¶
- Mount the panel: Mount the file panel through the
dock-basesidebar and browse the current session working directory. - Open a file: Click a file; it is opened by the registered viewer.
- Configure the opening method: Modify
dock-files.open-sourcein settings. - Custom extension: Call
ctx.files.registerFileViewerin another plugin to register a viewer matching extensions or a default viewer.
Notes¶
- Windows limitation: Currently does not support directly pasting files in the Windows native Explorer, copying file contents, copying download links, or downloading folders.
- Task persistence: Transfer task state is not preserved across restarts; tasks disappear after a restart.
- Drag and drop limitation: Dropping onto itself or descendant directories is rejected.
- Security: Check the source code and license before installation.