mirror of
https://github.com/stablyai/orca.git
synced 2026-11-05 19:47:27 +00:00
* Preview HTML files by default across file-opening flows * Centralize workspace file opening and HTML preview routing - Preserve source, diff, and host-safety behavior across all entry points - Reuse previews within the requested editor group and support branch HTML files * Respect working tree state when opening HTML previews * Route HTML links through owning workspaces and editors * Preserve HTML preview state and refresh changed local files * Resolve HTML preview hosts from workspace ownership * Update file-opening tests for HTML preview routing
23 lines
688 B
TypeScript
23 lines
688 B
TypeScript
import { fileUriToFilesystemPath } from './file-uri-path'
|
|
|
|
export function isHtmlFilePath(filePath: string): boolean {
|
|
return /\.html?$/i.test(filePath)
|
|
}
|
|
|
|
/** File authorities name this machine, never an Orca SSH target. */
|
|
export function htmlFilePathFromUrl(input: string): string | null {
|
|
if (!/^file:\/\//i.test(input) || /[?#\p{Cc}]|%2f|%5c/iu.test(input)) {
|
|
return null
|
|
}
|
|
try {
|
|
const url = new URL(input)
|
|
if (url.hostname || url.pathname.startsWith('//')) {
|
|
return null
|
|
}
|
|
const filePath = fileUriToFilesystemPath(url)
|
|
return filePath && isHtmlFilePath(filePath) && !/\p{Cc}/u.test(filePath) ? filePath : null
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|