'CaPaCaptain', // 从截图中的仓库访问看到 'repo' => 'VvvebJs_huggingface_db_01', // 从截图中看到 'branch' => 'main', 'path' => 'pages/', 'token' => $_ENV['GITHUB_TOKEN'] ?? getenv('GITHUB_TOKEN') ?: '' ]; function testGitHubAPI($url, $token, $method = 'GET', $data = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: token ' . $token, 'User-Agent: VvvebJs-TokenTest/1.0', 'Accept: application/vnd.github.v3+json', 'Content-Type: application/json' ]); if ($data) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); } $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); return [ 'success' => $httpCode >= 200 && $httpCode < 300, 'code' => $httpCode, 'response' => $response, 'error' => $error ]; } $results = []; if ($_POST['test'] ?? false) { // 测试 1: Token 有效性 $results['token'] = testGitHubAPI('https://api.github.com/user', $config['token']); // 测试 2: 仓库访问 $repoUrl = "https://api.github.com/repos/{$config['owner']}/{$config['repo']}"; $results['repo'] = testGitHubAPI($repoUrl, $config['token']); // 测试 3: 分支检查 $branchUrl = "https://api.github.com/repos/{$config['owner']}/{$config['repo']}/branches/{$config['branch']}"; $results['branch'] = testGitHubAPI($branchUrl, $config['token']); // 测试 4: 写入权限测试 $testFile = 'token-test-' . date('Y-m-d-H-i-s') . '.html'; $testContent = '
创建时间: ' . date('Y-m-d H:i:s') . '
'; $createUrl = "https://api.github.com/repos/{$config['owner']}/{$config['repo']}/contents/{$config['path']}{$testFile}"; $results['write'] = testGitHubAPI($createUrl, $config['token'], 'PUT', [ 'message' => 'VvvebJs Token 测试文件', 'content' => base64_encode($testContent), 'branch' => $config['branch'] ]); } ?>GitHub Owner: = htmlspecialchars($config['owner']) ?>
Repository: = htmlspecialchars($config['repo']) ?>
Token 状态: = !empty($config['token']) ? '✅ 已配置' : '❌ 未找到' ?>
Branch: = htmlspecialchars($config['branch']) ?>
Path: = htmlspecialchars($config['path']) ?>
完整 URL:https://github.com/= htmlspecialchars($config['owner']) ?>/= htmlspecialchars($config['repo']) ?>
= htmlspecialchars($test['response']) ?>
在您的 Hugging Face Space Settings 中设置以下环境变量:
GITHUB_TOKEN=your_token_hereGITHUB_OWNER== htmlspecialchars($config['owner']) ?>GITHUB_REPO== htmlspecialchars($config['repo']) ?>GITHUB_BRANCH== $results['branch']['success'] ? $config['branch'] : 'master' ?>GITHUB_PATH== htmlspecialchars($config['path']) ?>STORAGE_TYPE=github请在环境变量中设置 GITHUB_TOKEN。
Token 应该是您在 GitHub 截图中创建的那个。