File size: 19,129 Bytes
456e734
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?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);
        
        // 测试1: 创建一个简单的HTML文件来触发目录创建
        $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!'
        ];
        
        // 测试2: 验证目录结构
        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: #f8f9fa; padding: 2px 6px; border-radius: 3px; font-family: monospace; }
        .status-ok { color: #28a745; }
        .status-error { color: #dc3545; }
        .status-warning { color: #ffc107; }
        .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 TokenHugging Face Space中正确设置</li>

                                            <li>确认Token有<code>repo</code>权限(不只是public_repo)</li>

                                            <li>确认仓库名称和所有者名称完全正确</li>

                                            <li>确认分支名称正确(通常是mainmaster)</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>