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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Directory Test"');
|
| 14 |
+
header('HTTP/1.0 401 Unauthorized');
|
| 15 |
+
die('Authentication required');
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
$github = StorageConfig::getGitHubConfig();
|
| 19 |
+
$currentUser = StorageConfig::getCurrentUser();
|
| 20 |
+
$userPath = StorageConfig::getUserPath();
|
| 21 |
+
|
| 22 |
+
// 目录创建测试
|
| 23 |
+
$testResults = [];
|
| 24 |
+
if ($_POST['test_directory_creation'] ?? false) {
|
| 25 |
+
try {
|
| 26 |
+
error_log("Directory Test: Starting manual directory creation test");
|
| 27 |
+
|
| 28 |
+
$storageManager = new StorageManager();
|
| 29 |
+
$githubStorage = new GitHubStorage($github);
|
| 30 |
+
|
| 31 |
+
// 测试1: 创建一个简单的HTML文件来触发目录创建
|
| 32 |
+
$testHtml = '<!DOCTYPE html>
|
| 33 |
+
<html lang="en">
|
| 34 |
+
<head>
|
| 35 |
+
<meta charset="UTF-8">
|
| 36 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 37 |
+
<title>VvvebJs Directory Creation Test</title>
|
| 38 |
+
<style>
|
| 39 |
+
body { font-family: Arial, sans-serif; margin: 40px; background: #f5f5f5; }
|
| 40 |
+
.container { max-width: 800px; margin: 0 auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
|
| 41 |
+
h1 { color: #333; border-bottom: 2px solid #4CAF50; padding-bottom: 10px; }
|
| 42 |
+
.success { color: #4CAF50; font-weight: bold; }
|
| 43 |
+
.info { background: #e7f3ff; padding: 15px; border-radius: 5px; margin: 15px 0; }
|
| 44 |
+
</style>
|
| 45 |
+
</head>
|
| 46 |
+
<body>
|
| 47 |
+
<div class="container">
|
| 48 |
+
<h1>🎉 VvvebJs Directory Creation Test</h1>
|
| 49 |
+
|
| 50 |
+
<div class="info">
|
| 51 |
+
<p><strong>Test Status:</strong> <span class="success">SUCCESS</span></p>
|
| 52 |
+
<p><strong>Created:</strong> ' . date('Y-m-d H:i:s') . ' UTC</p>
|
| 53 |
+
<p><strong>User:</strong> ' . htmlspecialchars($currentUser) . '</p>
|
| 54 |
+
<p><strong>User Path:</strong> ' . htmlspecialchars($userPath) . '</p>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<h2>📁 Directory Structure Created</h2>
|
| 58 |
+
<ul>
|
| 59 |
+
<li><code>pages/</code> - Base directory for all pages</li>
|
| 60 |
+
<li><code>pages/users/</code> - Users directory</li>
|
| 61 |
+
<li><code>pages/users/' . str_replace('/', '', $userPath) . '</code> - Your personal directory</li>
|
| 62 |
+
</ul>
|
| 63 |
+
|
| 64 |
+
<h2>✅ What This Proves</h2>
|
| 65 |
+
<p>If you can see this page, it means:</p>
|
| 66 |
+
<ol>
|
| 67 |
+
<li>GitHub directory creation is working correctly</li>
|
| 68 |
+
<li>User isolation is functioning properly</li>
|
| 69 |
+
<li>File saving to GitHub repository is successful</li>
|
| 70 |
+
<li>All necessary directories have been created automatically</li>
|
| 71 |
+
</ol>
|
| 72 |
+
|
| 73 |
+
<h2>🔗 Next Steps</h2>
|
| 74 |
+
<p>You can now safely use the VvvebJs editor to create and save your HTML pages. Each user gets their own isolated directory within the GitHub repository.</p>
|
| 75 |
+
|
| 76 |
+
<div class="info">
|
| 77 |
+
<p><strong>GitHub Repository:</strong> <a href="https://github.com/' . htmlspecialchars($github['owner']) . '/' . htmlspecialchars($github['repo']) . '" target="_blank">' . htmlspecialchars($github['owner']) . '/' . htmlspecialchars($github['repo']) . '</a></p>
|
| 78 |
+
<p><strong>File Location:</strong> <code>pages/' . htmlspecialchars($userPath) . 'directory-test-' . time() . '.html</code></p>
|
| 79 |
+
</div>
|
| 80 |
+
</div>
|
| 81 |
+
</body>
|
| 82 |
+
</html>';
|
| 83 |
+
|
| 84 |
+
$testFilename = 'directory-test-' . time() . '.html';
|
| 85 |
+
|
| 86 |
+
error_log("Directory Test: Attempting to save test file: $testFilename");
|
| 87 |
+
$result = $storageManager->saveFile($testFilename, $testHtml);
|
| 88 |
+
|
| 89 |
+
$testResults['directory_test'] = [
|
| 90 |
+
'success' => $result,
|
| 91 |
+
'filename' => $testFilename,
|
| 92 |
+
'content_length' => strlen($testHtml),
|
| 93 |
+
'message' => $result ? 'Directory structure created and file saved successfully!' : 'Directory creation or file save failed!'
|
| 94 |
+
];
|
| 95 |
+
|
| 96 |
+
// 测试2: 验证目录结构
|
| 97 |
+
if ($result) {
|
| 98 |
+
error_log("Directory Test: File saved successfully, now testing directory structure");
|
| 99 |
+
|
| 100 |
+
// 检查基础目录
|
| 101 |
+
$baseUrl = "https://api.github.com/repos/{$github['owner']}/{$github['repo']}/contents/pages";
|
| 102 |
+
$usersUrl = "https://api.github.com/repos/{$github['owner']}/{$github['repo']}/contents/pages/users";
|
| 103 |
+
$userDirUrl = "https://api.github.com/repos/{$github['owner']}/{$github['repo']}/contents/pages/{$userPath}";
|
| 104 |
+
|
| 105 |
+
$testResults['structure_check'] = [
|
| 106 |
+
'base_dir' => $githubStorage->makeRequest($baseUrl, 'GET') !== false,
|
| 107 |
+
'users_dir' => $githubStorage->makeRequest($usersUrl, 'GET') !== false,
|
| 108 |
+
'user_dir' => $githubStorage->makeRequest($userDirUrl, 'GET') !== false
|
| 109 |
+
];
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
} catch (Exception $e) {
|
| 113 |
+
error_log("Directory Test Error: " . $e->getMessage());
|
| 114 |
+
$testResults['directory_test'] = [
|
| 115 |
+
'success' => false,
|
| 116 |
+
'error' => $e->getMessage(),
|
| 117 |
+
'filename' => $testFilename ?? 'unknown'
|
| 118 |
+
];
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// 清理测试文件
|
| 123 |
+
if ($_POST['cleanup_test_files'] ?? false) {
|
| 124 |
+
try {
|
| 125 |
+
$storageManager = new StorageManager();
|
| 126 |
+
$files = $storageManager->listFiles();
|
| 127 |
+
|
| 128 |
+
$cleanedCount = 0;
|
| 129 |
+
foreach ($files as $file) {
|
| 130 |
+
if (strpos($file['name'], 'directory-test-') === 0 || strpos($file['name'], 'test-') === 0) {
|
| 131 |
+
if ($storageManager->deleteFile($file['name'])) {
|
| 132 |
+
$cleanedCount++;
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
$testResults['cleanup'] = [
|
| 138 |
+
'success' => true,
|
| 139 |
+
'cleaned_count' => $cleanedCount,
|
| 140 |
+
'message' => "Cleaned up $cleanedCount test files"
|
| 141 |
+
];
|
| 142 |
+
|
| 143 |
+
} catch (Exception $e) {
|
| 144 |
+
$testResults['cleanup'] = [
|
| 145 |
+
'success' => false,
|
| 146 |
+
'error' => $e->getMessage()
|
| 147 |
+
];
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
?>
|
| 151 |
+
|
| 152 |
+
<!DOCTYPE html>
|
| 153 |
+
<html lang="en">
|
| 154 |
+
<head>
|
| 155 |
+
<meta charset="utf-8">
|
| 156 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 157 |
+
<title>VvvebJs 目录创建测试</title>
|
| 158 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 159 |
+
<style>
|
| 160 |
+
.config-value { background-color: #f8f9fa; padding: 2px 6px; border-radius: 3px; font-family: monospace; }
|
| 161 |
+
.status-ok { color: #28a745; }
|
| 162 |
+
.status-error { color: #dc3545; }
|
| 163 |
+
.status-warning { color: #ffc107; }
|
| 164 |
+
.test-result { margin-bottom: 20px; }
|
| 165 |
+
</style>
|
| 166 |
+
</head>
|
| 167 |
+
<body>
|
| 168 |
+
<div class="container mt-5">
|
| 169 |
+
<div class="row">
|
| 170 |
+
<div class="col-md-10 mx-auto">
|
| 171 |
+
<h1 class="mb-4">📁 VvvebJs GitHub 目录创建测试</h1>
|
| 172 |
+
|
| 173 |
+
<!-- 当前状态 -->
|
| 174 |
+
<div class="card mb-4">
|
| 175 |
+
<div class="card-header">
|
| 176 |
+
<h3>📋 当前状态</h3>
|
| 177 |
+
</div>
|
| 178 |
+
<div class="card-body">
|
| 179 |
+
<div class="row">
|
| 180 |
+
<div class="col-md-6">
|
| 181 |
+
<p><strong>当前用户:</strong> <span class="config-value"><?= htmlspecialchars($currentUser) ?></span></p>
|
| 182 |
+
<p><strong>用户路径:</strong> <span class="config-value"><?= htmlspecialchars($userPath) ?></span></p>
|
| 183 |
+
<p><strong>GitHub仓库:</strong> <span class="config-value"><?= htmlspecialchars($github['owner']) ?>/<?= htmlspecialchars($github['repo']) ?></span></p>
|
| 184 |
+
</div>
|
| 185 |
+
<div class="col-md-6">
|
| 186 |
+
<p><strong>分支:</strong> <span class="config-value"><?= htmlspecialchars($github['branch']) ?></span></p>
|
| 187 |
+
<p><strong>基础路径:</strong> <span class="config-value"><?= htmlspecialchars($github['path']) ?></span></p>
|
| 188 |
+
<p><strong>完整用户路径:</strong> <span class="config-value"><?= htmlspecialchars($github['path'] . $userPath) ?></span></p>
|
| 189 |
+
</div>
|
| 190 |
+
</div>
|
| 191 |
+
</div>
|
| 192 |
+
</div>
|
| 193 |
+
|
| 194 |
+
<!-- 测试控制 -->
|
| 195 |
+
<div class="card mb-4">
|
| 196 |
+
<div class="card-header">
|
| 197 |
+
<h3>🧪 目录创建测试</h3>
|
| 198 |
+
</div>
|
| 199 |
+
<div class="card-body">
|
| 200 |
+
<?php if (empty($testResults['directory_test'])): ?>
|
| 201 |
+
<div class="alert alert-info">
|
| 202 |
+
<h5>💡 测试说明</h5>
|
| 203 |
+
<p>此测试将:</p>
|
| 204 |
+
<ol>
|
| 205 |
+
<li>自动创建必要的GitHub目录结构</li>
|
| 206 |
+
<li>保存一个测试HTML文件到你的用户目录</li>
|
| 207 |
+
<li>验证目录创建是否成功</li>
|
| 208 |
+
<li>检查文件是否能正确保存和访问</li>
|
| 209 |
+
</ol>
|
| 210 |
+
</div>
|
| 211 |
+
|
| 212 |
+
<form method="POST">
|
| 213 |
+
<button type="submit" name="test_directory_creation" value="1" class="btn btn-primary btn-lg">
|
| 214 |
+
🚀 创建目录并测试保存
|
| 215 |
+
</button>
|
| 216 |
+
</form>
|
| 217 |
+
<?php else: ?>
|
| 218 |
+
<div class="test-result">
|
| 219 |
+
<h5>目录创建测试结果</h5>
|
| 220 |
+
<?php $dirTest = $testResults['directory_test']; ?>
|
| 221 |
+
<div class="alert alert-<?= $dirTest['success'] ? 'success' : 'danger' ?>">
|
| 222 |
+
<h6>
|
| 223 |
+
<span class="<?= $dirTest['success'] ? 'status-ok' : 'status-error' ?>">
|
| 224 |
+
<?= $dirTest['success'] ? '✅ 测试成功' : '❌ 测试失败' ?>
|
| 225 |
+
</span>
|
| 226 |
+
</h6>
|
| 227 |
+
<p><strong>文件名:</strong> <?= htmlspecialchars($dirTest['filename']) ?></p>
|
| 228 |
+
<p><strong>内容长度:</strong> <?= $dirTest['content_length'] ?? 0 ?> 字符</p>
|
| 229 |
+
<p><strong>结果:</strong> <?= htmlspecialchars($dirTest['message']) ?></p>
|
| 230 |
+
<?php if (!$dirTest['success'] && isset($dirTest['error'])): ?>
|
| 231 |
+
<p><strong>错误:</strong> <?= htmlspecialchars($dirTest['error']) ?></p>
|
| 232 |
+
<?php endif; ?>
|
| 233 |
+
</div>
|
| 234 |
+
|
| 235 |
+
<?php if ($dirTest['success'] && isset($testResults['structure_check'])): ?>
|
| 236 |
+
<h6>📁 目录结构验证</h6>
|
| 237 |
+
<?php $structCheck = $testResults['structure_check']; ?>
|
| 238 |
+
<ul class="list-unstyled">
|
| 239 |
+
<li><span class="<?= $structCheck['base_dir'] ? 'status-ok' : 'status-error' ?>"><?= $structCheck['base_dir'] ? '✅' : '❌' ?></span> 基础目录 (<code>pages/</code>)</li>
|
| 240 |
+
<li><span class="<?= $structCheck['users_dir'] ? 'status-ok' : 'status-error' ?>"><?= $structCheck['users_dir'] ? '✅' : '❌' ?></span> 用户目录 (<code>pages/users/</code>)</li>
|
| 241 |
+
<li><span class="<?= $structCheck['user_dir'] ? 'status-ok' : 'status-error' ?>"><?= $structCheck['user_dir'] ? '✅' : '❌' ?></span> 个人目录 (<code>pages/<?= htmlspecialchars($userPath) ?></code>)</li>
|
| 242 |
+
</ul>
|
| 243 |
+
<?php endif; ?>
|
| 244 |
+
|
| 245 |
+
<?php if ($dirTest['success']): ?>
|
| 246 |
+
<div class="alert alert-success mt-3">
|
| 247 |
+
<h6>🎉 成功!</h6>
|
| 248 |
+
<p>目录结构已成功创建,现在可以使用VvvebJs编辑器正常保存文件了。</p>
|
| 249 |
+
<p><strong>查看测试文件:</strong>
|
| 250 |
+
<a href="https://github.com/<?= htmlspecialchars($github['owner']) ?>/<?= htmlspecialchars($github['repo']) ?>/blob/<?= htmlspecialchars($github['branch']) ?>/pages/<?= htmlspecialchars($userPath) ?><?= htmlspecialchars($dirTest['filename']) ?>" target="_blank" class="btn btn-sm btn-outline-primary">
|
| 251 |
+
在GitHub上查看
|
| 252 |
+
</a>
|
| 253 |
+
</p>
|
| 254 |
+
</div>
|
| 255 |
+
<?php endif; ?>
|
| 256 |
+
</div>
|
| 257 |
+
|
| 258 |
+
<div class="mt-3">
|
| 259 |
+
<form method="POST" class="d-inline">
|
| 260 |
+
<button type="submit" name="test_directory_creation" value="1" class="btn btn-secondary">
|
| 261 |
+
🔄 重新测试
|
| 262 |
+
</button>
|
| 263 |
+
</form>
|
| 264 |
+
|
| 265 |
+
<form method="POST" class="d-inline ms-2">
|
| 266 |
+
<button type="submit" name="cleanup_test_files" value="1" class="btn btn-warning">
|
| 267 |
+
🧹 清理测试文件
|
| 268 |
+
</button>
|
| 269 |
+
</form>
|
| 270 |
+
</div>
|
| 271 |
+
<?php endif; ?>
|
| 272 |
+
|
| 273 |
+
<?php if (isset($testResults['cleanup'])): ?>
|
| 274 |
+
<div class="alert alert-info mt-3">
|
| 275 |
+
<h6>🧹 清理结果</h6>
|
| 276 |
+
<?php $cleanup = $testResults['cleanup']; ?>
|
| 277 |
+
<p><?= htmlspecialchars($cleanup['message'] ?? $cleanup['error']) ?></p>
|
| 278 |
+
</div>
|
| 279 |
+
<?php endif; ?>
|
| 280 |
+
</div>
|
| 281 |
+
</div>
|
| 282 |
+
|
| 283 |
+
<!-- 问题诊断 -->
|
| 284 |
+
<div class="card mb-4">
|
| 285 |
+
<div class="card-header">
|
| 286 |
+
<h3>🔍 问题诊断指南</h3>
|
| 287 |
+
</div>
|
| 288 |
+
<div class="card-body">
|
| 289 |
+
<div class="accordion" id="diagnosticAccordion">
|
| 290 |
+
<div class="accordion-item">
|
| 291 |
+
<h2 class="accordion-header">
|
| 292 |
+
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#diag1">
|
| 293 |
+
如果测试失败怎么办?
|
| 294 |
+
</button>
|
| 295 |
+
</h2>
|
| 296 |
+
<div id="diag1" class="accordion-collapse collapse show" data-bs-parent="#diagnosticAccordion">
|
| 297 |
+
<div class="accordion-body">
|
| 298 |
+
<strong>检查清单:</strong>
|
| 299 |
+
<ol>
|
| 300 |
+
<li>确认GitHub Token在Hugging Face Space中正确设置</li>
|
| 301 |
+
<li>确认Token有<code>repo</code>权限(不只是public_repo)</li>
|
| 302 |
+
<li>确认仓库名称和所有者名称完全正确</li>
|
| 303 |
+
<li>确认分支名称正确(通常是main或master)</li>
|
| 304 |
+
<li>检查网络连接是否稳定</li>
|
| 305 |
+
</ol>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
<div class="accordion-item">
|
| 310 |
+
<h2 class="accordion-header">
|
| 311 |
+
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#diag2">
|
| 312 |
+
目录结构说明
|
| 313 |
+
</button>
|
| 314 |
+
</h2>
|
| 315 |
+
<div id="diag2" class="accordion-collapse collapse" data-bs-parent="#diagnosticAccordion">
|
| 316 |
+
<div class="accordion-body">
|
| 317 |
+
<strong>创建的目录结构:</strong>
|
| 318 |
+
<pre><code>你的仓库/
|
| 319 |
+
├── pages/ # 基础页面目录
|
| 320 |
+
│ ├── README.md # 目录说明文件
|
| 321 |
+
│ └── users/ # 用户目录
|
| 322 |
+
│ ├── README.md # 用户目录说明
|
| 323 |
+
│ └── <?= str_replace('/', '', $userPath) ?>/ # 你的个人目录
|
| 324 |
+
│ ├── README.md # 个人目录说明
|
| 325 |
+
│ └── *.html # 你创建的HTML文件</code></pre>
|
| 326 |
+
</div>
|
| 327 |
+
</div>
|
| 328 |
+
</div>
|
| 329 |
+
</div>
|
| 330 |
+
</div>
|
| 331 |
+
</div>
|
| 332 |
+
|
| 333 |
+
<!-- 操作按钮 -->
|
| 334 |
+
<div class="card">
|
| 335 |
+
<div class="card-body text-center">
|
| 336 |
+
<div class="row">
|
| 337 |
+
<div class="col-md-3">
|
| 338 |
+
<a href="github-advanced-test.php" class="btn btn-primary w-100">完整测试</a>
|
| 339 |
+
</div>
|
| 340 |
+
<div class="col-md-3">
|
| 341 |
+
<a href="github-save-debug.php" class="btn btn-warning w-100">保存调试</a>
|
| 342 |
+
</div>
|
| 343 |
+
<div class="col-md-3">
|
| 344 |
+
<a href="hf-space-check.php" class="btn btn-info w-100">HF Space检查</a>
|
| 345 |
+
</div>
|
| 346 |
+
<div class="col-md-3">
|
| 347 |
+
<a href="editor.html" class="btn btn-success w-100">返回编辑器</a>
|
| 348 |
+
</div>
|
| 349 |
+
</div>
|
| 350 |
+
</div>
|
| 351 |
+
</div>
|
| 352 |
+
</div>
|
| 353 |
+
</div>
|
| 354 |
+
</div>
|
| 355 |
+
|
| 356 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
| 357 |
+
</body>
|
| 358 |
+
</html>
|
storage.php
CHANGED
|
@@ -429,31 +429,99 @@ class GitHubStorage {
|
|
| 429 |
|
| 430 |
// 新增方法:确保用户目录存在
|
| 431 |
private function ensureUserDirectoryExists() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
$userDirPath = $this->config['path'] . $this->userPath;
|
| 433 |
-
$readmePath = $userDirPath . 'README.md';
|
| 434 |
$readmeUrl = "https://api.github.com/repos/{$this->config['owner']}/{$this->config['repo']}/contents/{$readmePath}";
|
| 435 |
|
| 436 |
-
|
|
|
|
|
|
|
| 437 |
$existing = $this->makeRequest($readmeUrl, 'GET');
|
| 438 |
|
| 439 |
if (!$existing) {
|
| 440 |
-
|
| 441 |
-
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
$readmeData = [
|
| 444 |
-
'message' => "Create user directory for " .
|
| 445 |
'content' => base64_encode($readmeContent),
|
| 446 |
'branch' => $this->config['branch']
|
| 447 |
];
|
| 448 |
|
| 449 |
-
error_log("GitHub
|
| 450 |
$result = $this->makeRequest($readmeUrl, 'PUT', $readmeData);
|
| 451 |
|
| 452 |
if ($result) {
|
| 453 |
-
error_log("GitHub
|
|
|
|
| 454 |
} else {
|
| 455 |
-
error_log("GitHub
|
|
|
|
| 456 |
}
|
|
|
|
|
|
|
|
|
|
| 457 |
}
|
| 458 |
}
|
| 459 |
|
|
|
|
| 429 |
|
| 430 |
// 新增方法:确保用户目录存在
|
| 431 |
private function ensureUserDirectoryExists() {
|
| 432 |
+
error_log("GitHub Directory Creation: Starting directory creation process");
|
| 433 |
+
|
| 434 |
+
// 第一步:确保基础pages目录存在
|
| 435 |
+
$basePath = rtrim($this->config['path'], '/');
|
| 436 |
+
$baseReadmePath = $basePath . '/README.md';
|
| 437 |
+
$baseReadmeUrl = "https://api.github.com/repos/{$this->config['owner']}/{$this->config['repo']}/contents/{$baseReadmePath}";
|
| 438 |
+
|
| 439 |
+
// 检查基础目录是否存在
|
| 440 |
+
$baseExists = $this->makeRequest($baseReadmeUrl, 'GET');
|
| 441 |
+
if (!$baseExists) {
|
| 442 |
+
error_log("GitHub Directory Creation: Base directory '$basePath' does not exist, creating...");
|
| 443 |
+
|
| 444 |
+
$baseReadmeContent = "# VvvebJs Web Builder Pages\n\nThis directory contains HTML files created by VvvebJs web builder.\n\nDirectory structure:\n- `users/` - User-specific files\n\nCreated: " . date('Y-m-d H:i:s') . " UTC";
|
| 445 |
+
|
| 446 |
+
$baseReadmeData = [
|
| 447 |
+
'message' => "Initialize VvvebJs pages directory",
|
| 448 |
+
'content' => base64_encode($baseReadmeContent),
|
| 449 |
+
'branch' => $this->config['branch']
|
| 450 |
+
];
|
| 451 |
+
|
| 452 |
+
$baseResult = $this->makeRequest($baseReadmeUrl, 'PUT', $baseReadmeData);
|
| 453 |
+
if ($baseResult) {
|
| 454 |
+
error_log("GitHub Directory Creation: Base directory created successfully");
|
| 455 |
+
} else {
|
| 456 |
+
error_log("GitHub Directory Creation: Failed to create base directory");
|
| 457 |
+
}
|
| 458 |
+
} else {
|
| 459 |
+
error_log("GitHub Directory Creation: Base directory already exists");
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
// 第二步:确保users目录存在
|
| 463 |
+
$usersPath = $basePath . '/users';
|
| 464 |
+
$usersReadmePath = $usersPath . '/README.md';
|
| 465 |
+
$usersReadmeUrl = "https://api.github.com/repos/{$this->config['owner']}/{$this->config['repo']}/contents/{$usersReadmePath}";
|
| 466 |
+
|
| 467 |
+
$usersExists = $this->makeRequest($usersReadmeUrl, 'GET');
|
| 468 |
+
if (!$usersExists) {
|
| 469 |
+
error_log("GitHub Directory Creation: Users directory '$usersPath' does not exist, creating...");
|
| 470 |
+
|
| 471 |
+
$usersReadmeContent = "# User Files Directory\n\nThis directory contains individual user folders with their HTML files.\n\nEach user gets their own isolated directory.\n\nCreated: " . date('Y-m-d H:i:s') . " UTC";
|
| 472 |
+
|
| 473 |
+
$usersReadmeData = [
|
| 474 |
+
'message' => "Create users directory for VvvebJs",
|
| 475 |
+
'content' => base64_encode($usersReadmeContent),
|
| 476 |
+
'branch' => $this->config['branch']
|
| 477 |
+
];
|
| 478 |
+
|
| 479 |
+
$usersResult = $this->makeRequest($usersReadmeUrl, 'PUT', $usersReadmeData);
|
| 480 |
+
if ($usersResult) {
|
| 481 |
+
error_log("GitHub Directory Creation: Users directory created successfully");
|
| 482 |
+
} else {
|
| 483 |
+
error_log("GitHub Directory Creation: Failed to create users directory");
|
| 484 |
+
}
|
| 485 |
+
} else {
|
| 486 |
+
error_log("GitHub Directory Creation: Users directory already exists");
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
// 第三步:确保用户特定目录存在
|
| 490 |
$userDirPath = $this->config['path'] . $this->userPath;
|
| 491 |
+
$readmePath = rtrim($userDirPath, '/') . '/README.md';
|
| 492 |
$readmeUrl = "https://api.github.com/repos/{$this->config['owner']}/{$this->config['repo']}/contents/{$readmePath}";
|
| 493 |
|
| 494 |
+
error_log("GitHub Directory Creation: Checking user directory at: $readmePath");
|
| 495 |
+
|
| 496 |
+
// 检查用户目录的README.md是否存在
|
| 497 |
$existing = $this->makeRequest($readmeUrl, 'GET');
|
| 498 |
|
| 499 |
if (!$existing) {
|
| 500 |
+
error_log("GitHub Directory Creation: User directory does not exist, creating...");
|
| 501 |
+
|
| 502 |
+
// 目录不存在,创建用户专用的README.md文件
|
| 503 |
+
$username = trim($this->userPath, '/');
|
| 504 |
+
$readmeContent = "# User Files for " . str_replace('users/', '', $username) . "\n\nThis directory contains HTML files created by VvvebJs web builder for this user.\n\n## Files\nAll HTML files in this directory are created and managed through the VvvebJs web interface.\n\nCreated: " . date('Y-m-d H:i:s') . " UTC\nUser: " . str_replace('users/', '', $username);
|
| 505 |
|
| 506 |
$readmeData = [
|
| 507 |
+
'message' => "Create user directory for " . str_replace('users/', '', $username),
|
| 508 |
'content' => base64_encode($readmeContent),
|
| 509 |
'branch' => $this->config['branch']
|
| 510 |
];
|
| 511 |
|
| 512 |
+
error_log("GitHub Directory Creation: Creating user README at: $readmePath");
|
| 513 |
$result = $this->makeRequest($readmeUrl, 'PUT', $readmeData);
|
| 514 |
|
| 515 |
if ($result) {
|
| 516 |
+
error_log("GitHub Directory Creation: User directory created successfully");
|
| 517 |
+
return true;
|
| 518 |
} else {
|
| 519 |
+
error_log("GitHub Directory Creation: Failed to create user directory README");
|
| 520 |
+
return false;
|
| 521 |
}
|
| 522 |
+
} else {
|
| 523 |
+
error_log("GitHub Directory Creation: User directory already exists");
|
| 524 |
+
return true;
|
| 525 |
}
|
| 526 |
}
|
| 527 |
|