Upload 3 files
Browse files- .env +3 -1
- editor.html +375 -68
- validate-github.bat +102 -0
.env
CHANGED
|
@@ -2,7 +2,9 @@
|
|
| 2 |
STORAGE_TYPE=github
|
| 3 |
|
| 4 |
# GitHub Configuration
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
GITHUB_OWNER=CaPaCaptain
|
| 7 |
GITHUB_REPO=VvvebJs_huggingface_db_01
|
| 8 |
GITHUB_BRANCH=main
|
|
|
|
| 2 |
STORAGE_TYPE=github
|
| 3 |
|
| 4 |
# GitHub Configuration
|
| 5 |
+
# 🔑 重要:请将下面的 YOUR_ACTUAL_GITHUB_TOKEN 替换为您的真实GitHub Token
|
| 6 |
+
# 获取Token: https://github.com/settings/tokens → Generate new token (classic) → 选择 repo 权限
|
| 7 |
+
GITHUB_TOKEN=YOUR_ACTUAL_GITHUB_TOKEN
|
| 8 |
GITHUB_OWNER=CaPaCaptain
|
| 9 |
GITHUB_REPO=VvvebJs_huggingface_db_01
|
| 10 |
GITHUB_BRANCH=main
|
editor.html
CHANGED
|
@@ -15,31 +15,165 @@
|
|
| 15 |
<script>
|
| 16 |
// Enhanced authentication and file loading for GitHub integration
|
| 17 |
window.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
|
|
| 18 |
// Check authentication first
|
| 19 |
fetch('save.php?action=checkAuth', {
|
| 20 |
method: 'GET',
|
| 21 |
credentials: 'include'
|
| 22 |
}).then(response => {
|
| 23 |
if (response.status === 401) {
|
| 24 |
-
|
| 25 |
window.location.href = '/';
|
| 26 |
return;
|
| 27 |
}
|
| 28 |
|
| 29 |
-
// If authenticated,
|
| 30 |
-
|
|
|
|
| 31 |
}).catch(err => {
|
| 32 |
-
console.
|
| 33 |
-
// Redirect to login page on error
|
| 34 |
window.location.href = '/';
|
| 35 |
});
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
// GitHub-aware file loading functionality
|
| 38 |
function loadFileList() {
|
|
|
|
|
|
|
| 39 |
fetch('save.php?action=listFiles')
|
| 40 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
| 41 |
.then(data => {
|
| 42 |
-
console.log('File list response:', data);
|
| 43 |
const selector = document.getElementById('file-selector');
|
| 44 |
if (selector) {
|
| 45 |
selector.innerHTML = '<option value="">Select a file...</option>';
|
|
@@ -47,99 +181,153 @@
|
|
| 47 |
if (data.success && data.files && data.files.length > 0) {
|
| 48 |
data.files.forEach(file => {
|
| 49 |
const option = document.createElement('option');
|
| 50 |
-
|
| 51 |
-
option.
|
|
|
|
| 52 |
selector.appendChild(option);
|
| 53 |
});
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
} else {
|
| 58 |
-
console.log('No files found
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
}
|
| 60 |
}
|
| 61 |
})
|
| 62 |
.catch(error => {
|
| 63 |
-
console.error('Error loading file list:', error);
|
|
|
|
| 64 |
});
|
| 65 |
}
|
| 66 |
|
| 67 |
-
// Enhanced file loading with
|
| 68 |
function loadFileFromGitHub(filename) {
|
| 69 |
if (!filename) {
|
| 70 |
-
|
| 71 |
return;
|
| 72 |
}
|
| 73 |
|
| 74 |
-
console.log('Loading file from GitHub:', filename);
|
|
|
|
| 75 |
|
| 76 |
fetch(`save.php?action=loadFile&file=${encodeURIComponent(filename)}`)
|
| 77 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
.then(data => {
|
| 79 |
-
console.log('Load file response:', data);
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
}
|
| 95 |
} else {
|
| 96 |
-
console.warn('VvvebJs not ready yet, retrying...');
|
| 97 |
setTimeout(() => loadFileFromGitHub(filename), 1000);
|
| 98 |
}
|
| 99 |
} else {
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
}
|
| 102 |
})
|
| 103 |
.catch(error => {
|
| 104 |
-
console.error('Error loading file:', error);
|
| 105 |
-
|
|
|
|
| 106 |
});
|
| 107 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
//
|
| 110 |
const loadFileBtn = document.getElementById('load-file-btn');
|
| 111 |
if (loadFileBtn) {
|
| 112 |
loadFileBtn.addEventListener('click', function() {
|
| 113 |
const selector = document.getElementById('file-selector');
|
| 114 |
const filename = selector ? selector.value : '';
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
});
|
| 117 |
}
|
| 118 |
|
| 119 |
// Make functions globally available
|
| 120 |
window.loadFileList = loadFileList;
|
| 121 |
window.loadFileFromGitHub = loadFileFromGitHub;
|
| 122 |
-
|
| 123 |
-
// Override the default save function to ensure proper authentication
|
| 124 |
-
window.setTimeout(() => {
|
| 125 |
-
if (typeof Vvveb !== 'undefined' && Vvveb.Builder) {
|
| 126 |
-
const originalSaveAjax = Vvveb.Builder.saveAjax;
|
| 127 |
-
Vvveb.Builder.saveAjax = function(data, saveUrl, callback, error) {
|
| 128 |
-
console.log('Saving to GitHub via:', saveUrl);
|
| 129 |
-
return originalSaveAjax.call(this, data, saveUrl, callback, error);
|
| 130 |
-
};
|
| 131 |
-
|
| 132 |
-
// Add file refresh functionality
|
| 133 |
-
const originalCallback = Vvveb.Builder.saveAjax;
|
| 134 |
-
Vvveb.Builder.saveAjax = function(data, saveUrl, callback, error) {
|
| 135 |
-
return originalSaveAjax.call(this, data, saveUrl, function(result) {
|
| 136 |
-
if (callback) callback(result);
|
| 137 |
-
// Refresh file list after save
|
| 138 |
-
setTimeout(loadFileList, 1000);
|
| 139 |
-
}, error);
|
| 140 |
-
};
|
| 141 |
-
}
|
| 142 |
-
}, 2000);
|
| 143 |
});
|
| 144 |
</script>
|
| 145 |
</head>
|
|
@@ -1953,7 +2141,7 @@ Unzip the latest ckeditor release zip from https://github.com/ckeditor/ckeditor4
|
|
| 1953 |
<script src="libs/autocomplete/jquery.autocomplete.js"></script>
|
| 1954 |
-->
|
| 1955 |
<script>
|
| 1956 |
-
// Override default pages to use
|
| 1957 |
let defaultPages = {
|
| 1958 |
"blank": {
|
| 1959 |
name: "blank",
|
|
@@ -1969,10 +2157,16 @@ let defaultPages = {
|
|
| 1969 |
let pages = defaultPages;
|
| 1970 |
let firstPage = Object.keys(pages)[0];
|
| 1971 |
|
| 1972 |
-
//
|
| 1973 |
try {
|
|
|
|
|
|
|
|
|
|
| 1974 |
Vvveb.Builder.init(pages[firstPage]["url"], function() {
|
| 1975 |
console.log('VvvebJs builder initialized successfully');
|
|
|
|
|
|
|
|
|
|
| 1976 |
});
|
| 1977 |
|
| 1978 |
Vvveb.Gui.init();
|
|
@@ -1985,26 +2179,139 @@ try {
|
|
| 1985 |
Vvveb.FileManager.addPages(pages);
|
| 1986 |
Vvveb.FileManager.loadPage(pages[firstPage]["name"]);
|
| 1987 |
Vvveb.Gui.toggleRightColumn(false);
|
| 1988 |
-
Vvveb.Breadcrumb.init();
|
| 1989 |
|
| 1990 |
-
console.log('VvvebJs initialized successfully');
|
| 1991 |
} catch (error) {
|
| 1992 |
console.error('Error initializing VvvebJs:', error);
|
| 1993 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1994 |
document.body.innerHTML = `
|
| 1995 |
<div style="max-width: 600px; margin: 100px auto; padding: 40px; text-align: center; background: #f8f9fa; border-radius: 10px;">
|
| 1996 |
-
<h2>🛠️ Editor Loading
|
| 1997 |
-
<p>The visual editor
|
| 1998 |
<ul style="text-align: left; margin: 20px 0;">
|
| 1999 |
-
<li>Browser console for errors</li>
|
| 2000 |
<li>Network connectivity</li>
|
| 2001 |
-
<li>
|
|
|
|
| 2002 |
</ul>
|
| 2003 |
<a href="config.php" class="btn btn-primary" style="margin: 10px; padding: 12px 24px; background: #007bff; color: white; text-decoration: none; border-radius: 5px;">⚙️ Check Configuration</a>
|
|
|
|
| 2004 |
<a href="index.html" class="btn btn-secondary" style="margin: 10px; padding: 12px 24px; background: #6c757d; color: white; text-decoration: none; border-radius: 5px;">🏠 Return Home</a>
|
| 2005 |
</div>
|
| 2006 |
`;
|
| 2007 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2008 |
</script>
|
| 2009 |
</body>
|
| 2010 |
</html>
|
|
|
|
| 15 |
<script>
|
| 16 |
// Enhanced authentication and file loading for GitHub integration
|
| 17 |
window.addEventListener('DOMContentLoaded', function() {
|
| 18 |
+
console.log('VvvebJs Editor: Starting initialization...');
|
| 19 |
+
|
| 20 |
// Check authentication first
|
| 21 |
fetch('save.php?action=checkAuth', {
|
| 22 |
method: 'GET',
|
| 23 |
credentials: 'include'
|
| 24 |
}).then(response => {
|
| 25 |
if (response.status === 401) {
|
| 26 |
+
console.log('VvvebJs Editor: Not authenticated, redirecting to login');
|
| 27 |
window.location.href = '/';
|
| 28 |
return;
|
| 29 |
}
|
| 30 |
|
| 31 |
+
// If authenticated, proceed with initialization
|
| 32 |
+
console.log('VvvebJs Editor: Authentication verified, initializing editor...');
|
| 33 |
+
initializeEditor();
|
| 34 |
}).catch(err => {
|
| 35 |
+
console.error('VvvebJs Editor: Auth check failed:', err);
|
|
|
|
| 36 |
window.location.href = '/';
|
| 37 |
});
|
| 38 |
|
| 39 |
+
// Enhanced initialization with proper error handling
|
| 40 |
+
function initializeEditor() {
|
| 41 |
+
// Initialize VvvebJs first
|
| 42 |
+
initializeVvvebJs();
|
| 43 |
+
|
| 44 |
+
// Then load GitHub files
|
| 45 |
+
setTimeout(() => {
|
| 46 |
+
loadFileList();
|
| 47 |
+
setupGitHubIntegration();
|
| 48 |
+
}, 1000);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function initializeVvvebJs() {
|
| 52 |
+
// Wait for VvvebJs to be ready
|
| 53 |
+
let initAttempts = 0;
|
| 54 |
+
const maxInitAttempts = 50;
|
| 55 |
+
|
| 56 |
+
function waitForVvvebJs() {
|
| 57 |
+
initAttempts++;
|
| 58 |
+
|
| 59 |
+
if (typeof Vvveb !== 'undefined' && Vvveb.Builder) {
|
| 60 |
+
console.log('VvvebJs Editor: VvvebJs is ready');
|
| 61 |
+
|
| 62 |
+
// Initialize with a blank template first
|
| 63 |
+
if (Vvveb.Builder.init) {
|
| 64 |
+
try {
|
| 65 |
+
Vvveb.Builder.init('new-page-blank-template.html', function() {
|
| 66 |
+
console.log('VvvebJs Editor: Builder initialized successfully');
|
| 67 |
+
|
| 68 |
+
// After a short delay, try to load GitHub files
|
| 69 |
+
setTimeout(loadGitHubFilesWithFallback, 2000);
|
| 70 |
+
});
|
| 71 |
+
} catch (error) {
|
| 72 |
+
console.error('VvvebJs Editor: Builder init error:', error);
|
| 73 |
+
// Fallback initialization
|
| 74 |
+
setTimeout(loadGitHubFilesWithFallback, 3000);
|
| 75 |
+
}
|
| 76 |
+
} else {
|
| 77 |
+
console.warn('VvvebJs Editor: Builder.init not available, using fallback');
|
| 78 |
+
setTimeout(loadGitHubFilesWithFallback, 2000);
|
| 79 |
+
}
|
| 80 |
+
} else if (initAttempts < maxInitAttempts) {
|
| 81 |
+
console.log(`VvvebJs Editor: Waiting for VvvebJs... (attempt ${initAttempts}/${maxInitAttempts})`);
|
| 82 |
+
setTimeout(waitForVvvebJs, 200);
|
| 83 |
+
} else {
|
| 84 |
+
console.error('VvvebJs Editor: Timeout waiting for VvvebJs, trying fallback');
|
| 85 |
+
loadGitHubFilesWithFallback();
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
waitForVvvebJs();
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
function setupGitHubIntegration() {
|
| 93 |
+
// Override save function to work with GitHub
|
| 94 |
+
if (typeof Vvveb !== 'undefined' && Vvveb.Builder && Vvveb.Builder.saveAjax) {
|
| 95 |
+
const originalSaveAjax = Vvveb.Builder.saveAjax;
|
| 96 |
+
Vvveb.Builder.saveAjax = function(data, saveUrl, callback, error) {
|
| 97 |
+
console.log('VvvebJs Editor: Saving to GitHub via:', saveUrl);
|
| 98 |
+
|
| 99 |
+
return originalSaveAjax.call(this, data, saveUrl, function(result) {
|
| 100 |
+
console.log('VvvebJs Editor: Save completed successfully');
|
| 101 |
+
if (callback) callback(result);
|
| 102 |
+
// Refresh file list after successful save
|
| 103 |
+
setTimeout(loadFileList, 1000);
|
| 104 |
+
}, function(err) {
|
| 105 |
+
console.error('VvvebJs Editor: Save failed:', err);
|
| 106 |
+
if (error) error(err);
|
| 107 |
+
});
|
| 108 |
+
};
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// Load GitHub files with multiple fallback strategies
|
| 113 |
+
function loadGitHubFilesWithFallback() {
|
| 114 |
+
console.log('VvvebJs Editor: Loading GitHub files with fallback...');
|
| 115 |
+
|
| 116 |
+
// Strategy 1: Check URL parameter first
|
| 117 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 118 |
+
const fileParam = urlParams.get('file');
|
| 119 |
+
|
| 120 |
+
if (fileParam) {
|
| 121 |
+
console.log('VvvebJs Editor: Loading file from URL parameter:', fileParam);
|
| 122 |
+
loadFileFromGitHub(fileParam);
|
| 123 |
+
return;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// Strategy 2: Load first available GitHub file
|
| 127 |
+
loadFirstAvailableFile();
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
async function loadFirstAvailableFile() {
|
| 131 |
+
try {
|
| 132 |
+
console.log('VvvebJs Editor: Fetching GitHub files...');
|
| 133 |
+
const response = await fetch('save.php?action=listFiles');
|
| 134 |
+
const data = await response.json();
|
| 135 |
+
|
| 136 |
+
console.log('VvvebJs Editor: GitHub files response:', data);
|
| 137 |
+
|
| 138 |
+
if (data.success && data.files && data.files.length > 0) {
|
| 139 |
+
const firstFile = data.files[0];
|
| 140 |
+
const filename = firstFile.name || firstFile.filename || firstFile.path;
|
| 141 |
+
|
| 142 |
+
if (filename) {
|
| 143 |
+
console.log('VvvebJs Editor: Auto-loading first GitHub file:', filename);
|
| 144 |
+
setTimeout(() => loadFileFromGitHub(filename), 500);
|
| 145 |
+
} else {
|
| 146 |
+
console.warn('VvvebJs Editor: First file has no valid name');
|
| 147 |
+
showWelcomeMessage();
|
| 148 |
+
}
|
| 149 |
+
} else {
|
| 150 |
+
console.log('VvvebJs Editor: No GitHub files found:', data.message);
|
| 151 |
+
showWelcomeMessage();
|
| 152 |
+
}
|
| 153 |
+
} catch (error) {
|
| 154 |
+
console.error('VvvebJs Editor: Error loading GitHub files:', error);
|
| 155 |
+
showWelcomeMessage();
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
function showWelcomeMessage() {
|
| 160 |
+
console.log('VvvebJs Editor: Showing welcome message for new user');
|
| 161 |
+
setTimeout(() => {
|
| 162 |
+
showSuccessMessage('Welcome! No files found. Create your first page by clicking SAVE.');
|
| 163 |
+
}, 1000);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
// GitHub-aware file loading functionality
|
| 167 |
function loadFileList() {
|
| 168 |
+
console.log('VvvebJs Editor: Loading file list...');
|
| 169 |
+
|
| 170 |
fetch('save.php?action=listFiles')
|
| 171 |
+
.then(response => {
|
| 172 |
+
console.log('VvvebJs Editor: File list response status:', response.status);
|
| 173 |
+
return response.json();
|
| 174 |
+
})
|
| 175 |
.then(data => {
|
| 176 |
+
console.log('VvvebJs Editor: File list response:', data);
|
| 177 |
const selector = document.getElementById('file-selector');
|
| 178 |
if (selector) {
|
| 179 |
selector.innerHTML = '<option value="">Select a file...</option>';
|
|
|
|
| 181 |
if (data.success && data.files && data.files.length > 0) {
|
| 182 |
data.files.forEach(file => {
|
| 183 |
const option = document.createElement('option');
|
| 184 |
+
const filename = file.name || file.filename || file.path;
|
| 185 |
+
option.value = filename;
|
| 186 |
+
option.textContent = (filename || 'Untitled').replace('.html', '');
|
| 187 |
selector.appendChild(option);
|
| 188 |
});
|
| 189 |
|
| 190 |
+
console.log(`VvvebJs Editor: Loaded ${data.files.length} files for user: ${data.user}`);
|
| 191 |
+
updateFileCount(data.files.length);
|
| 192 |
} else {
|
| 193 |
+
console.log('VvvebJs Editor: No files found. Response:', data);
|
| 194 |
+
updateFileCount(0);
|
| 195 |
+
|
| 196 |
+
// Show helpful message if no files
|
| 197 |
+
if (data.message && !data.message.includes('No files found')) {
|
| 198 |
+
showErrorMessage(`GitHub Error: ${data.message}`);
|
| 199 |
+
}
|
| 200 |
}
|
| 201 |
}
|
| 202 |
})
|
| 203 |
.catch(error => {
|
| 204 |
+
console.error('VvvebJs Editor: Error loading file list:', error);
|
| 205 |
+
showErrorMessage('Failed to load file list. Check your GitHub configuration.');
|
| 206 |
});
|
| 207 |
}
|
| 208 |
|
| 209 |
+
// Enhanced file loading with better error handling and retries
|
| 210 |
function loadFileFromGitHub(filename) {
|
| 211 |
if (!filename) {
|
| 212 |
+
showErrorMessage('Please select a file to load');
|
| 213 |
return;
|
| 214 |
}
|
| 215 |
|
| 216 |
+
console.log('VvvebJs Editor: Loading file from GitHub:', filename);
|
| 217 |
+
showLoadingIndicator(true);
|
| 218 |
|
| 219 |
fetch(`save.php?action=loadFile&file=${encodeURIComponent(filename)}`)
|
| 220 |
+
.then(response => {
|
| 221 |
+
console.log('VvvebJs Editor: Load file response status:', response.status);
|
| 222 |
+
if (!response.ok) {
|
| 223 |
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
| 224 |
+
}
|
| 225 |
+
return response.json();
|
| 226 |
+
})
|
| 227 |
.then(data => {
|
| 228 |
+
console.log('VvvebJs Editor: Load file response:', data);
|
| 229 |
+
showLoadingIndicator(false);
|
| 230 |
+
|
| 231 |
+
if (data.success && data.content) {
|
| 232 |
+
// Ensure VvvebJs is ready before loading content
|
| 233 |
+
if (typeof Vvveb !== 'undefined' && Vvveb.Builder && Vvveb.Builder.loadHtml) {
|
| 234 |
+
try {
|
| 235 |
+
Vvveb.Builder.loadHtml(data.content);
|
| 236 |
+
console.log('VvvebJs Editor: File loaded successfully from GitHub');
|
| 237 |
+
|
| 238 |
+
// Update current file reference
|
| 239 |
+
window.currentFile = filename;
|
| 240 |
+
|
| 241 |
+
// Update file selector
|
| 242 |
+
const selector = document.getElementById('file-selector');
|
| 243 |
+
if (selector) {
|
| 244 |
+
selector.value = filename;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
showSuccessMessage(`File "${filename}" loaded successfully`);
|
| 248 |
+
} catch (error) {
|
| 249 |
+
console.error('VvvebJs Editor: Error loading HTML into builder:', error);
|
| 250 |
+
showErrorMessage('Error loading file content into editor');
|
| 251 |
}
|
| 252 |
} else {
|
| 253 |
+
console.warn('VvvebJs Editor: VvvebJs not ready yet, retrying in 1 second...');
|
| 254 |
setTimeout(() => loadFileFromGitHub(filename), 1000);
|
| 255 |
}
|
| 256 |
} else {
|
| 257 |
+
const errorMsg = data.message || 'Unknown error loading file';
|
| 258 |
+
console.error('VvvebJs Editor: File load failed:', errorMsg);
|
| 259 |
+
showErrorMessage('Error loading file: ' + errorMsg);
|
| 260 |
}
|
| 261 |
})
|
| 262 |
.catch(error => {
|
| 263 |
+
console.error('VvvebJs Editor: Error loading file:', error);
|
| 264 |
+
showLoadingIndicator(false);
|
| 265 |
+
showErrorMessage('Error loading file from GitHub: ' + error.message);
|
| 266 |
});
|
| 267 |
}
|
| 268 |
+
|
| 269 |
+
// UI helper functions
|
| 270 |
+
function showLoadingIndicator(show) {
|
| 271 |
+
const indicator = document.querySelector('.loading-message');
|
| 272 |
+
if (indicator) {
|
| 273 |
+
indicator.style.display = show ? 'block' : 'none';
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
function showErrorMessage(message) {
|
| 278 |
+
console.error('VvvebJs Editor:', message);
|
| 279 |
+
const toast = document.createElement('div');
|
| 280 |
+
toast.className = 'alert alert-danger';
|
| 281 |
+
toast.style.cssText = 'position: fixed; top: 20px; right: 20px; z-index: 9999; max-width: 400px;';
|
| 282 |
+
toast.innerHTML = `<strong>Error:</strong> ${message}`;
|
| 283 |
+
document.body.appendChild(toast);
|
| 284 |
+
setTimeout(() => toast.remove(), 5000);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
function showSuccessMessage(message) {
|
| 288 |
+
console.log('VvvebJs Editor:', message);
|
| 289 |
+
const toast = document.createElement('div');
|
| 290 |
+
toast.className = 'alert alert-success';
|
| 291 |
+
toast.style.cssText = 'position: fixed; top: 20px; right: 20px; z-index: 9999; max-width: 400px;';
|
| 292 |
+
toast.innerHTML = `<strong>Success:</strong> ${message}`;
|
| 293 |
+
document.body.appendChild(toast);
|
| 294 |
+
setTimeout(() => toast.remove(), 3000);
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
function updateFileCount(count) {
|
| 298 |
+
const fileCountElement = document.querySelector('.file-count');
|
| 299 |
+
if (fileCountElement) {
|
| 300 |
+
fileCountElement.textContent = `${count} files`;
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
|
| 304 |
+
// Event listeners for file operations
|
| 305 |
const loadFileBtn = document.getElementById('load-file-btn');
|
| 306 |
if (loadFileBtn) {
|
| 307 |
loadFileBtn.addEventListener('click', function() {
|
| 308 |
const selector = document.getElementById('file-selector');
|
| 309 |
const filename = selector ? selector.value : '';
|
| 310 |
+
if (filename) {
|
| 311 |
+
loadFileFromGitHub(filename);
|
| 312 |
+
} else {
|
| 313 |
+
showErrorMessage('Please select a file from the dropdown first');
|
| 314 |
+
}
|
| 315 |
+
});
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
const fileSelector = document.getElementById('file-selector');
|
| 319 |
+
if (fileSelector) {
|
| 320 |
+
fileSelector.addEventListener('change', function() {
|
| 321 |
+
const filename = this.value;
|
| 322 |
+
if (filename) {
|
| 323 |
+
loadFileFromGitHub(filename);
|
| 324 |
+
}
|
| 325 |
});
|
| 326 |
}
|
| 327 |
|
| 328 |
// Make functions globally available
|
| 329 |
window.loadFileList = loadFileList;
|
| 330 |
window.loadFileFromGitHub = loadFileFromGitHub;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
});
|
| 332 |
</script>
|
| 333 |
</head>
|
|
|
|
| 2141 |
<script src="libs/autocomplete/jquery.autocomplete.js"></script>
|
| 2142 |
-->
|
| 2143 |
<script>
|
| 2144 |
+
// Override default pages to use GitHub-loaded pages
|
| 2145 |
let defaultPages = {
|
| 2146 |
"blank": {
|
| 2147 |
name: "blank",
|
|
|
|
| 2157 |
let pages = defaultPages;
|
| 2158 |
let firstPage = Object.keys(pages)[0];
|
| 2159 |
|
| 2160 |
+
// Enhanced initialization with GitHub integration
|
| 2161 |
try {
|
| 2162 |
+
console.log('VvvebJs: Starting editor initialization...');
|
| 2163 |
+
|
| 2164 |
+
// Initialize builder with default template first
|
| 2165 |
Vvveb.Builder.init(pages[firstPage]["url"], function() {
|
| 2166 |
console.log('VvvebJs builder initialized successfully');
|
| 2167 |
+
|
| 2168 |
+
// After builder initialization, load GitHub files
|
| 2169 |
+
loadGitHubPages();
|
| 2170 |
});
|
| 2171 |
|
| 2172 |
Vvveb.Gui.init();
|
|
|
|
| 2179 |
Vvveb.FileManager.addPages(pages);
|
| 2180 |
Vvveb.FileManager.loadPage(pages[firstPage]["name"]);
|
| 2181 |
Vvveb.Gui.toggleRightColumn(false);
|
|
|
|
| 2182 |
|
| 2183 |
+
console.log('VvvebJs core components initialized successfully');
|
| 2184 |
} catch (error) {
|
| 2185 |
console.error('Error initializing VvvebJs:', error);
|
| 2186 |
+
showErrorFallback();
|
| 2187 |
+
}
|
| 2188 |
+
|
| 2189 |
+
// Load pages from GitHub and integrate with VvvebJs
|
| 2190 |
+
async function loadGitHubPages() {
|
| 2191 |
+
try {
|
| 2192 |
+
console.log('VvvebJs: Loading pages from GitHub...');
|
| 2193 |
+
|
| 2194 |
+
const response = await fetch('save.php?action=listFiles');
|
| 2195 |
+
const data = await response.json();
|
| 2196 |
+
|
| 2197 |
+
if (data.success && data.files && data.files.length > 0) {
|
| 2198 |
+
console.log(`VvvebJs: Found ${data.files.length} GitHub files`);
|
| 2199 |
+
|
| 2200 |
+
// Convert GitHub files to VvvebJs page format
|
| 2201 |
+
const gitHubPages = {};
|
| 2202 |
+
data.files.forEach((file, index) => {
|
| 2203 |
+
const pageKey = file.name.replace('.html', '') || `page_${index}`;
|
| 2204 |
+
gitHubPages[pageKey] = {
|
| 2205 |
+
name: pageKey,
|
| 2206 |
+
filename: file.name,
|
| 2207 |
+
file: file.path || file.name,
|
| 2208 |
+
url: file.url || `user-files/${file.name}`,
|
| 2209 |
+
title: file.name.replace('.html', '').replace(/[-_]/g, ' '),
|
| 2210 |
+
folder: file.folder || null,
|
| 2211 |
+
description: `GitHub file: ${file.name}`
|
| 2212 |
+
};
|
| 2213 |
+
});
|
| 2214 |
+
|
| 2215 |
+
// Add GitHub pages to VvvebJs
|
| 2216 |
+
if (Object.keys(gitHubPages).length > 0) {
|
| 2217 |
+
pages = { ...defaultPages, ...gitHubPages };
|
| 2218 |
+
Vvveb.FileManager.addPages(gitHubPages);
|
| 2219 |
+
|
| 2220 |
+
// Auto-load first GitHub file if available
|
| 2221 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 2222 |
+
const fileParam = urlParams.get('file');
|
| 2223 |
+
|
| 2224 |
+
if (fileParam) {
|
| 2225 |
+
// Load specific file from URL parameter
|
| 2226 |
+
const targetPage = Object.values(pages).find(p =>
|
| 2227 |
+
p.filename === fileParam || p.file === fileParam
|
| 2228 |
+
);
|
| 2229 |
+
if (targetPage) {
|
| 2230 |
+
console.log('VvvebJs: Loading file from URL parameter:', fileParam);
|
| 2231 |
+
loadGitHubFile(fileParam);
|
| 2232 |
+
}
|
| 2233 |
+
} else {
|
| 2234 |
+
// Auto-load first GitHub file
|
| 2235 |
+
const firstGitHubPage = Object.keys(gitHubPages)[0];
|
| 2236 |
+
if (firstGitHubPage) {
|
| 2237 |
+
console.log('VvvebJs: Auto-loading first GitHub file:', gitHubPages[firstGitHubPage].filename);
|
| 2238 |
+
setTimeout(() => {
|
| 2239 |
+
loadGitHubFile(gitHubPages[firstGitHubPage].filename);
|
| 2240 |
+
}, 1000);
|
| 2241 |
+
}
|
| 2242 |
+
}
|
| 2243 |
+
}
|
| 2244 |
+
|
| 2245 |
+
} else {
|
| 2246 |
+
console.log('VvvebJs: No GitHub files found or error:', data.message);
|
| 2247 |
+
}
|
| 2248 |
+
|
| 2249 |
+
} catch (error) {
|
| 2250 |
+
console.error('VvvebJs: Error loading GitHub pages:', error);
|
| 2251 |
+
}
|
| 2252 |
+
}
|
| 2253 |
+
|
| 2254 |
+
// Load specific file from GitHub
|
| 2255 |
+
async function loadGitHubFile(filename) {
|
| 2256 |
+
try {
|
| 2257 |
+
console.log('VvvebJs: Loading GitHub file:', filename);
|
| 2258 |
+
|
| 2259 |
+
const response = await fetch(`save.php?action=loadFile&file=${encodeURIComponent(filename)}`);
|
| 2260 |
+
const data = await response.json();
|
| 2261 |
+
|
| 2262 |
+
if (data.success && data.content) {
|
| 2263 |
+
// Load content into VvvebJs builder
|
| 2264 |
+
Vvveb.Builder.loadHtml(data.content);
|
| 2265 |
+
console.log('VvvebJs: GitHub file loaded successfully:', filename);
|
| 2266 |
+
|
| 2267 |
+
// Update file manager selection
|
| 2268 |
+
const pageKey = filename.replace('.html', '');
|
| 2269 |
+
if (pages[pageKey]) {
|
| 2270 |
+
Vvveb.FileManager.loadPage(pageKey);
|
| 2271 |
+
}
|
| 2272 |
+
|
| 2273 |
+
// Update UI elements
|
| 2274 |
+
updateFileSelector(filename);
|
| 2275 |
+
|
| 2276 |
+
} else {
|
| 2277 |
+
console.error('VvvebJs: Failed to load GitHub file:', data.message);
|
| 2278 |
+
}
|
| 2279 |
+
|
| 2280 |
+
} catch (error) {
|
| 2281 |
+
console.error('VvvebJs: Error loading GitHub file:', error);
|
| 2282 |
+
}
|
| 2283 |
+
}
|
| 2284 |
+
|
| 2285 |
+
// Update file selector dropdown
|
| 2286 |
+
function updateFileSelector(selectedFile) {
|
| 2287 |
+
const selector = document.getElementById('file-selector');
|
| 2288 |
+
if (selector) {
|
| 2289 |
+
selector.value = selectedFile;
|
| 2290 |
+
}
|
| 2291 |
+
}
|
| 2292 |
+
|
| 2293 |
+
// Error fallback display
|
| 2294 |
+
function showErrorFallback() {
|
| 2295 |
document.body.innerHTML = `
|
| 2296 |
<div style="max-width: 600px; margin: 100px auto; padding: 40px; text-align: center; background: #f8f9fa; border-radius: 10px;">
|
| 2297 |
+
<h2>🛠️ Editor Loading Error</h2>
|
| 2298 |
+
<p>The visual editor failed to initialize. Please check:</p>
|
| 2299 |
<ul style="text-align: left; margin: 20px 0;">
|
| 2300 |
+
<li>Browser console for detailed errors</li>
|
| 2301 |
<li>Network connectivity</li>
|
| 2302 |
+
<li>GitHub configuration in .env file</li>
|
| 2303 |
+
<li>Required JavaScript files are present</li>
|
| 2304 |
</ul>
|
| 2305 |
<a href="config.php" class="btn btn-primary" style="margin: 10px; padding: 12px 24px; background: #007bff; color: white; text-decoration: none; border-radius: 5px;">⚙️ Check Configuration</a>
|
| 2306 |
+
<a href="dashboard.html" class="btn btn-secondary" style="margin: 10px; padding: 12px 24px; background: #6c757d; color: white; text-decoration: none; border-radius: 5px;">📊 Dashboard</a>
|
| 2307 |
<a href="index.html" class="btn btn-secondary" style="margin: 10px; padding: 12px 24px; background: #6c757d; color: white; text-decoration: none; border-radius: 5px;">🏠 Return Home</a>
|
| 2308 |
</div>
|
| 2309 |
`;
|
| 2310 |
}
|
| 2311 |
+
|
| 2312 |
+
// Make functions globally available
|
| 2313 |
+
window.loadGitHubPages = loadGitHubPages;
|
| 2314 |
+
window.loadGitHubFile = loadGitHubFile;
|
| 2315 |
</script>
|
| 2316 |
</body>
|
| 2317 |
</html>
|
validate-github.bat
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
title GitHub Token 验证工具
|
| 3 |
+
chcp 65001 > nul
|
| 4 |
+
|
| 5 |
+
echo.
|
| 6 |
+
echo ============================================
|
| 7 |
+
echo GitHub Token 快速验证工具
|
| 8 |
+
echo ============================================
|
| 9 |
+
echo.
|
| 10 |
+
|
| 11 |
+
REM 检查环境变量文件
|
| 12 |
+
if not exist ".env" (
|
| 13 |
+
echo ❌ 错误: 找不到 .env 文件
|
| 14 |
+
echo 请确保在项目根目录运行此脚本
|
| 15 |
+
pause
|
| 16 |
+
exit /b 1
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
REM 读取环境变量
|
| 20 |
+
for /f "tokens=1,2 delims==" %%A in ('type .env ^| findstr GITHUB_') do (
|
| 21 |
+
set %%A=%%B
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
echo 📋 当前配置:
|
| 25 |
+
echo Token: %GITHUB_TOKEN:~0,8%...
|
| 26 |
+
echo Owner: %GITHUB_OWNER%
|
| 27 |
+
echo Repo: %GITHUB_REPO%
|
| 28 |
+
echo Branch: %GITHUB_BRANCH%
|
| 29 |
+
echo.
|
| 30 |
+
|
| 31 |
+
REM 检查必要参数
|
| 32 |
+
if "%GITHUB_TOKEN%"=="YOUR_ACTUAL_GITHUB_TOKEN" (
|
| 33 |
+
echo ❌ 致命错误: GitHub Token 尚未配置
|
| 34 |
+
echo.
|
| 35 |
+
echo 请按照以下步骤配置 GitHub Token:
|
| 36 |
+
echo 1. 访问 https://github.com/settings/tokens
|
| 37 |
+
echo 2. 点击 "Generate new token" → "Generate new token (classic)"
|
| 38 |
+
echo 3. 选择权限: repo (完整仓库访问权限)
|
| 39 |
+
echo 4. 复制生成的 token
|
| 40 |
+
echo 5. 在 .env 文件中替换 YOUR_ACTUAL_GITHUB_TOKEN
|
| 41 |
+
echo.
|
| 42 |
+
pause
|
| 43 |
+
exit /b 1
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
echo 🔑 测试1: 验证 GitHub Token...
|
| 47 |
+
curl -s -H "Authorization: token %GITHUB_TOKEN%" -H "User-Agent: VvvebJs-Test" https://api.github.com/user > temp_user.json
|
| 48 |
+
findstr "login" temp_user.json >nul
|
| 49 |
+
if %errorlevel%==0 (
|
| 50 |
+
echo ✅ Token 有效
|
| 51 |
+
) else (
|
| 52 |
+
echo ❌ Token 无效或过期
|
| 53 |
+
type temp_user.json
|
| 54 |
+
del temp_user.json
|
| 55 |
+
pause
|
| 56 |
+
exit /b 1
|
| 57 |
+
)
|
| 58 |
+
del temp_user.json
|
| 59 |
+
|
| 60 |
+
echo.
|
| 61 |
+
echo 📁 测试2: 检查仓库访问...
|
| 62 |
+
curl -s -H "Authorization: token %GITHUB_TOKEN%" -H "User-Agent: VvvebJs-Test" https://api.github.com/repos/%GITHUB_OWNER%/%GITHUB_REPO% > temp_repo.json
|
| 63 |
+
findstr "full_name" temp_repo.json >nul
|
| 64 |
+
if %errorlevel%==0 (
|
| 65 |
+
echo ✅ 仓库可访问
|
| 66 |
+
) else (
|
| 67 |
+
echo ❌ 仓库不存在或无权限访问
|
| 68 |
+
type temp_repo.json
|
| 69 |
+
del temp_repo.json
|
| 70 |
+
pause
|
| 71 |
+
exit /b 1
|
| 72 |
+
)
|
| 73 |
+
del temp_repo.json
|
| 74 |
+
|
| 75 |
+
echo.
|
| 76 |
+
echo 🌿 测试3: 检查分支...
|
| 77 |
+
curl -s -H "Authorization: token %GITHUB_TOKEN%" -H "User-Agent: VvvebJs-Test" https://api.github.com/repos/%GITHUB_OWNER%/%GITHUB_REPO%/branches/%GITHUB_BRANCH% > temp_branch.json
|
| 78 |
+
findstr "name" temp_branch.json >nul
|
| 79 |
+
if %errorlevel%==0 (
|
| 80 |
+
echo ✅ 分支 '%GITHUB_BRANCH%' 存在
|
| 81 |
+
) else (
|
| 82 |
+
echo ⚠️ 分支 '%GITHUB_BRANCH%' 不存在,检查 'master' 分支...
|
| 83 |
+
curl -s -H "Authorization: token %GITHUB_TOKEN%" -H "User-Agent: VvvebJs-Test" https://api.github.com/repos/%GITHUB_OWNER%/%GITHUB_REPO%/branches/master > temp_master.json
|
| 84 |
+
findstr "name" temp_master.json >nul
|
| 85 |
+
if %errorlevel%==0 (
|
| 86 |
+
echo ✅ 分支 'master' 存在,建议修改 .env 中的 GITHUB_BRANCH=master
|
| 87 |
+
del temp_master.json
|
| 88 |
+
) else (
|
| 89 |
+
echo ❌ 主分支不存在
|
| 90 |
+
del temp_master.json
|
| 91 |
+
)
|
| 92 |
+
)
|
| 93 |
+
if exist temp_branch.json del temp_branch.json
|
| 94 |
+
|
| 95 |
+
echo.
|
| 96 |
+
echo 🎉 GitHub 连接测试完成!
|
| 97 |
+
echo.
|
| 98 |
+
echo 如果所有测试都通过,您现在可以:
|
| 99 |
+
echo 1. 访问 http://localhost/editor.html 打开编辑器
|
| 100 |
+
echo 2. 登录并开始创建页面
|
| 101 |
+
echo.
|
| 102 |
+
pause
|