fix(workspace): normalize backslash paths in artifact open flow

openArtifactPath/_workspacePathExists split on '/' but Windows artifact
paths use backslashes (D:\workspace\dir\file), so prefix-strip failed
and /api/list existence check never matched -> 'cannot open file'.
Normalize both rel and workspace to '/' before stripping.
This commit is contained in:
fatbee0808 committed 2026-08-05 11:06:12 +08:00
1 parent 320789ae59
commit 71ee457d7d
1 file changed
+6 -3
+6 -3
View File
@@ -611,7 +611,7 @@ function renderSessionArtifacts(){
async function _workspacePathExists(path){
if(!S.session||!path) return false;
const parts=String(path).split('/').filter(Boolean);
const parts=String(path).replace(/\\/g,'/').split('/').filter(Boolean);
const name=parts.pop();
if(!name) return false;
const dir=parts.length?parts.join('/'):'.';
@@ -622,9 +622,12 @@ async function _workspacePathExists(path){
async function openArtifactPath(path){
if(!path) return;
switchWorkspacePanelTab('files');
let rel = path.replace(/^~\//,'').replace(/^\.\/+/,'');
// Normalize backslash separators to '/' first — Windows absolute paths
// (e.g. "D:\workspace\dir\file") otherwise break prefix-strip and the
// /api/list existence check (which splits on '/').
let rel = String(path).replace(/\\/g,'/').replace(/^~\//,'').replace(/^(?:\.\/)+/,'');
// Strip workspace prefix so /api/list receives a workspace-relative path.
const ws = S.session && S.session.workspace;
const ws = (S.session && S.session.workspace || '').replace(/\\/g,'/');
if(ws){
const normWs = ws.replace(/\/+$/,'') + '/';
if(rel.startsWith(normWs)) rel = rel.slice(normWs.length);