test d盘能否访问

This commit is contained in:
root
2025-07-11 18:24:10 +08:00
parent 7fa995501a
commit 18e0f49b0c
4 changed files with 509 additions and 1 deletions

View File

@@ -0,0 +1,269 @@
# Asset Protocol 访问问题诊断
## 🔍 问题分析
### 现象
-**桌面资源可以访问**: `C:\Users\imeep\Desktop\**`
-**mixvideo资源无法访问**: `C:\Users\imeep\.mixvideo\**`
### 可能原因
#### 1. **AssetProtocol Scope 配置问题**
当前配置:
```json
{
"scope": [
"$HOME/**",
"$DESKTOP/**",
"$DOCUMENT/**",
"$DOWNLOAD/**",
"$APPDATA/**",
"$LOCALAPPDATA/**",
"C:\\Users\\**",
"C:\\**"
]
}
```
#### 2. **Windows 环境变量解析问题**
- `$HOME` 在 Windows 上可能不指向 `C:\Users\imeep`
- `$APPDATA` 可能不包含 `.mixvideo` 目录
#### 3. **隐藏文件夹权限问题**
- `.mixvideo` 是隐藏文件夹,可能有特殊权限限制
## 🔧 解决方案
### 方案1: 添加具体路径 (推荐)
```json
{
"assetProtocol": {
"enable": true,
"scope": [
"$HOME/**",
"$DESKTOP/**",
"$DOCUMENT/**",
"$DOWNLOAD/**",
"$APPDATA/**",
"$LOCALAPPDATA/**",
"C:\\Users\\imeep\\**",
"C:\\Users\\imeep\\.mixvideo\\**",
"C:\\**"
]
}
}
```
### 方案2: 使用通配符路径
```json
{
"assetProtocol": {
"enable": true,
"scope": [
"C:\\Users\\*\\**",
"C:\\Users\\*\\.mixvideo\\**",
"**"
]
}
}
```
### 方案3: 临时使用全局访问 (仅调试)
```json
{
"assetProtocol": {
"enable": true,
"scope": ["**"]
}
}
```
## 🧪 测试步骤
### 1. 在浏览器控制台测试
```javascript
// 测试 convertFileSrc 转换
import { convertFileSrc } from '@tauri-apps/api/core'
// 测试桌面文件 (应该成功)
const desktopPath = 'C:\\Users\\imeep\\Desktop\\test.txt'
const desktopUrl = convertFileSrc(desktopPath)
console.log('Desktop URL:', desktopUrl)
// 测试 mixvideo 文件 (当前失败)
const mixvideoPath = 'C:\\Users\\imeep\\.mixvideo\\temp\\video_segments\\test.mp4'
const mixvideoUrl = convertFileSrc(mixvideoPath)
console.log('Mixvideo URL:', mixvideoUrl)
// 尝试访问
fetch(mixvideoUrl)
.then(response => console.log('Mixvideo access:', response.status))
.catch(error => console.error('Mixvideo error:', error))
```
### 2. 检查实际的环境变量
在 Tauri 后端添加调试命令:
```rust
#[tauri::command]
fn debug_paths() -> Result<serde_json::Value, String> {
use std::env;
let mut paths = std::collections::HashMap::new();
// 获取环境变量
if let Ok(home) = env::var("HOME") {
paths.insert("HOME", home);
}
if let Ok(userprofile) = env::var("USERPROFILE") {
paths.insert("USERPROFILE", userprofile);
}
if let Ok(appdata) = env::var("APPDATA") {
paths.insert("APPDATA", appdata);
}
if let Ok(localappdata) = env::var("LOCALAPPDATA") {
paths.insert("LOCALAPPDATA", localappdata);
}
// 检查 .mixvideo 目录
let mixvideo_path = format!("{}/.mixvideo", env::var("USERPROFILE").unwrap_or_default());
paths.insert("MIXVIDEO_PATH", mixvideo_path.clone());
paths.insert("MIXVIDEO_EXISTS", std::path::Path::new(&mixvideo_path).exists().to_string());
Ok(serde_json::to_value(paths).unwrap())
}
```
### 3. 文件权限检查
```javascript
// 检查文件是否存在
import { invoke } from '@tauri-apps/api/core'
const checkFile = async (path) => {
try {
const exists = await invoke('check_file_exists', { filePath: path })
console.log(`File exists (${path}):`, exists)
return exists
} catch (error) {
console.error(`Check file error (${path}):`, error)
return false
}
}
// 测试不同路径
checkFile('C:\\Users\\imeep\\Desktop\\test.txt')
checkFile('C:\\Users\\imeep\\.mixvideo\\temp\\video_segments\\test.mp4')
```
## 🔧 立即修复
### 修改 tauri.conf.json
```json
{
"app": {
"security": {
"assetProtocol": {
"enable": true,
"scope": [
"$HOME/**",
"$DESKTOP/**",
"$DOCUMENT/**",
"$DOWNLOAD/**",
"$APPDATA/**",
"$LOCALAPPDATA/**",
"C:\\Users\\imeep\\**",
"C:\\Users\\imeep\\.mixvideo\\**",
"C:\\**"
]
}
}
}
}
```
### 重启应用
```bash
# 重启 Tauri 开发服务器以应用配置更改
pnpm tauri dev
```
## 🔍 调试技巧
### 1. 查看 Tauri 日志
在开发者工具的 Console 中查看详细错误信息:
```javascript
// 启用详细日志
window.__TAURI__.logger.setLevel('debug')
```
### 2. 检查网络请求
在开发者工具的 Network 标签中:
- 查看 asset:// 协议的请求
- 检查返回的状态码
- 查看错误信息
### 3. 比较成功和失败的URL
```javascript
// 成功的桌面文件
const successUrl = convertFileSrc('C:\\Users\\imeep\\Desktop\\test.txt')
console.log('Success URL:', successUrl)
// 失败的 mixvideo 文件
const failUrl = convertFileSrc('C:\\Users\\imeep\\.mixvideo\\test.mp4')
console.log('Fail URL:', failUrl)
// 比较 URL 格式差异
```
## 🚨 常见错误和解决方案
### 错误1: "Asset protocol access denied"
**原因**: 文件路径不在 scope 范围内
**解决**: 添加具体路径到 scope 配置
### 错误2: "File not found"
**原因**: 文件确实不存在或路径错误
**解决**: 检查文件路径和文件是否存在
### 错误3: "Permission denied"
**原因**: 文件权限问题
**解决**: 检查文件权限,可能需要管理员权限
### 错误4: 环境变量解析失败
**原因**: Windows 环境变量在 Tauri 中解析不正确
**解决**: 使用绝对路径而不是环境变量
## 📋 检查清单
- [ ] 确认 assetProtocol.enable 为 true
- [ ] 检查 scope 配置包含目标路径
- [ ] 重启 Tauri 应用以应用配置更改
- [ ] 确认文件确实存在
- [ ] 检查文件权限
- [ ] 测试 convertFileSrc 转换结果
- [ ] 查看浏览器控制台错误信息
- [ ] 检查网络请求状态
## 🎯 预期结果
修复后应该能够:
- ✅ 访问 `C:\Users\imeep\.mixvideo\**` 下的所有文件
- ✅ 正常播放 mixvideo 目录中的视频文件
- ✅ 加载 mixvideo 目录中的图片资源
- ✅ 在控制台看到成功的网络请求
---
*按照以上步骤应该能够解决 asset protocol 访问问题*

