update web dataset file

pull/524/head
wangyuzhan 2025-11-21 12:33:04 +08:00
parent 249d1c08fe
commit 8845d9170c
2 changed files with 18 additions and 6 deletions

View File

@ -99,7 +99,11 @@ function confirmFileSelection() {
}
function navigateToParent() {
if (currentBrowsePath !== './') {
if (window.currentParentPath) {
// 使用后端提供的父目录路径(绝对路径)
browsePath(window.currentParentPath);
} else if (currentBrowsePath && currentBrowsePath !== './') {
// 回退到基于当前路径的计算
const parentPath = currentBrowsePath.includes('/') ?
currentBrowsePath.substring(0, currentBrowsePath.lastIndexOf('/')) : './';
browsePath(parentPath || './');
@ -141,7 +145,6 @@ async function browsePath(path) {
try {
currentBrowsePath = path;
selectedFilePath = null; // 重置选中的文件路径
document.getElementById('current-path').textContent = path;
document.getElementById('selected-path').value = ''; // 清空显示
// 更新帮助文本
@ -172,6 +175,12 @@ function renderFileList(data) {
return;
}
// 更新当前路径显示(使用相对路径用于显示)
document.getElementById('current-path').textContent = data.relative_path || data.current_path;
// 存储父目录路径供导航使用
window.currentParentPath = data.parent;
// 先显示目录,再显示文件
const directories = data.items.filter(item => item.type === 'directory');
const files = data.items.filter(item => item.type === 'file');

View File

@ -371,7 +371,8 @@ def browse_files():
stat = os.stat(item_path)
items.append({
'name': item,
'path': os.path.relpath(item_path, project_root),
'path': item_path, # 返回绝对路径
'relative_path': os.path.relpath(item_path, project_root), # 同时返回相对路径用于显示
'type': 'directory' if os.path.isdir(item_path) else 'file',
'size': stat.st_size if os.path.isfile(item_path) else 0,
'modified': time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stat.st_mtime))
@ -381,10 +382,11 @@ def browse_files():
continue
return jsonify({
'current_path': os.path.relpath(full_path, project_root),
'current_path': full_path, # 返回绝对路径
'relative_path': os.path.relpath(full_path, project_root), # 相对路径用于显示
'absolute_path': full_path,
'items': items,
'parent': os.path.relpath(os.path.dirname(full_path), project_root) if full_path != project_root else None
'parent': os.path.dirname(full_path) if full_path != project_root else None
})
except (OSError, PermissionError) as e:
return jsonify({'error': f'无法访问目录: {str(e)}', 'path': path})
@ -394,7 +396,8 @@ def browse_files():
stat = os.stat(full_path)
return jsonify({
'name': os.path.basename(full_path),
'path': os.path.relpath(full_path, project_root),
'path': full_path, # 返回绝对路径
'relative_path': os.path.relpath(full_path, project_root), # 相对路径用于显示
'type': 'file',
'size': stat.st_size,
'modified': time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stat.st_mtime))