From 0036200d1f25d6cdf4592f39e3e6bb351c5ae144 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 11 Jul 2025 18:25:03 +0800 Subject: [PATCH] fix: scope ** --- src-tauri/tauri.conf.json | 13 +- src/components/AssetAccessTest.tsx | 210 +++++++++++++++++++++++++++++ 2 files changed, 211 insertions(+), 12 deletions(-) create mode 100644 src/components/AssetAccessTest.tsx diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5b65cd6..471d311 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -29,18 +29,7 @@ "assetProtocol": { "enable": true, "scope": [ - "$HOME/**", - "$DESKTOP/**", - "$DOCUMENT/**", - "$DOWNLOAD/**", - "$APPDATA/**", - "$LOCALAPPDATA/**", - "C:\\Users\\imeep\\**", - "C:\\Users\\imeep\\.mixvideo\\**", - "C:\\Users\\**", - "C:\\**", - "/Users/**", - "/home/**" + "**" ] }, "freezePrototype": true diff --git a/src/components/AssetAccessTest.tsx b/src/components/AssetAccessTest.tsx new file mode 100644 index 0000000..e8c25ab --- /dev/null +++ b/src/components/AssetAccessTest.tsx @@ -0,0 +1,210 @@ +import React, { useState } from 'react' +import { convertFileSrc, invoke } from '@tauri-apps/api/core' +import { CheckCircle, XCircle, AlertCircle } from 'lucide-react' + +interface TestResult { + path: string + status: 'success' | 'error' | 'pending' + message: string + url?: string +} + +const AssetAccessTest: React.FC = () => { + const [results, setResults] = useState([]) + const [customPath, setCustomPath] = useState('C:\\Users\\imeep\\.mixvideo\\temp\\video_segments') + + const addResult = (result: TestResult) => { + setResults(prev => [...prev, result]) + } + + const updateLastResult = (updates: Partial) => { + setResults(prev => { + const newResults = [...prev] + const lastIndex = newResults.length - 1 + if (lastIndex >= 0) { + newResults[lastIndex] = { ...newResults[lastIndex], ...updates } + } + return newResults + }) + } + + const testPath = async (path: string) => { + addResult({ path, status: 'pending', message: '测试中...' }) + + try { + // 1. 检查文件是否存在 + const exists = await invoke('check_file_exists', { filePath: path }) + if (!exists) { + updateLastResult({ + status: 'error', + message: '文件不存在' + }) + return + } + + // 2. 转换为 asset URL + const assetUrl = convertFileSrc(path) + console.log(`Converting ${path} -> ${assetUrl}`) + + // 3. 尝试访问 + const response = await fetch(assetUrl) + if (response.ok) { + const contentLength = response.headers.get('content-length') + updateLastResult({ + status: 'success', + message: `访问成功 (${contentLength} bytes)`, + url: assetUrl + }) + } else { + updateLastResult({ + status: 'error', + message: `HTTP ${response.status}: ${response.statusText}`, + url: assetUrl + }) + } + } catch (error) { + updateLastResult({ + status: 'error', + message: `访问失败: ${error}` + }) + } + } + + const testCommonPaths = async () => { + const paths = [ + 'C:\\Users\\imeep\\Desktop', + 'C:\\Users\\imeep\\Documents', + 'C:\\Users\\imeep\\.mixvideo', + 'C:\\Users\\imeep\\.mixvideo\\temp', + 'C:\\Users\\imeep\\.mixvideo\\temp\\video_segments', + 'C:\\Users\\imeep\\.mixvideo\\temp\\original_videos', + 'C:\\Users\\imeep\\.mixvideo\\temp\\cache' + ] + + for (const path of paths) { + await testPath(path) + // 添加小延迟避免请求过快 + await new Promise(resolve => setTimeout(resolve, 100)) + } + } + + const clearResults = () => { + setResults([]) + } + + const getStatusIcon = (status: TestResult['status']) => { + switch (status) { + case 'success': + return + case 'error': + return + case 'pending': + return + } + } + + const getStatusColor = (status: TestResult['status']) => { + switch (status) { + case 'success': + return 'bg-green-50 border-green-200' + case 'error': + return 'bg-red-50 border-red-200' + case 'pending': + return 'bg-yellow-50 border-yellow-200' + } + } + + return ( +
+

Asset Protocol 访问测试

+ + {/* 控制面板 */} +
+
+
+ +
+ setCustomPath(e.target.value)} + className="flex-1 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" + placeholder="输入要测试的路径" + /> + +
+
+ +
+ + +
+
+
+ + {/* 测试结果 */} +
+

测试结果

+ {results.length === 0 ? ( +
+ 暂无测试结果,点击上方按钮开始测试 +
+ ) : ( + results.map((result, index) => ( +
+
+ {getStatusIcon(result.status)} +
+
+ {result.path} +
+
+ {result.message} +
+ {result.url && ( +
+ Asset URL: {result.url} +
+ )} +
+
+
+ )) + )} +
+ + {/* 说明信息 */} +
+

说明

+
    +
  • • 此工具用于测试 Tauri AssetProtocol 的文件访问权限
  • +
  • • 绿色表示可以正常访问,红色表示访问被拒绝
  • +
  • • 如果 .mixvideo 路径访问失败,请检查 tauri.conf.json 中的 scope 配置
  • +
  • • 修改配置后需要重启应用才能生效
  • +
+
+
+ ) +} + +export default AssetAccessTest