|
|
<?php
|
|
|
require_once __DIR__ . '/storage.php';
|
|
|
|
|
|
|
|
|
$testAuth = false;
|
|
|
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
|
|
|
$users = StorageConfig::getUsers();
|
|
|
$testAuth = isset($users[$_SERVER['PHP_AUTH_USER']]) &&
|
|
|
$users[$_SERVER['PHP_AUTH_USER']] === $_SERVER['PHP_AUTH_PW'];
|
|
|
}
|
|
|
|
|
|
if (!$testAuth) {
|
|
|
header('WWW-Authenticate: Basic realm="VvvebJs Directory Test"');
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
die('Authentication required');
|
|
|
}
|
|
|
|
|
|
$github = StorageConfig::getGitHubConfig();
|
|
|
$currentUser = StorageConfig::getCurrentUser();
|
|
|
$userPath = StorageConfig::getUserPath();
|
|
|
|
|
|
|
|
|
$testResults = [];
|
|
|
if ($_POST['test_directory_creation'] ?? false) {
|
|
|
try {
|
|
|
error_log("Directory Test: Starting manual directory creation test");
|
|
|
|
|
|
$storageManager = new StorageManager();
|
|
|
$githubStorage = new GitHubStorage($github);
|
|
|
|
|
|
|
|
|
$testHtml = '<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
<title>VvvebJs Directory Creation Test</title>
|
|
|
<style>
|
|
|
body { font-family: Arial, sans-serif; margin: 40px; background: #f5f5f5; }
|
|
|
.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); }
|
|
|
h1 { color: #333; border-bottom: 2px solid #4CAF50; padding-bottom: 10px; }
|
|
|
.success { color: #4CAF50; font-weight: bold; }
|
|
|
.info { background: #e7f3ff; padding: 15px; border-radius: 5px; margin: 15px 0; }
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|
|
|
<div class="container">
|
|
|
<h1>🎉 VvvebJs Directory Creation Test</h1>
|
|
|
|
|
|
<div class="info">
|
|
|
<p><strong>Test Status:</strong> <span class="success">SUCCESS</span></p>
|
|
|
<p><strong>Created:</strong> ' . date('Y-m-d H:i:s') . ' UTC</p>
|
|
|
<p><strong>User:</strong> ' . htmlspecialchars($currentUser) . '</p>
|
|
|
<p><strong>User Path:</strong> ' . htmlspecialchars($userPath) . '</p>
|
|
|
</div>
|
|
|
|
|
|
<h2>📁 Directory Structure Created</h2>
|
|
|
<ul>
|
|
|
<li><code>pages/</code> - Base directory for all pages</li>
|
|
|
<li><code>pages/users/</code> - Users directory</li>
|
|
|
<li><code>pages/users/' . str_replace('/', '', $userPath) . '</code> - Your personal directory</li>
|
|
|
</ul>
|
|
|
|
|
|
<h2>✅ What This Proves</h2>
|
|
|
<p>If you can see this page, it means:</p>
|
|
|
<ol>
|
|
|
<li>GitHub directory creation is working correctly</li>
|
|
|
<li>User isolation is functioning properly</li>
|
|
|
<li>File saving to GitHub repository is successful</li>
|
|
|
<li>All necessary directories have been created automatically</li>
|
|
|
</ol>
|
|
|
|
|
|
<h2>🔗 Next Steps</h2>
|
|
|
<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>
|
|
|
|
|
|
<div class="info">
|
|
|
<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>
|
|
|
<p><strong>File Location:</strong> <code>pages/' . htmlspecialchars($userPath) . 'directory-test-' . time() . '.html</code></p>
|
|
|
</div>
|
|
|
</div>
|
|
|
</body>
|
|
|
</html>';
|
|
|
|
|
|
$testFilename = 'directory-test-' . time() . '.html';
|
|
|
|
|
|
error_log("Directory Test: Attempting to save test file: $testFilename");
|
|
|
$result = $storageManager->saveFile($testFilename, $testHtml);
|
|
|
|
|
|
$testResults['directory_test'] = [
|
|
|
'success' => $result,
|
|
|
'filename' => $testFilename,
|
|
|
'content_length' => strlen($testHtml),
|
|
|
'message' => $result ? 'Directory structure created and file saved successfully!' : 'Directory creation or file save failed!'
|
|
|
];
|
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
error_log("Directory Test: File saved successfully, now testing directory structure");
|
|
|
|
|
|
|
|
|
$baseUrl = "https://api.github.com/repos/{$github['owner']}/{$github['repo']}/contents/pages";
|
|
|
$usersUrl = "https://api.github.com/repos/{$github['owner']}/{$github['repo']}/contents/pages/users";
|
|
|
$userDirUrl = "https://api.github.com/repos/{$github['owner']}/{$github['repo']}/contents/pages/{$userPath}";
|
|
|
|
|
|
$testResults['structure_check'] = [
|
|
|
'base_dir' => $githubStorage->makeRequest($baseUrl, 'GET') !== false,
|
|
|
'users_dir' => $githubStorage->makeRequest($usersUrl, 'GET') !== false,
|
|
|
'user_dir' => $githubStorage->makeRequest($userDirUrl, 'GET') !== false
|
|
|
];
|
|
|
}
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
error_log("Directory Test Error: " . $e->getMessage());
|
|
|
$testResults['directory_test'] = [
|
|
|
'success' => false,
|
|
|
'error' => $e->getMessage(),
|
|
|
'filename' => $testFilename ?? 'unknown'
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if ($_POST['cleanup_test_files'] ?? false) {
|
|
|
try {
|
|
|
$storageManager = new StorageManager();
|
|
|
$files = $storageManager->listFiles();
|
|
|
|
|
|
$cleanedCount = 0;
|
|
|
foreach ($files as $file) {
|
|
|
if (strpos($file['name'], 'directory-test-') === 0 || strpos($file['name'], 'test-') === 0) {
|
|
|
if ($storageManager->deleteFile($file['name'])) {
|
|
|
$cleanedCount++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$testResults['cleanup'] = [
|
|
|
'success' => true,
|
|
|
'cleaned_count' => $cleanedCount,
|
|
|
'message' => "Cleaned up $cleanedCount test files"
|
|
|
];
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
$testResults['cleanup'] = [
|
|
|
'success' => false,
|
|
|
'error' => $e->getMessage()
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
?>
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="utf-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
<title>VvvebJs 目录创建测试</title>
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
<style>
|
|
|
.config-value { background-color:
|
|
|
.status-ok { color:
|
|
|
.status-error { color:
|
|
|
.status-warning { color:
|
|
|
.test-result { margin-bottom: 20px; }
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|
|
|
<div class="container mt-5">
|
|
|
<div class="row">
|
|
|
<div class="col-md-10 mx-auto">
|
|
|
<h1 class="mb-4">📁 VvvebJs GitHub 目录创建测试</h1>
|
|
|
|
|
|
<!-- 当前状态 -->
|
|
|
<div class="card mb-4">
|
|
|
<div class="card-header">
|
|
|
<h3>📋 当前状态</h3>
|
|
|
</div>
|
|
|
<div class="card-body">
|
|
|
<div class="row">
|
|
|
<div class="col-md-6">
|
|
|
<p><strong>当前用户:</strong> <span class="config-value"><?= htmlspecialchars($currentUser) ?></span></p>
|
|
|
<p><strong>用户路径:</strong> <span class="config-value"><?= htmlspecialchars($userPath) ?></span></p>
|
|
|
<p><strong>GitHub仓库:</strong> <span class="config-value"><?= htmlspecialchars($github['owner']) ?>/<?= htmlspecialchars($github['repo']) ?></span></p>
|
|
|
</div>
|
|
|
<div class="col-md-6">
|
|
|
<p><strong>分支:</strong> <span class="config-value"><?= htmlspecialchars($github['branch']) ?></span></p>
|
|
|
<p><strong>基础路径:</strong> <span class="config-value"><?= htmlspecialchars($github['path']) ?></span></p>
|
|
|
<p><strong>完整用户路径:</strong> <span class="config-value"><?= htmlspecialchars($github['path'] . $userPath) ?></span></p>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<!-- 测试控制 -->
|
|
|
<div class="card mb-4">
|
|
|
<div class="card-header">
|
|
|
<h3>🧪 目录创建测试</h3>
|
|
|
</div>
|
|
|
<div class="card-body">
|
|
|
<?php if (empty($testResults['directory_test'])): ?>
|
|
|
<div class="alert alert-info">
|
|
|
<h5>💡 测试说明</h5>
|
|
|
<p>此测试将:</p>
|
|
|
<ol>
|
|
|
<li>自动创建必要的GitHub目录结构</li>
|
|
|
<li>保存一个测试HTML文件到你的用户目录</li>
|
|
|
<li>验证目录创建是否成功</li>
|
|
|
<li>检查文件是否能正确保存和访问</li>
|
|
|
</ol>
|
|
|
</div>
|
|
|
|
|
|
<form method="POST">
|
|
|
<button type="submit" name="test_directory_creation" value="1" class="btn btn-primary btn-lg">
|
|
|
🚀 创建目录并测试保存
|
|
|
</button>
|
|
|
</form>
|
|
|
<?php else: ?>
|
|
|
<div class="test-result">
|
|
|
<h5>目录创建测试结果</h5>
|
|
|
<?php $dirTest = $testResults['directory_test']; ?>
|
|
|
<div class="alert alert-<?= $dirTest['success'] ? 'success' : 'danger' ?>">
|
|
|
<h6>
|
|
|
<span class="<?= $dirTest['success'] ? 'status-ok' : 'status-error' ?>">
|
|
|
<?= $dirTest['success'] ? '✅ 测试成功' : '❌ 测试失败' ?>
|
|
|
</span>
|
|
|
</h6>
|
|
|
<p><strong>文件名:</strong> <?= htmlspecialchars($dirTest['filename']) ?></p>
|
|
|
<p><strong>内容长度:</strong> <?= $dirTest['content_length'] ?? 0 ?> 字符</p>
|
|
|
<p><strong>结果:</strong> <?= htmlspecialchars($dirTest['message']) ?></p>
|
|
|
<?php if (!$dirTest['success'] && isset($dirTest['error'])): ?>
|
|
|
<p><strong>错误:</strong> <?= htmlspecialchars($dirTest['error']) ?></p>
|
|
|
<?php endif; ?>
|
|
|
</div>
|
|
|
|
|
|
<?php if ($dirTest['success'] && isset($testResults['structure_check'])): ?>
|
|
|
<h6>📁 目录结构验证</h6>
|
|
|
<?php $structCheck = $testResults['structure_check']; ?>
|
|
|
<ul class="list-unstyled">
|
|
|
<li><span class="<?= $structCheck['base_dir'] ? 'status-ok' : 'status-error' ?>"><?= $structCheck['base_dir'] ? '✅' : '❌' ?></span> 基础目录 (<code>pages/</code>)</li>
|
|
|
<li><span class="<?= $structCheck['users_dir'] ? 'status-ok' : 'status-error' ?>"><?= $structCheck['users_dir'] ? '✅' : '❌' ?></span> 用户目录 (<code>pages/users/</code>)</li>
|
|
|
<li><span class="<?= $structCheck['user_dir'] ? 'status-ok' : 'status-error' ?>"><?= $structCheck['user_dir'] ? '✅' : '❌' ?></span> 个人目录 (<code>pages/<?= htmlspecialchars($userPath) ?></code>)</li>
|
|
|
</ul>
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<?php if ($dirTest['success']): ?>
|
|
|
<div class="alert alert-success mt-3">
|
|
|
<h6>🎉 成功!</h6>
|
|
|
<p>目录结构已成功创建,现在可以使用VvvebJs编辑器正常保存文件了。</p>
|
|
|
<p><strong>查看测试文件:</strong>
|
|
|
<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">
|
|
|
在GitHub上查看
|
|
|
</a>
|
|
|
</p>
|
|
|
</div>
|
|
|
<?php endif; ?>
|
|
|
</div>
|
|
|
|
|
|
<div class="mt-3">
|
|
|
<form method="POST" class="d-inline">
|
|
|
<button type="submit" name="test_directory_creation" value="1" class="btn btn-secondary">
|
|
|
🔄 重新测试
|
|
|
</button>
|
|
|
</form>
|
|
|
|
|
|
<form method="POST" class="d-inline ms-2">
|
|
|
<button type="submit" name="cleanup_test_files" value="1" class="btn btn-warning">
|
|
|
🧹 清理测试文件
|
|
|
</button>
|
|
|
</form>
|
|
|
</div>
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<?php if (isset($testResults['cleanup'])): ?>
|
|
|
<div class="alert alert-info mt-3">
|
|
|
<h6>🧹 清理结果</h6>
|
|
|
<?php $cleanup = $testResults['cleanup']; ?>
|
|
|
<p><?= htmlspecialchars($cleanup['message'] ?? $cleanup['error']) ?></p>
|
|
|
</div>
|
|
|
<?php endif; ?>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<!-- 问题诊断 -->
|
|
|
<div class="card mb-4">
|
|
|
<div class="card-header">
|
|
|
<h3>🔍 问题诊断指南</h3>
|
|
|
</div>
|
|
|
<div class="card-body">
|
|
|
<div class="accordion" id="diagnosticAccordion">
|
|
|
<div class="accordion-item">
|
|
|
<h2 class="accordion-header">
|
|
|
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#diag1">
|
|
|
如果测试失败怎么办?
|
|
|
</button>
|
|
|
</h2>
|
|
|
<div id="diag1" class="accordion-collapse collapse show" data-bs-parent="#diagnosticAccordion">
|
|
|
<div class="accordion-body">
|
|
|
<strong>检查清单:</strong>
|
|
|
<ol>
|
|
|
<li>确认GitHub Token在Hugging Face Space中正确设置</li>
|
|
|
<li>确认Token有<code>repo</code>权限(不只是public_repo)</li>
|
|
|
<li>确认仓库名称和所有者名称完全正确</li>
|
|
|
<li>确认分支名称正确(通常是main或master)</li>
|
|
|
<li>检查网络连接是否稳定</li>
|
|
|
</ol>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="accordion-item">
|
|
|
<h2 class="accordion-header">
|
|
|
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#diag2">
|
|
|
目录结构说明
|
|
|
</button>
|
|
|
</h2>
|
|
|
<div id="diag2" class="accordion-collapse collapse" data-bs-parent="#diagnosticAccordion">
|
|
|
<div class="accordion-body">
|
|
|
<strong>创建的目录结构:</strong>
|
|
|
<pre><code>你的仓库/
|
|
|
├── pages/ # 基础页面目录
|
|
|
│ ├── README.md # 目录说明文件
|
|
|
│ └── users/ # 用户目录
|
|
|
│ ├── README.md # 用户目录说明
|
|
|
│ └── <?= str_replace('/', '', $userPath) ?>/ # 你的个人目录
|
|
|
│ ├── README.md # 个人目录说明
|
|
|
│ └── *.html # 你创建的HTML文件</code></pre>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<!-- 操作按钮 -->
|
|
|
<div class="card">
|
|
|
<div class="card-body text-center">
|
|
|
<div class="row">
|
|
|
<div class="col-md-3">
|
|
|
<a href="github-advanced-test.php" class="btn btn-primary w-100">完整测试</a>
|
|
|
</div>
|
|
|
<div class="col-md-3">
|
|
|
<a href="github-save-debug.php" class="btn btn-warning w-100">保存调试</a>
|
|
|
</div>
|
|
|
<div class="col-md-3">
|
|
|
<a href="hf-space-check.php" class="btn btn-info w-100">HF Space检查</a>
|
|
|
</div>
|
|
|
<div class="col-md-3">
|
|
|
<a href="editor.html" class="btn btn-success w-100">返回编辑器</a>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
</body>
|
|
|
</html> |