View File

@@ -0,0 +1,237 @@
<!DOCTYPE html>
<html>
<head>
<title>Asset Protocol Access Test</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.test-item { margin: 10px 0; padding: 10px; border: 1px solid #ccc; }
.success { background-color: #d4edda; border-color: #c3e6cb; }
.error { background-color: #f8d7da; border-color: #f5c6cb; }
.pending { background-color: #fff3cd; border-color: #ffeaa7; }
button { margin: 5px; padding: 5px 10px; }
img, video { max-width: 200px; max-height: 150px; margin: 5px; }
.log { background: #f8f9fa; padding: 10px; margin: 10px 0; font-family: monospace; }
</style>
</head>
<body>
<h1>Tauri Asset Protocol 访问测试</h1>
<div>
<h2>测试路径</h2>
<div>
<label>测试路径: </label>
<input type="text" id="testPath" value="C:\Users\imeep\.mixvideo\temp\video_segments" style="width: 400px;">
<button onclick="testPath()">测试路径</button>
</div>
<div>
<label>测试文件: </label>
<input type="text" id="testFile" value="C:\Users\imeep\.mixvideo\temp\video_segments\test.mp4" style="width: 400px;">
<button onclick="testFile()">测试文件</button>
</div>
</div>
<div>
<h2>预设测试</h2>
<button onclick="testCommonPaths()">测试常用路径</button>
<button onclick="testMixvideoPath()">测试 .mixvideo 路径</button>
<button onclick="clearResults()">清除结果</button>
</div>
<div id="results"></div>
<div>
<h2>调试日志</h2>
<div id="log" class="log"></div>
</div>
<script>
function log(message) {
const logDiv = document.getElementById('log');
const timestamp = new Date().toLocaleTimeString();
logDiv.innerHTML += `[${timestamp}] ${message}\n`;
logDiv.scrollTop = logDiv.scrollHeight;
console.log(message);
}
function addResult(path, status, message, element = null) {
const resultsDiv = document.getElementById('results');
const div = document.createElement('div');
div.className = `test-item ${status}`;
let content = `<strong>路径:</strong> ${path}<br><strong>状态:</strong> ${message}`;
if (element) {
content += '<br>';
div.appendChild(document.createTextNode(''));
div.innerHTML = content;
div.appendChild(element);
} else {
div.innerHTML = content;
}
resultsDiv.appendChild(div);
}
async function testAssetUrl(path, type = 'fetch') {
try {
// 使用 Tauri 的 convertFileSrc
const { convertFileSrc } = window.__TAURI__.core;
const assetUrl = convertFileSrc(path);
log(`Testing: ${path} -> ${assetUrl}`);
if (type === 'image') {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => {
log(`✅ Image loaded: ${path}`);
resolve({ success: true, element: img, url: assetUrl });
};
img.onerror = (e) => {
log(`❌ Image failed: ${path} - ${e}`);
reject(new Error('Image load failed'));
};
img.src = assetUrl;
});
} else if (type === 'video') {
return new Promise((resolve, reject) => {
const video = document.createElement('video');
video.controls = true;
video.onloadedmetadata = () => {
log(`✅ Video loaded: ${path} (${video.duration}s)`);
resolve({ success: true, element: video, url: assetUrl });
};
video.onerror = (e) => {
log(`❌ Video failed: ${path} - ${e}`);
reject(new Error('Video load failed'));
};
video.src = assetUrl;
});
} else {
// Fetch test
const response = await fetch(assetUrl);
if (response.ok) {
const size = response.headers.get('content-length');
log(`✅ Fetch success: ${path} (${size} bytes)`);
return { success: true, url: assetUrl, size };
} else {
throw new Error(`HTTP ${response.status}`);
}
}
} catch (error) {
log(`❌ Test failed: ${path} - ${error.message}`);
throw error;
}
}
async function testPath() {
const path = document.getElementById('testPath').value;
if (!path) return;
try {
const result = await testAssetUrl(path, 'fetch');
addResult(path, 'success', `访问成功 (${result.size} bytes)`);
} catch (error) {
addResult(path, 'error', `访问失败: ${error.message}`);
}
}
async function testFile() {
const path = document.getElementById('testFile').value;
if (!path) return;
const ext = path.toLowerCase().split('.').pop();
let type = 'fetch';
if (['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'].includes(ext)) {
type = 'image';
} else if (['mp4', 'avi', 'mov', 'mkv', 'webm'].includes(ext)) {
type = 'video';
}
try {
const result = await testAssetUrl(path, type);
addResult(path, 'success', `${type} 加载成功`, result.element);
} catch (error) {
addResult(path, 'error', `${type} 加载失败: ${error.message}`);
}
}
async function testCommonPaths() {
const paths = [
'C:\\Users\\imeep\\Desktop',
'C:\\Users\\imeep\\Documents',
'C:\\Users\\imeep\\Downloads',
'C:\\Users\\imeep\\.mixvideo',
'C:\\Users\\imeep\\.mixvideo\\temp',
'C:\\Users\\imeep\\.mixvideo\\temp\\video_segments'
];
for (const path of paths) {
try {
addResult(path, 'pending', '测试中...');
await testAssetUrl(path, 'fetch');
// 更新结果
const items = document.querySelectorAll('.test-item');
const lastItem = items[items.length - 1];
lastItem.className = 'test-item success';
lastItem.innerHTML = `<strong>路径:</strong> ${path}<br><strong>状态:</strong> 访问成功`;
} catch (error) {
const items = document.querySelectorAll('.test-item');
const lastItem = items[items.length - 1];
lastItem.className = 'test-item error';
lastItem.innerHTML = `<strong>路径:</strong> ${path}<br><strong>状态:</strong> 访问失败: ${error.message}`;
}
}
}
async function testMixvideoPath() {
const basePath = 'C:\\Users\\imeep\\.mixvideo';
const subPaths = [
'',
'\\temp',
'\\temp\\cache',
'\\temp\\video_segments',
'\\temp\\original_videos',
'\\temp\\thumbnails'
];
for (const subPath of subPaths) {
const fullPath = basePath + subPath;
try {
addResult(fullPath, 'pending', '测试中...');
await testAssetUrl(fullPath, 'fetch');
// 更新结果
const items = document.querySelectorAll('.test-item');
const lastItem = items[items.length - 1];
lastItem.className = 'test-item success';
lastItem.innerHTML = `<strong>路径:</strong> ${fullPath}<br><strong>状态:</strong> 访问成功`;
} catch (error) {
const items = document.querySelectorAll('.test-item');
const lastItem = items[items.length - 1];
lastItem.className = 'test-item error';
lastItem.innerHTML = `<strong>路径:</strong> ${fullPath}<br><strong>状态:</strong> 访问失败: ${error.message}`;
}
}
}
function clearResults() {
document.getElementById('results').innerHTML = '';
document.getElementById('log').innerHTML = '';
}
// 页面加载时的初始化
window.addEventListener('DOMContentLoaded', () => {
log('Asset Protocol 测试工具已加载');
log('当前 User Agent: ' + navigator.userAgent);
// 检查 Tauri API 是否可用
if (window.__TAURI__) {
log('✅ Tauri API 可用');
} else {
log('❌ Tauri API 不可用 - 请在 Tauri 应用中运行此测试');
}
});
</script>
</body>
</html>

View File

@@ -35,6 +35,8 @@
"$DOWNLOAD/**", "$DOWNLOAD/**",
"$APPDATA/**", "$APPDATA/**",
"$LOCALAPPDATA/**", "$LOCALAPPDATA/**",
"C:\\Users\\imeep\\**",
"C:\\Users\\imeep\\.mixvideo\\**",
"C:\\Users\\**", "C:\\Users\\**",
"C:\\**", "C:\\**",
"/Users/**", "/Users/**",

View File

@@ -9,7 +9,7 @@ const HomePage: React.FC = () => {
return ( return (
<div className="p-6 space-y-8"> <div className="p-6 space-y-8">
<VideoPlayer2 src={`C:\\Users\\imeep\\Desktop\\mertial\\AI视频\\0630-交付素材2\\背景1\\1751264202864.mp4`}/> <VideoPlayer2 src={`"D:\\1751275800969.mp4"`}/>
{/* Welcome Section */} {/* Welcome Section */}
<WelcomeSection /> <WelcomeSection />