307 lines
14 KiB
HTML
307 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>File Explorer Page | HiAPI-C# 2025 </title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="title" content="File Explorer Page | HiAPI-C# 2025 ">
|
|
|
|
|
|
<link rel="icon" href="../../img/HiAPI.favicon.ico">
|
|
<link rel="stylesheet" href="../../public/docfx.min.css">
|
|
<link rel="stylesheet" href="../../public/main.css">
|
|
<meta name="docfx:navrel" content="../../toc.html">
|
|
<meta name="docfx:tocrel" content="../toc.html">
|
|
|
|
<meta name="docfx:rel" content="../../">
|
|
|
|
|
|
|
|
<meta name="loc:inThisArticle" content="In this article">
|
|
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
|
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
|
<meta name="loc:tocFilter" content="Filter by title">
|
|
<meta name="loc:nextArticle" content="Next">
|
|
<meta name="loc:prevArticle" content="Previous">
|
|
<meta name="loc:themeLight" content="Light">
|
|
<meta name="loc:themeDark" content="Dark">
|
|
<meta name="loc:themeAuto" content="Auto">
|
|
<meta name="loc:changeTheme" content="Change theme">
|
|
<meta name="loc:copy" content="Copy">
|
|
<meta name="loc:downloadPdf" content="Download PDF">
|
|
|
|
<script type="module" src="./../../public/docfx.min.js"></script>
|
|
|
|
<script>
|
|
const theme = localStorage.getItem('theme') || 'auto'
|
|
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
|
|
<header class="bg-body border-bottom">
|
|
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
|
<div class="container-xxl flex-nowrap">
|
|
<a class="navbar-brand" href="../../index.html">
|
|
<img id="logo" class="svg" src="../../img/HiAPI.logo.png" alt="">
|
|
|
|
</a>
|
|
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
|
<i class="bi bi-three-dots"></i>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navpanel">
|
|
<div id="navbar">
|
|
<form class="search" role="search" id="search">
|
|
<i class="bi bi-search"></i>
|
|
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="container-xxl">
|
|
<div class="toc-offcanvas">
|
|
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
|
<div class="offcanvas-header">
|
|
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
|
</div>
|
|
<div class="offcanvas-body">
|
|
<nav class="toc" id="toc"></nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<div class="actionbar">
|
|
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
|
<i class="bi bi-list"></i>
|
|
</button>
|
|
|
|
<nav id="breadcrumb"></nav>
|
|
</div>
|
|
|
|
<article data-uid="">
|
|
<h1 id="file-explorer-page">File Explorer Page</h1>
|
|
|
|
<p>The File Explorer page is a server-side filesystem browser covering three named roots:</p>
|
|
<ul>
|
|
<li><strong>AdminDirectory</strong> — server-wide admin area.</li>
|
|
<li><strong>ProjectDirectory</strong> — the currently-loaded project directory (omitted from the root list when no project is loaded).</li>
|
|
<li><strong>ResourceDir</strong> — the shared resource tree under <code>AdminDirectory + "Resource/"</code>.</li>
|
|
</ul>
|
|
<div class="NOTE">
|
|
<h5>Note</h5>
|
|
<p>Absolute filesystem paths <strong>never leave the server</strong>. The <code>/roots</code> endpoint returns only <code>{ name, displayName }</code>, and every exception message is scrubbed to replace root prefixes with the tokens <code><Admin></code> / <code><Project></code> / <code><Resource></code> before it is returned to the browser.</p>
|
|
</div>
|
|
<h2 id="layout">Layout</h2>
|
|
<ul>
|
|
<li>File Explorer Page
|
|
<ul>
|
|
<li>Toolbar
|
|
<ul>
|
|
<li>Root Selector Dropdown — display-name only, sourced from <code>GET /roots</code>.</li>
|
|
<li>Up Button</li>
|
|
<li>Path Input — editable; <code>Enter</code> navigates.</li>
|
|
<li>Refresh / New Folder / New File / Upload Buttons.</li>
|
|
</ul>
|
|
</li>
|
|
<li>Breadcrumb Row — single-click navigation up the tree.</li>
|
|
<li>Listing Table (<code><q-table></code>) — columns Name / Size / Modified / Actions. Directories first, then files, name-ascending.
|
|
<ul>
|
|
<li>Row click:
|
|
<ul>
|
|
<li>Directory → navigate into it.</li>
|
|
<li>Non-binary file → open the editor dialog.</li>
|
|
</ul>
|
|
</li>
|
|
<li>Actions: Edit (non-binary files only), Download (files), Download ZIP (folders), Extract ZIP (<code>.zip</code> only), Rename, Duplicate, Delete (double-click to confirm).</li>
|
|
</ul>
|
|
</li>
|
|
<li>Editor Dialog (full-width / full-height)
|
|
<ul>
|
|
<li>Title Bar — file name + language chip + Cancel / Save / Close.</li>
|
|
<li>Body — <code><TextEditor></code> wrapping CodeMirror 6 filling the viewport.</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<h2 id="behavior">Behavior</h2>
|
|
<ul>
|
|
<li><strong>Path-traversal defence.</strong> Every request is resolved via <code>Path.GetFullPath</code> and validated with <code>Hi.Common.PathUtils.PathUtil.IsDescendant(root, absolute)</code> before any IO. Attempts like <code>relativePath=../outside</code> are rejected with HTTP 400.</li>
|
|
<li><strong>Duplicate.</strong> <code>POST /copy</code> tries <code>{name}-Copy-00</code> through <code>{name}-Copy-19</code> and returns the first free slot; 400 if all 20 are taken.</li>
|
|
<li><strong>UTF-8 without BOM.</strong> <code>WriteText</code> uses a cached <code>new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)</code> so round-tripped files do not accumulate a 3-byte BOM on every save.</li>
|
|
<li><strong>Binary gating.</strong> The backend refuses to open binary files as text; the frontend also pre-filters by extension (<code>.stl</code>, <code>.zip</code>, images, DBs, …) so the Edit button only appears when the text path is likely to work.</li>
|
|
</ul>
|
|
<h2 id="syntax-highlighting">Syntax Highlighting</h2>
|
|
<p><code>components/widgets/TextEditor.vue</code> wraps CodeMirror 6 so the editor gets real syntax highlighting for the common project-file formats listed below.</p>
|
|
<p>Stack:</p>
|
|
<ul>
|
|
<li><code>codemirror</code> + <code>@codemirror/state</code> + <code>@codemirror/view</code> (core).</li>
|
|
<li><code>@codemirror/lang-xml</code> + <code>@codemirror/lang-json</code> + <code>@codemirror/lang-markdown</code> (3 language packs).</li>
|
|
</ul>
|
|
<p>Props: <code>modelValue</code> (two-way), <code>language: 'xml' | 'json' | 'markdown' | 'text'</code> (default <code>text</code>), <code>readonly</code>. Language and readonly are swapped via <code>Compartment.reconfigure</code>, so the view never has to tear down on mode change.</p>
|
|
<p>Extension → language mapping lives in <code>components/widgets/editorLanguage.ts</code> (single source of truth imported by both <code>TextEditor.vue</code> and <code>FileExplorerPage.vue</code>):</p>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Language</th>
|
|
<th>Extensions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><code>xml</code></td>
|
|
<td><code>xml</code>, <code>hincproj</code>, <code>CoatingMaterial</code>, <code>CutterMaterial</code>, <code>Holder</code>, <code>WorkpieceMaterial</code>, <code>mp</code>, <code>MillingPara</code>, <code>SpindleCapability</code>, <code>StickMachiningTool</code>, <code>general-mech</code>, <code>mt</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>markdown</code></td>
|
|
<td><code>md</code>, <code>markdown</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>json</code></td>
|
|
<td><code>json</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>text</code> (fallback)</td>
|
|
<td>everything else, including <code>.nc</code> / <code>.ptp</code> / <code>.mpf</code> / <code>.h</code> / <code>.cs</code> / <code>.csv</code></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="source-code-path">Source Code Path</h2>
|
|
<p>See <a href="../index.html">HiNC App Anatomy</a> for git repository links.</p>
|
|
<h3 id="wpf-application-source-code-path">WPF Application Source Code Path</h3>
|
|
<ul>
|
|
<li>Not implemented.</li>
|
|
</ul>
|
|
<h3 id="web-page-application-source-code-path">Web Page Application Source Code Path</h3>
|
|
<p>HiNC-2025-webservice (Quasar CLI SPA):</p>
|
|
<ul>
|
|
<li><code>wwwroot-src/src/pages/FileExplorerPage.vue</code> — routed page at <code>/util/file-explorer</code>.</li>
|
|
<li><code>wwwroot-src/src/components/widgets/TextEditor.vue</code> — CodeMirror 6 wrapper.</li>
|
|
<li><code>wwwroot-src/src/components/widgets/editorLanguage.ts</code> — extension → <code>EditorLanguage</code> mapping.</li>
|
|
<li><code>wwwroot-src/src/api/fileExplorer.ts</code> — typed wrapper over <code>/api/file-explorer/*</code>.</li>
|
|
<li><code>wwwroot-src/src/router/routes.ts</code> — <code>/util/file-explorer</code> entry (route name <code>util-file-explorer</code>).</li>
|
|
<li><code>wwwroot-src/src/layouts/AppMenuBar.vue</code> — <code>Util → File Explorer</code> entry.</li>
|
|
<li><code>Common/FileExplorerController.cs</code> — REST endpoints under <code>/api/file-explorer</code>:</li>
|
|
</ul>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Method</th>
|
|
<th>Path</th>
|
|
<th>Notes</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>GET</td>
|
|
<td><code>/roots</code></td>
|
|
<td>List available roots; Project is omitted when no project is loaded. Returns display names only.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>GET</td>
|
|
<td><code>/list?rootName=&relativePath=</code></td>
|
|
<td>Directories-first, name-ascending listing.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>GET</td>
|
|
<td><code>/read-text?…</code></td>
|
|
<td>UTF-8 text; when the file is detected as binary returns <code>content=null</code>, <code>isBinary=true</code>.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>POST</td>
|
|
<td><code>/write-text</code></td>
|
|
<td>Body <code>{rootName, relativePath, content}</code>; creates parents as needed.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>POST</td>
|
|
<td><code>/create-file</code></td>
|
|
<td>Fails if target exists.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>POST</td>
|
|
<td><code>/create-directory</code></td>
|
|
<td>Recursive create; no-op if already a directory.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>POST</td>
|
|
<td><code>/rename</code></td>
|
|
<td>Body <code>{rootName, relativePath, newRelativePath}</code>; refuses cross-root moves.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>POST</td>
|
|
<td><code>/copy</code></td>
|
|
<td><code>{name}-Copy-00..-Copy-19</code>; uses <code>Hi.Common.FileLines.FileUtil.CopyDirectory</code> for directories.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>DELETE</td>
|
|
<td><code>/delete?…</code></td>
|
|
<td>Files → delete, directories → recursive; refuses to delete the root itself.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>GET</td>
|
|
<td><code>/download?…</code></td>
|
|
<td>Streams a file as <code>application/octet-stream</code>.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>GET</td>
|
|
<td><code>/download-zip?…</code></td>
|
|
<td>Zips a directory in-memory and streams <code>application/zip</code>.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>POST</td>
|
|
<td><code>/upload?…</code></td>
|
|
<td>Multipart single-file upload; overwrites target.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>POST</td>
|
|
<td><code>/extract-zip</code></td>
|
|
<td>Body <code>{rootName, relativePath}</code>; extracts next to the archive into <code><name>/</code>.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="deferred">Deferred</h2>
|
|
<ul>
|
|
<li>Path-embedded route like <code>/FileExplorer/{Root}/{*path}</code> — replaced by explicit query state for easier linking.</li>
|
|
<li><code><q-tree></code> directory-tree sidebar — <code><q-table></code> + breadcrumb + Up button covers every navigation need.</li>
|
|
<li>Drag-and-drop upload, multi-file upload, folder upload (<code>webkitdirectory</code>).</li>
|
|
<li>Syntax highlighting for <code>.nc</code> / <code>.cs</code> / <code>.csv</code>. NC needs a CM6 <code>StreamLanguage</code> G-code parser; C# needs <code>@codemirror/legacy-modes</code> wiring.</li>
|
|
<li><code>FileExplorerConfig.ExposeAbsolutePath</code> flag in <code>appsettings.json</code>. Default (absolute paths never leave the server) is identical to what the flag's default would be, so adding later doesn't change observable behaviour.</li>
|
|
</ul>
|
|
<h2 id="related-pages">Related Pages</h2>
|
|
<ul>
|
|
<li><a href="../widget/object-management-menu-button.html">Object Management Menu Button</a> — shares the XML editor dialog pattern and targets the same project / resource folders through a different endpoint family.</li>
|
|
<li><a href="../mech/mech-builder-page.html">Mechanism Builder Page</a> — future integration target for Mechanism Builder's Load / Save As dialogs.</li>
|
|
</ul>
|
|
|
|
</article>
|
|
|
|
<div class="contribution d-print-none">
|
|
</div>
|
|
|
|
<div class="next-article d-print-none border-top" id="nextArticle"></div>
|
|
|
|
</div>
|
|
|
|
<div class="affix">
|
|
<nav id="affix"></nav>
|
|
</div>
|
|
</main>
|
|
|
|
<div class="container-xxl search-results" id="search-results"></div>
|
|
|
|
<footer class="border-top text-secondary">
|
|
<div class="container-xxl">
|
|
<div class="flex-fill">
|
|
<span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|