Upload 5 files
Browse files- config-check.php +19 -7
- fix-config.html +196 -0
- hf-space-check.php +331 -0
- storage.php +60 -17
config-check.php
CHANGED
|
@@ -24,13 +24,25 @@ function checkConfig() {
|
|
| 24 |
$github = StorageConfig::getGitHubConfig();
|
| 25 |
$issues = [];
|
| 26 |
|
| 27 |
-
//
|
| 28 |
-
if (
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
|
| 36 |
// 检查GitHub基本配置
|
|
|
|
| 24 |
$github = StorageConfig::getGitHubConfig();
|
| 25 |
$issues = [];
|
| 26 |
|
| 27 |
+
// 检查是否在Hugging Face Space环境
|
| 28 |
+
if (StorageConfig::isHuggingFaceSpace()) {
|
| 29 |
+
// 在Hugging Face Space环境中,重点检查环境变量
|
| 30 |
+
if (empty($github['token'])) {
|
| 31 |
+
$issues[] = [
|
| 32 |
+
'type' => 'error',
|
| 33 |
+
'title' => 'GitHub Token 未在Hugging Face Space中配置',
|
| 34 |
+
'message' => 'GITHUB_TOKEN 环境变量为空,请在Hugging Face Space的Settings中添加此私有密钥'
|
| 35 |
+
];
|
| 36 |
+
}
|
| 37 |
+
} else {
|
| 38 |
+
// 在本地环境中,检查.env文件配置
|
| 39 |
+
if (empty($github['token']) || $github['token'] === 'YOUR_ACTUAL_GITHUB_TOKEN') {
|
| 40 |
+
$issues[] = [
|
| 41 |
+
'type' => 'error',
|
| 42 |
+
'title' => 'GitHub Token 未配置',
|
| 43 |
+
'message' => 'GITHUB_TOKEN 仍然是占位符或为空,需要设置真实的GitHub Token'
|
| 44 |
+
];
|
| 45 |
+
}
|
| 46 |
}
|
| 47 |
|
| 48 |
// 检查GitHub基本配置
|
fix-config.html
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>VvvebJs 快速配置修复</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
+
<style>
|
| 9 |
+
.config-value { background-color: #f8f9fa; padding: 2px 6px; border-radius: 3px; font-family: monospace; }
|
| 10 |
+
.status-ok { color: #28a745; }
|
| 11 |
+
.status-error { color: #dc3545; }
|
| 12 |
+
.status-warning { color: #ffc107; }
|
| 13 |
+
.copy-button { margin-left: 10px; }
|
| 14 |
+
</style>
|
| 15 |
+
</head>
|
| 16 |
+
<body>
|
| 17 |
+
<div class="container mt-5">
|
| 18 |
+
<div class="row">
|
| 19 |
+
<div class="col-md-10 mx-auto">
|
| 20 |
+
<h1 class="mb-4">🚨 VvvebJs 紧急配置修复</h1>
|
| 21 |
+
|
| 22 |
+
<div class="alert alert-danger">
|
| 23 |
+
<h4>❌ 发现严重配置问题</h4>
|
| 24 |
+
<p>你的 GitHub Token 仍然是占位符,需要立即修复才能正常保存文件。</p>
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
<!-- 步骤指导 -->
|
| 28 |
+
<div class="card mb-4">
|
| 29 |
+
<div class="card-header">
|
| 30 |
+
<h3>🔧 修复步骤</h3>
|
| 31 |
+
</div>
|
| 32 |
+
<div class="card-body">
|
| 33 |
+
<div class="row">
|
| 34 |
+
<div class="col-md-6">
|
| 35 |
+
<h5>步骤 1: 获取 GitHub Token</h5>
|
| 36 |
+
<ol>
|
| 37 |
+
<li>点击下面的链接访问 GitHub:<br>
|
| 38 |
+
<a href="https://github.com/settings/tokens" target="_blank" class="btn btn-primary mt-2">
|
| 39 |
+
🔑 打开 GitHub Token 设置
|
| 40 |
+
</a>
|
| 41 |
+
</li>
|
| 42 |
+
<li class="mt-3">点击 "Generate new token (classic)"</li>
|
| 43 |
+
<li>设置名称为:<code>VvvebJs WebBuilder</code></li>
|
| 44 |
+
<li><strong>重要:勾选 "repo" 权限</strong>(完整仓库访问)</li>
|
| 45 |
+
<li>点击 "Generate token"</li>
|
| 46 |
+
<li>复制生成的Token(以 <code>ghp_</code> 开头)</li>
|
| 47 |
+
</ol>
|
| 48 |
+
</div>
|
| 49 |
+
<div class="col-md-6">
|
| 50 |
+
<h5>步骤 2: 更新 .env 文件</h5>
|
| 51 |
+
<p>找到你的 <code>.env</code> 文件,将这一行:</p>
|
| 52 |
+
<div class="bg-light p-3 rounded">
|
| 53 |
+
<code class="text-danger">GITHUB_TOKEN=YOUR_ACTUAL_GITHUB_TOKEN</code>
|
| 54 |
+
</div>
|
| 55 |
+
<p class="mt-2">替换为:</p>
|
| 56 |
+
<div class="bg-light p-3 rounded">
|
| 57 |
+
<code class="text-success">GITHUB_TOKEN=ghp_你的真实Token</code>
|
| 58 |
+
</div>
|
| 59 |
+
<div class="mt-3">
|
| 60 |
+
<h6>示例:</h6>
|
| 61 |
+
<div class="bg-light p-3 rounded">
|
| 62 |
+
<code>GITHUB_TOKEN=ghp_1234567890abcdef1234567890abcdef12345678</code>
|
| 63 |
+
<button class="btn btn-sm btn-outline-secondary copy-button" onclick="copyExample()">复制格式</button>
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</div>
|
| 69 |
+
</div>
|
| 70 |
+
|
| 71 |
+
<!-- 当前配置状态 -->
|
| 72 |
+
<div class="card mb-4">
|
| 73 |
+
<div class="card-header">
|
| 74 |
+
<h3>📋 当前配置状态</h3>
|
| 75 |
+
</div>
|
| 76 |
+
<div class="card-body">
|
| 77 |
+
<div class="row">
|
| 78 |
+
<div class="col-md-6">
|
| 79 |
+
<p><strong>GitHub Token:</strong>
|
| 80 |
+
<span class="config-value status-error">❌ 占位符 (YOUR_ACTUAL_GITHUB_TOKEN)</span>
|
| 81 |
+
</p>
|
| 82 |
+
<p><strong>GitHub Owner:</strong>
|
| 83 |
+
<span class="config-value">CaPaCaptain</span>
|
| 84 |
+
</p>
|
| 85 |
+
<p><strong>GitHub Repo:</strong>
|
| 86 |
+
<span class="config-value">VvvebJs_huggingface_db_01</span>
|
| 87 |
+
</p>
|
| 88 |
+
</div>
|
| 89 |
+
<div class="col-md-6">
|
| 90 |
+
<p><strong>GitHub Branch:</strong>
|
| 91 |
+
<span class="config-value">main</span>
|
| 92 |
+
</p>
|
| 93 |
+
<p><strong>GitHub Path:</strong>
|
| 94 |
+
<span class="config-value">pages/</span>
|
| 95 |
+
</p>
|
| 96 |
+
<p><strong>存储类型:</strong>
|
| 97 |
+
<span class="config-value">github</span>
|
| 98 |
+
</p>
|
| 99 |
+
</div>
|
| 100 |
+
</div>
|
| 101 |
+
</div>
|
| 102 |
+
</div>
|
| 103 |
+
|
| 104 |
+
<!-- 检查工具 -->
|
| 105 |
+
<div class="card mb-4">
|
| 106 |
+
<div class="card-header">
|
| 107 |
+
<h3>🧪 修复后测试</h3>
|
| 108 |
+
</div>
|
| 109 |
+
<div class="card-body">
|
| 110 |
+
<p>修复Token后,使用以下工具验证配置:</p>
|
| 111 |
+
<div class="row">
|
| 112 |
+
<div class="col-md-4">
|
| 113 |
+
<a href="config-check.php" class="btn btn-info w-100">配置检查</a>
|
| 114 |
+
</div>
|
| 115 |
+
<div class="col-md-4">
|
| 116 |
+
<a href="github-advanced-test.php" class="btn btn-primary w-100">完整测试</a>
|
| 117 |
+
</div>
|
| 118 |
+
<div class="col-md-4">
|
| 119 |
+
<a href="editor.html" class="btn btn-success w-100">返回编辑器</a>
|
| 120 |
+
</div>
|
| 121 |
+
</div>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
|
| 125 |
+
<!-- 常见问题 -->
|
| 126 |
+
<div class="card">
|
| 127 |
+
<div class="card-header">
|
| 128 |
+
<h3>❓ 常见问题</h3>
|
| 129 |
+
</div>
|
| 130 |
+
<div class="card-body">
|
| 131 |
+
<div class="accordion" id="faqAccordion">
|
| 132 |
+
<div class="accordion-item">
|
| 133 |
+
<h2 class="accordion-header">
|
| 134 |
+
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#faq1">
|
| 135 |
+
为什么需要 GitHub Token?
|
| 136 |
+
</button>
|
| 137 |
+
</h2>
|
| 138 |
+
<div id="faq1" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
|
| 139 |
+
<div class="accordion-body">
|
| 140 |
+
GitHub Token 是访问你的 GitHub 仓库所必需的认证凭据。没有它,VvvebJs 无法保存文件到你的 GitHub 仓库。
|
| 141 |
+
</div>
|
| 142 |
+
</div>
|
| 143 |
+
</div>
|
| 144 |
+
<div class="accordion-item">
|
| 145 |
+
<h2 class="accordion-header">
|
| 146 |
+
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#faq2">
|
| 147 |
+
Token 权限应该如何设置?
|
| 148 |
+
</button>
|
| 149 |
+
</h2>
|
| 150 |
+
<div id="faq2" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
|
| 151 |
+
<div class="accordion-body">
|
| 152 |
+
必须勾选 <strong>"repo"</strong> 权限,这包括:
|
| 153 |
+
<ul>
|
| 154 |
+
<li>repo:status - 访问提交状态</li>
|
| 155 |
+
<li>repo_deployment - 访问部署状态</li>
|
| 156 |
+
<li>public_repo - 访问公共仓库</li>
|
| 157 |
+
<li>repo:invite - 访问仓库邀请</li>
|
| 158 |
+
</ul>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
+
<div class="accordion-item">
|
| 163 |
+
<h2 class="accordion-header">
|
| 164 |
+
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#faq3">
|
| 165 |
+
如何找到 .env 文件?
|
| 166 |
+
</button>
|
| 167 |
+
</h2>
|
| 168 |
+
<div id="faq3" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
|
| 169 |
+
<div class="accordion-body">
|
| 170 |
+
<code>.env</code> 文件位于 VvvebJs 根目录下。如果看不到,请确保:
|
| 171 |
+
<ul>
|
| 172 |
+
<li>显示隐藏文件(文件名以点开头)</li>
|
| 173 |
+
<li>使用文��编辑器打开</li>
|
| 174 |
+
<li>路径:<code>f:\apps\VvvebJs-master\.env</code></li>
|
| 175 |
+
</ul>
|
| 176 |
+
</div>
|
| 177 |
+
</div>
|
| 178 |
+
</div>
|
| 179 |
+
</div>
|
| 180 |
+
</div>
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
</div>
|
| 185 |
+
|
| 186 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
| 187 |
+
<script>
|
| 188 |
+
function copyExample() {
|
| 189 |
+
const text = "GITHUB_TOKEN=ghp_";
|
| 190 |
+
navigator.clipboard.writeText(text).then(function() {
|
| 191 |
+
alert('已复制格式到剪贴板!请在后面添加你的真实Token。');
|
| 192 |
+
});
|
| 193 |
+
}
|
| 194 |
+
</script>
|
| 195 |
+
</body>
|
| 196 |
+
</html>
|
hf-space-check.php
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
require_once __DIR__ . '/storage.php';
|
| 3 |
+
|
| 4 |
+
// 简单的测试认证
|
| 5 |
+
$testAuth = false;
|
| 6 |
+
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
|
| 7 |
+
$users = StorageConfig::getUsers();
|
| 8 |
+
$testAuth = isset($users[$_SERVER['PHP_AUTH_USER']]) &&
|
| 9 |
+
$users[$_SERVER['PHP_AUTH_USER']] === $_SERVER['PHP_AUTH_PW'];
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
if (!$testAuth) {
|
| 13 |
+
header('WWW-Authenticate: Basic realm="VvvebJs HF Space Check"');
|
| 14 |
+
header('HTTP/1.0 401 Unauthorized');
|
| 15 |
+
die('Authentication required for Hugging Face Space check');
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
// 获取环境信息
|
| 19 |
+
$isHuggingFace = StorageConfig::isHuggingFaceSpace();
|
| 20 |
+
$envDebug = StorageConfig::debugEnvironment();
|
| 21 |
+
$github = StorageConfig::getGitHubConfig();
|
| 22 |
+
$kv = StorageConfig::getKVConfig();
|
| 23 |
+
$storageType = StorageConfig::getStorageType();
|
| 24 |
+
|
| 25 |
+
// 检查配置状态
|
| 26 |
+
function checkHuggingFaceConfig() {
|
| 27 |
+
$github = StorageConfig::getGitHubConfig();
|
| 28 |
+
$issues = [];
|
| 29 |
+
|
| 30 |
+
// 检查是否在Hugging Face Space环境
|
| 31 |
+
if (!StorageConfig::isHuggingFaceSpace()) {
|
| 32 |
+
$issues[] = [
|
| 33 |
+
'type' => 'warning',
|
| 34 |
+
'title' => '不在 Hugging Face Space 环境',
|
| 35 |
+
'message' => '当前似乎不在Hugging Face Space环境中运行,某些环境变量可能无法正确读取'
|
| 36 |
+
];
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// 检查GitHub Token
|
| 40 |
+
if (empty($github['token'])) {
|
| 41 |
+
$issues[] = [
|
| 42 |
+
'type' => 'error',
|
| 43 |
+
'title' => 'GitHub Token 未配置',
|
| 44 |
+
'message' => 'GITHUB_TOKEN 环境变量为空,请在Hugging Face Space设置中添加此私有变量'
|
| 45 |
+
];
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
// 检查GitHub基本配置
|
| 49 |
+
if (empty($github['owner'])) {
|
| 50 |
+
$issues[] = [
|
| 51 |
+
'type' => 'error',
|
| 52 |
+
'title' => 'GitHub Owner 未配置',
|
| 53 |
+
'message' => 'GITHUB_OWNER 环境变量为空'
|
| 54 |
+
];
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if (empty($github['repo'])) {
|
| 58 |
+
$issues[] = [
|
| 59 |
+
'type' => 'error',
|
| 60 |
+
'title' => 'GitHub Repo 未配置',
|
| 61 |
+
'message' => 'GITHUB_REPO 环境变量为空'
|
| 62 |
+
];
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
return $issues;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
$configIssues = checkHuggingFaceConfig();
|
| 69 |
+
?>
|
| 70 |
+
|
| 71 |
+
<!DOCTYPE html>
|
| 72 |
+
<html lang="en">
|
| 73 |
+
<head>
|
| 74 |
+
<meta charset="utf-8">
|
| 75 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 76 |
+
<title>VvvebJs Hugging Face Space 配置检查</title>
|
| 77 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 78 |
+
<style>
|
| 79 |
+
.config-value { background-color: #f8f9fa; padding: 2px 6px; border-radius: 3px; font-family: monospace; }
|
| 80 |
+
.status-ok { color: #28a745; }
|
| 81 |
+
.status-error { color: #dc3545; }
|
| 82 |
+
.status-warning { color: #ffc107; }
|
| 83 |
+
.env-debug { background: #f8f9fa; padding: 10px; border-radius: 5px; font-family: monospace; font-size: 12px; }
|
| 84 |
+
</style>
|
| 85 |
+
</head>
|
| 86 |
+
<body>
|
| 87 |
+
<div class="container mt-5">
|
| 88 |
+
<div class="row">
|
| 89 |
+
<div class="col-md-10 mx-auto">
|
| 90 |
+
<h1 class="mb-4">🚀 VvvebJs Hugging Face Space 配置检查</h1>
|
| 91 |
+
|
| 92 |
+
<!-- 环境检测 -->
|
| 93 |
+
<div class="card mb-4">
|
| 94 |
+
<div class="card-header">
|
| 95 |
+
<h3>🌐 运行环境检测</h3>
|
| 96 |
+
</div>
|
| 97 |
+
<div class="card-body">
|
| 98 |
+
<div class="row">
|
| 99 |
+
<div class="col-md-6">
|
| 100 |
+
<p><strong>Hugging Face Space:</strong>
|
| 101 |
+
<span class="<?= $isHuggingFace ? 'status-ok' : 'status-warning' ?>">
|
| 102 |
+
<?= $isHuggingFace ? '✅ 是' : '⚠️ 否' ?>
|
| 103 |
+
</span>
|
| 104 |
+
</p>
|
| 105 |
+
<p><strong>Space ID:</strong>
|
| 106 |
+
<span class="config-value"><?= htmlspecialchars($envDebug['space_id']) ?></span>
|
| 107 |
+
</p>
|
| 108 |
+
<p><strong>主机:</strong>
|
| 109 |
+
<span class="config-value"><?= htmlspecialchars($envDebug['host']) ?></span>
|
| 110 |
+
</p>
|
| 111 |
+
</div>
|
| 112 |
+
<div class="col-md-6">
|
| 113 |
+
<p><strong>环境变量来源:</strong> Hugging Face Space Settings</p>
|
| 114 |
+
<p><strong>检查方法:</strong> $_SERVER 和 $_ENV</p>
|
| 115 |
+
<p><strong>优先级:</strong> Space环境变量 > .env文件</p>
|
| 116 |
+
</div>
|
| 117 |
+
</div>
|
| 118 |
+
</div>
|
| 119 |
+
</div>
|
| 120 |
+
|
| 121 |
+
<!-- 配置问题检查 -->
|
| 122 |
+
<?php if (!empty($configIssues)): ?>
|
| 123 |
+
<div class="card mb-4">
|
| 124 |
+
<div class="card-header">
|
| 125 |
+
<h3 class="status-error">❌ 发现配置问题</h3>
|
| 126 |
+
</div>
|
| 127 |
+
<div class="card-body">
|
| 128 |
+
<?php foreach ($configIssues as $issue): ?>
|
| 129 |
+
<div class="alert alert-<?= $issue['type'] === 'error' ? 'danger' : 'warning' ?> mb-3">
|
| 130 |
+
<h5><?= htmlspecialchars($issue['title']) ?></h5>
|
| 131 |
+
<p><?= htmlspecialchars($issue['message']) ?></p>
|
| 132 |
+
</div>
|
| 133 |
+
<?php endforeach; ?>
|
| 134 |
+
|
| 135 |
+
<div class="alert alert-info">
|
| 136 |
+
<h5>🔧 如何在 Hugging Face Space 中配置环境变量:</h5>
|
| 137 |
+
<ol>
|
| 138 |
+
<li>访问你的 <a href="https://huggingface.co/spaces" target="_blank">Hugging Face Spaces</a></li>
|
| 139 |
+
<li>点击进入你的 Space 项目</li>
|
| 140 |
+
<li>点击 <strong>Settings</strong> 标签页</li>
|
| 141 |
+
<li>在 <strong>Variables and secrets</strong> 部分添加以下环境变量:</li>
|
| 142 |
+
<ul>
|
| 143 |
+
<li><code>GITHUB_TOKEN</code> (Private Secret) - 你的GitHub Personal Access Token</li>
|
| 144 |
+
<li><code>GITHUB_OWNER</code> (Public) - GitHub用户名或组织名</li>
|
| 145 |
+
<li><code>GITHUB_REPO</code> (Public) - 仓库名</li>
|
| 146 |
+
<li><code>GITHUB_BRANCH</code> (Public) - 分支名(通常是main)</li>
|
| 147 |
+
<li><code>GITHUB_PATH</code> (Public) - 存储路径(如: pages/)</li>
|
| 148 |
+
</ul>
|
| 149 |
+
<li>添加后点击 <strong>Restart this Space</strong> 使环境变量生效</li>
|
| 150 |
+
</ol>
|
| 151 |
+
</div>
|
| 152 |
+
</div>
|
| 153 |
+
</div>
|
| 154 |
+
<?php else: ?>
|
| 155 |
+
<div class="alert alert-success">
|
| 156 |
+
<h3 class="status-ok">✅ 配置检查通过</h3>
|
| 157 |
+
<p>所有必需的环境变量都已正确设置在Hugging Face Space中。</p>
|
| 158 |
+
</div>
|
| 159 |
+
<?php endif; ?>
|
| 160 |
+
|
| 161 |
+
<!-- 当前配置详情 -->
|
| 162 |
+
<div class="card mb-4">
|
| 163 |
+
<div class="card-header">
|
| 164 |
+
<h3>📋 当前环境变量配置</h3>
|
| 165 |
+
</div>
|
| 166 |
+
<div class="card-body">
|
| 167 |
+
<div class="row">
|
| 168 |
+
<div class="col-md-6">
|
| 169 |
+
<h5>存储配置</h5>
|
| 170 |
+
<p><strong>存储类型:</strong> <span class="config-value"><?= htmlspecialchars($storageType) ?></span></p>
|
| 171 |
+
|
| 172 |
+
<h5 class="mt-4">GitHub 环境变量</h5>
|
| 173 |
+
<p><strong>GITHUB_TOKEN:</strong>
|
| 174 |
+
<span class="config-value <?= empty($github['token']) ? 'status-error' : 'status-ok' ?>">
|
| 175 |
+
<?php
|
| 176 |
+
if (empty($github['token'])) {
|
| 177 |
+
echo '❌ 未设置';
|
| 178 |
+
} else {
|
| 179 |
+
echo '✅ ' . substr($github['token'], 0, 8) . '... (长度: ' . strlen($github['token']) . ')';
|
| 180 |
+
}
|
| 181 |
+
?>
|
| 182 |
+
</span>
|
| 183 |
+
</p>
|
| 184 |
+
<p><strong>GITHUB_OWNER:</strong> <span class="config-value"><?= htmlspecialchars($github['owner']) ?></span></p>
|
| 185 |
+
<p><strong>GITHUB_REPO:</strong> <span class="config-value"><?= htmlspecialchars($github['repo']) ?></span></p>
|
| 186 |
+
<p><strong>GITHUB_BRANCH:</strong> <span class="config-value"><?= htmlspecialchars($github['branch']) ?></span></p>
|
| 187 |
+
<p><strong>GITHUB_PATH:</strong> <span class="config-value"><?= htmlspecialchars($github['path']) ?></span></p>
|
| 188 |
+
</div>
|
| 189 |
+
<div class="col-md-6">
|
| 190 |
+
<h5>用户配置</h5>
|
| 191 |
+
<p><strong>当前用户:</strong> <span class="config-value"><?= htmlspecialchars(StorageConfig::getCurrentUser()) ?></span></p>
|
| 192 |
+
<p><strong>用户路径:</strong> <span class="config-value"><?= htmlspecialchars(StorageConfig::getUserPath()) ?></span></p>
|
| 193 |
+
|
| 194 |
+
<h5 class="mt-4">EdgeOne KV 配置</h5>
|
| 195 |
+
<p><strong>EDGEONE_KV_API_KEY:</strong>
|
| 196 |
+
<span class="config-value">
|
| 197 |
+
<?= !empty($kv['api_key']) ? '✅ ' . substr($kv['api_key'], 0, 8) . '...' : '❌ 未设置' ?>
|
| 198 |
+
</span>
|
| 199 |
+
</p>
|
| 200 |
+
<p><strong>EDGEONE_KV_SECRET_KEY:</strong>
|
| 201 |
+
<span class="config-value">
|
| 202 |
+
<?= !empty($kv['secret_key']) ? '✅ ' . substr($kv['secret_key'], 0, 8) . '...' : '❌ 未设置' ?>
|
| 203 |
+
</span>
|
| 204 |
+
</p>
|
| 205 |
+
<p><strong>EDGEONE_KV_ZONE_ID:</strong> <span class="config-value"><?= htmlspecialchars($kv['zone_id']) ?></span></p>
|
| 206 |
+
<p><strong>EDGEONE_KV_NAMESPACE:</strong> <span class="config-value"><?= htmlspecialchars($kv['namespace']) ?></span></p>
|
| 207 |
+
</div>
|
| 208 |
+
</div>
|
| 209 |
+
</div>
|
| 210 |
+
</div>
|
| 211 |
+
|
| 212 |
+
<!-- 环境调试信息 -->
|
| 213 |
+
<div class="card mb-4">
|
| 214 |
+
<div class="card-header">
|
| 215 |
+
<h3>🔍 环境调试信息</h3>
|
| 216 |
+
</div>
|
| 217 |
+
<div class="card-body">
|
| 218 |
+
<div class="env-debug">
|
| 219 |
+
<?= json_encode($envDebug, JSON_PRETTY_PRINT) ?>
|
| 220 |
+
</div>
|
| 221 |
+
<small class="text-muted">这些信息有助于调试环境变量读取问题</small>
|
| 222 |
+
</div>
|
| 223 |
+
</div>
|
| 224 |
+
|
| 225 |
+
<!-- 测试工具 -->
|
| 226 |
+
<div class="card mb-4">
|
| 227 |
+
<div class="card-header">
|
| 228 |
+
<h3>🧪 测试工具</h3>
|
| 229 |
+
</div>
|
| 230 |
+
<div class="card-body">
|
| 231 |
+
<div class="row">
|
| 232 |
+
<div class="col-md-3">
|
| 233 |
+
<a href="github-advanced-test.php" class="btn btn-primary w-100">GitHub 完整测试</a>
|
| 234 |
+
</div>
|
| 235 |
+
<div class="col-md-3">
|
| 236 |
+
<a href="github-test.php" class="btn btn-info w-100">GitHub 基础测试</a>
|
| 237 |
+
</div>
|
| 238 |
+
<div class="col-md-3">
|
| 239 |
+
<a href="config-check.php" class="btn btn-secondary w-100">通用配置检查</a>
|
| 240 |
+
</div>
|
| 241 |
+
<div class="col-md-3">
|
| 242 |
+
<a href="editor.html" class="btn btn-success w-100">返回编辑器</a>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
|
| 248 |
+
<!-- Hugging Face Space 特殊说明 -->
|
| 249 |
+
<div class="card">
|
| 250 |
+
<div class="card-header">
|
| 251 |
+
<h3>📚 Hugging Face Space 配置指南</h3>
|
| 252 |
+
</div>
|
| 253 |
+
<div class="card-body">
|
| 254 |
+
<div class="accordion" id="hfAccordion">
|
| 255 |
+
<div class="accordion-item">
|
| 256 |
+
<h2 class="accordion-header">
|
| 257 |
+
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#hf1">
|
| 258 |
+
如何添加环境变量?
|
| 259 |
+
</button>
|
| 260 |
+
</h2>
|
| 261 |
+
<div id="hf1" class="accordion-collapse collapse show" data-bs-parent="#hfAccordion">
|
| 262 |
+
<div class="accordion-body">
|
| 263 |
+
<ol>
|
| 264 |
+
<li>登录 <a href="https://huggingface.co" target="_blank">Hugging Face</a></li>
|
| 265 |
+
<li>进入你的 Space: <strong>catptain-vvvebjs</strong></li>
|
| 266 |
+
<li>点击 <strong>Settings</strong> 标签</li>
|
| 267 |
+
<li>找到 <strong>Variables and secrets</strong> 部分</li>
|
| 268 |
+
<li>点击 <strong>New variable</strong> 或 <strong>New secret</strong></li>
|
| 269 |
+
<li>添加必需的环境变量</li>
|
| 270 |
+
<li>点击 <strong>Restart this Space</strong></li>
|
| 271 |
+
</ol>
|
| 272 |
+
</div>
|
| 273 |
+
</div>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="accordion-item">
|
| 276 |
+
<h2 class="accordion-header">
|
| 277 |
+
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#hf2">
|
| 278 |
+
Public变量 vs Private密钥?
|
| 279 |
+
</button>
|
| 280 |
+
</h2>
|
| 281 |
+
<div id="hf2" class="accordion-collapse collapse" data-bs-parent="#hfAccordion">
|
| 282 |
+
<div class="accordion-body">
|
| 283 |
+
<strong>Private Secrets (私有密钥):</strong>
|
| 284 |
+
<ul>
|
| 285 |
+
<li><code>GITHUB_TOKEN</code> - GitHub访问令牌,必须保密</li>
|
| 286 |
+
<li><code>EDGEONE_KV_API_KEY</code> - API密钥</li>
|
| 287 |
+
<li><code>EDGEONE_KV_SECRET_KEY</code> - 密钥</li>
|
| 288 |
+
<li>用户密码变量</li>
|
| 289 |
+
</ul>
|
| 290 |
+
<strong>Public Variables (公开变量):</strong>
|
| 291 |
+
<ul>
|
| 292 |
+
<li><code>GITHUB_OWNER</code></li>
|
| 293 |
+
<li><code>GITHUB_REPO</code></li>
|
| 294 |
+
<li><code>GITHUB_BRANCH</code></li>
|
| 295 |
+
<li><code>GITHUB_PATH</code></li>
|
| 296 |
+
<li><code>STORAGE_TYPE</code></li>
|
| 297 |
+
<li>用户名变量</li>
|
| 298 |
+
</ul>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
</div>
|
| 302 |
+
<div class="accordion-item">
|
| 303 |
+
<h2 class="accordion-header">
|
| 304 |
+
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#hf3">
|
| 305 |
+
环境变量不生效?
|
| 306 |
+
</button>
|
| 307 |
+
</h2>
|
| 308 |
+
<div id="hf3" class="accordion-collapse collapse" data-bs-parent="#hfAccordion">
|
| 309 |
+
<div class="accordion-body">
|
| 310 |
+
<strong>解决步骤:</strong>
|
| 311 |
+
<ol>
|
| 312 |
+
<li>确认在Hugging Face Space的Settings中正确添加了所有环境变量</li>
|
| 313 |
+
<li>检查变量名拼写是否完全正确(区分大小写)</li>
|
| 314 |
+
<li>确认GitHub Token有正确的权限(需要repo权限)</li>
|
| 315 |
+
<li>保存环境变量后,一定要点击 <strong>"Restart this Space"</strong></li>
|
| 316 |
+
<li>等待Space重启完成(通常需要1-2分钟)</li>
|
| 317 |
+
<li>重新访问这个配置检查页面验证</li>
|
| 318 |
+
</ol>
|
| 319 |
+
</div>
|
| 320 |
+
</div>
|
| 321 |
+
</div>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
</div>
|
| 325 |
+
</div>
|
| 326 |
+
</div>
|
| 327 |
+
</div>
|
| 328 |
+
|
| 329 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
| 330 |
+
</body>
|
| 331 |
+
</html>
|
storage.php
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
-
// Load environment variables from .env file
|
| 3 |
function loadEnv($filePath) {
|
| 4 |
if (!file_exists($filePath)) {
|
| 5 |
return false;
|
|
@@ -11,6 +11,10 @@ function loadEnv($filePath) {
|
|
| 11 |
continue; // Skip comments
|
| 12 |
}
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
list($name, $value) = explode('=', $line, 2);
|
| 15 |
$name = trim($name);
|
| 16 |
$value = trim($value);
|
|
@@ -22,14 +26,16 @@ function loadEnv($filePath) {
|
|
| 22 |
$value = $matches[1];
|
| 23 |
}
|
| 24 |
|
| 25 |
-
if (
|
|
|
|
| 26 |
$_ENV[$name] = $value;
|
|
|
|
| 27 |
}
|
| 28 |
}
|
| 29 |
return true;
|
| 30 |
}
|
| 31 |
|
| 32 |
-
// Load .env file
|
| 33 |
if (file_exists(__DIR__ . '/.env')) {
|
| 34 |
loadEnv(__DIR__ . '/.env');
|
| 35 |
} else {
|
|
@@ -52,8 +58,9 @@ class StorageConfig {
|
|
| 52 |
$users = [];
|
| 53 |
$i = 1;
|
| 54 |
while (true) {
|
| 55 |
-
|
| 56 |
-
$
|
|
|
|
| 57 |
|
| 58 |
if (empty($username) || empty($password)) {
|
| 59 |
break;
|
|
@@ -68,26 +75,36 @@ class StorageConfig {
|
|
| 68 |
}
|
| 69 |
|
| 70 |
public static function getStorageType() {
|
| 71 |
-
return $_ENV['STORAGE_TYPE'] ?? 'github';
|
| 72 |
}
|
| 73 |
|
| 74 |
public static function getGitHubConfig() {
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
'
|
| 78 |
-
'
|
| 79 |
-
'
|
| 80 |
-
'
|
|
|
|
| 81 |
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
}
|
| 83 |
|
| 84 |
public static function getKVConfig() {
|
| 85 |
return [
|
| 86 |
-
'api_key' => $_ENV['EDGEONE_KV_API_KEY'] ?? '',
|
| 87 |
-
'secret_key' => $_ENV['EDGEONE_KV_SECRET_KEY'] ?? '',
|
| 88 |
-
'zone_id' => $_ENV['EDGEONE_KV_ZONE_ID'] ?? '',
|
| 89 |
-
'namespace' => $_ENV['EDGEONE_KV_NAMESPACE'] ?? 'vvvebjs',
|
| 90 |
-
'endpoint' => $_ENV['EDGEONE_KV_ENDPOINT'] ?? 'https://edgeone.tencentcloudapi.com'
|
| 91 |
];
|
| 92 |
}
|
| 93 |
|
|
@@ -113,6 +130,32 @@ class StorageConfig {
|
|
| 113 |
$safeUsername = preg_replace('/[^a-zA-Z0-9_-]/', '_', $username);
|
| 114 |
return "users/{$safeUsername}/";
|
| 115 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
}
|
| 117 |
|
| 118 |
// External storage handlers
|
|
|
|
| 1 |
<?php
|
| 2 |
+
// Load environment variables from .env file (for local development)
|
| 3 |
function loadEnv($filePath) {
|
| 4 |
if (!file_exists($filePath)) {
|
| 5 |
return false;
|
|
|
|
| 11 |
continue; // Skip comments
|
| 12 |
}
|
| 13 |
|
| 14 |
+
if (strpos($line, '=') === false) {
|
| 15 |
+
continue; // Skip lines without =
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
list($name, $value) = explode('=', $line, 2);
|
| 19 |
$name = trim($name);
|
| 20 |
$value = trim($value);
|
|
|
|
| 26 |
$value = $matches[1];
|
| 27 |
}
|
| 28 |
|
| 29 |
+
// Only set if not already in environment (Hugging Face Space variables take precedence)
|
| 30 |
+
if (!array_key_exists($name, $_ENV) && !isset($_SERVER[$name])) {
|
| 31 |
$_ENV[$name] = $value;
|
| 32 |
+
putenv("$name=$value");
|
| 33 |
}
|
| 34 |
}
|
| 35 |
return true;
|
| 36 |
}
|
| 37 |
|
| 38 |
+
// Load .env file for local development (Hugging Face Space already has environment variables)
|
| 39 |
if (file_exists(__DIR__ . '/.env')) {
|
| 40 |
loadEnv(__DIR__ . '/.env');
|
| 41 |
} else {
|
|
|
|
| 58 |
$users = [];
|
| 59 |
$i = 1;
|
| 60 |
while (true) {
|
| 61 |
+
// Check both $_ENV and $_SERVER for Hugging Face Space compatibility
|
| 62 |
+
$username = $_ENV["USER_{$i}_NAME"] ?? $_SERVER["USER_{$i}_NAME"] ?? '';
|
| 63 |
+
$password = $_ENV["USER_{$i}_PASSWORD"] ?? $_SERVER["USER_{$i}_PASSWORD"] ?? '';
|
| 64 |
|
| 65 |
if (empty($username) || empty($password)) {
|
| 66 |
break;
|
|
|
|
| 75 |
}
|
| 76 |
|
| 77 |
public static function getStorageType() {
|
| 78 |
+
return $_ENV['STORAGE_TYPE'] ?? $_SERVER['STORAGE_TYPE'] ?? 'github';
|
| 79 |
}
|
| 80 |
|
| 81 |
public static function getGitHubConfig() {
|
| 82 |
+
// Read from environment variables (Hugging Face Space or system environment)
|
| 83 |
+
$config = [
|
| 84 |
+
'token' => $_ENV['GITHUB_TOKEN'] ?? $_SERVER['GITHUB_TOKEN'] ?? '',
|
| 85 |
+
'owner' => $_ENV['GITHUB_OWNER'] ?? $_SERVER['GITHUB_OWNER'] ?? '',
|
| 86 |
+
'repo' => $_ENV['GITHUB_REPO'] ?? $_SERVER['GITHUB_REPO'] ?? '',
|
| 87 |
+
'branch' => $_ENV['GITHUB_BRANCH'] ?? $_SERVER['GITHUB_BRANCH'] ?? 'main',
|
| 88 |
+
'path' => $_ENV['GITHUB_PATH'] ?? $_SERVER['GITHUB_PATH'] ?? 'pages/'
|
| 89 |
];
|
| 90 |
+
|
| 91 |
+
// Debug log for Hugging Face Space
|
| 92 |
+
error_log("GitHub Config Debug - Token present: " . (!empty($config['token']) ? 'YES' : 'NO'));
|
| 93 |
+
error_log("GitHub Config Debug - Owner: " . $config['owner']);
|
| 94 |
+
error_log("GitHub Config Debug - Repo: " . $config['repo']);
|
| 95 |
+
error_log("GitHub Config Debug - Branch: " . $config['branch']);
|
| 96 |
+
error_log("GitHub Config Debug - Path: " . $config['path']);
|
| 97 |
+
|
| 98 |
+
return $config;
|
| 99 |
}
|
| 100 |
|
| 101 |
public static function getKVConfig() {
|
| 102 |
return [
|
| 103 |
+
'api_key' => $_ENV['EDGEONE_KV_API_KEY'] ?? $_SERVER['EDGEONE_KV_API_KEY'] ?? '',
|
| 104 |
+
'secret_key' => $_ENV['EDGEONE_KV_SECRET_KEY'] ?? $_SERVER['EDGEONE_KV_SECRET_KEY'] ?? '',
|
| 105 |
+
'zone_id' => $_ENV['EDGEONE_KV_ZONE_ID'] ?? $_SERVER['EDGEONE_KV_ZONE_ID'] ?? '',
|
| 106 |
+
'namespace' => $_ENV['EDGEONE_KV_NAMESPACE'] ?? $_SERVER['EDGEONE_KV_NAMESPACE'] ?? 'vvvebjs',
|
| 107 |
+
'endpoint' => $_ENV['EDGEONE_KV_ENDPOINT'] ?? $_SERVER['EDGEONE_KV_ENDPOINT'] ?? 'https://edgeone.tencentcloudapi.com'
|
| 108 |
];
|
| 109 |
}
|
| 110 |
|
|
|
|
| 130 |
$safeUsername = preg_replace('/[^a-zA-Z0-9_-]/', '_', $username);
|
| 131 |
return "users/{$safeUsername}/";
|
| 132 |
}
|
| 133 |
+
|
| 134 |
+
// Add method to check if running on Hugging Face Space
|
| 135 |
+
public static function isHuggingFaceSpace() {
|
| 136 |
+
return isset($_SERVER['SPACE_ID']) ||
|
| 137 |
+
isset($_ENV['SPACE_ID']) ||
|
| 138 |
+
strpos($_SERVER['HTTP_HOST'] ?? '', '.hf.space') !== false;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// Debug method to show all environment variables (for debugging)
|
| 142 |
+
public static function debugEnvironment() {
|
| 143 |
+
$debug = [
|
| 144 |
+
'is_hf_space' => self::isHuggingFaceSpace(),
|
| 145 |
+
'space_id' => $_SERVER['SPACE_ID'] ?? $_ENV['SPACE_ID'] ?? 'not_set',
|
| 146 |
+
'host' => $_SERVER['HTTP_HOST'] ?? 'unknown',
|
| 147 |
+
'github_vars' => [
|
| 148 |
+
'token_set' => !empty($_ENV['GITHUB_TOKEN'] ?? $_SERVER['GITHUB_TOKEN']),
|
| 149 |
+
'owner' => $_ENV['GITHUB_OWNER'] ?? $_SERVER['GITHUB_OWNER'] ?? 'not_set',
|
| 150 |
+
'repo' => $_ENV['GITHUB_REPO'] ?? $_SERVER['GITHUB_REPO'] ?? 'not_set',
|
| 151 |
+
'branch' => $_ENV['GITHUB_BRANCH'] ?? $_SERVER['GITHUB_BRANCH'] ?? 'not_set',
|
| 152 |
+
'path' => $_ENV['GITHUB_PATH'] ?? $_SERVER['GITHUB_PATH'] ?? 'not_set'
|
| 153 |
+
]
|
| 154 |
+
];
|
| 155 |
+
|
| 156 |
+
error_log("Environment Debug: " . json_encode($debug));
|
| 157 |
+
return $debug;
|
| 158 |
+
}
|
| 159 |
}
|
| 160 |
|
| 161 |
// External storage handlers
|