-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.html
More file actions
304 lines (269 loc) · 11.6 KB
/
debug.html
File metadata and controls
304 lines (269 loc) · 11.6 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Note.Lab Debug</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #0d1117;
color: #c9d1d9;
}
.debug-section {
background: #161b22;
border: 1px solid #30363d;
border-radius: 6px;
padding: 20px;
margin: 20px 0;
}
.debug-title {
font-size: 18px;
font-weight: 600;
margin-bottom: 15px;
color: #58a6ff;
}
.debug-content {
background: #0d1117;
border: 1px solid #30363d;
border-radius: 4px;
padding: 15px;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 12px;
white-space: pre-wrap;
max-height: 300px;
overflow-y: auto;
}
.status {
padding: 8px 12px;
border-radius: 4px;
margin: 5px 0;
font-weight: 500;
}
.status.success { background: #238636; color: white; }
.status.error { background: #da3633; color: white; }
.status.warning { background: #f0883e; color: white; }
.status.info { background: #58a6ff; color: white; }
button {
background: #238636;
color: white;
border: none;
padding: 10px 20px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
margin: 5px;
}
button:hover { background: #2ea043; }
button:disabled { background: #30363d; cursor: not-allowed; }
.test-results {
margin-top: 10px;
}
</style>
</head>
<body>
<h1>🔧 Note.Lab Debug Console</h1>
<div class="debug-section">
<div class="debug-title">Authentication Status</div>
<div id="authStatus" class="status info">Checking...</div>
<button onclick="checkAuth()">Check Authentication</button>
<button onclick="logout()">Logout</button>
</div>
<div class="debug-section">
<div class="debug-title">Notes API Test</div>
<div id="notesStatus" class="status info">Ready to test</div>
<button onclick="testNotesAPI()">Test Notes API</button>
<button onclick="createTestNote()">Create Test Note</button>
<button onclick="loadNotes()">Load Notes</button>
<div id="notesResults" class="test-results"></div>
</div>
<div class="debug-section">
<div class="debug-title">Local Storage</div>
<div id="localStorageContent" class="debug-content">Loading...</div>
<button onclick="refreshLocalStorage()">Refresh</button>
<button onclick="clearLocalStorage()">Clear All</button>
</div>
<div class="debug-section">
<div class="debug-title">Console Output</div>
<div id="consoleOutput" class="debug-content">Debug output will appear here...</div>
<button onclick="clearConsole()">Clear Console</button>
</div>
<script src="frontend/js/api-config.js"></script>
<script>
// Capture console output
const originalLog = console.log;
const originalError = console.error;
const consoleOutput = document.getElementById('consoleOutput');
function addToConsole(type, ...args) {
const timestamp = new Date().toLocaleTimeString();
const message = args.map(arg =>
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)
).join(' ');
consoleOutput.textContent += `[${timestamp}] ${type.toUpperCase()}: ${message}\n`;
consoleOutput.scrollTop = consoleOutput.scrollHeight;
}
console.log = (...args) => {
originalLog.apply(console, args);
addToConsole('log', ...args);
};
console.error = (...args) => {
originalError.apply(console, args);
addToConsole('error', ...args);
};
// Debug functions
async function checkAuth() {
const authStatus = document.getElementById('authStatus');
authStatus.textContent = 'Checking authentication...';
authStatus.className = 'status info';
try {
if (!window.api) {
throw new Error('API not available');
}
const response = await window.api.getProfile();
if (response.success) {
authStatus.textContent = `✅ Authenticated as ${response.data.user.name || response.data.user.email}`;
authStatus.className = 'status success';
} else {
authStatus.textContent = '❌ Authentication failed';
authStatus.className = 'status error';
}
} catch (error) {
authStatus.textContent = `❌ Auth error: ${error.message}`;
authStatus.className = 'status error';
}
}
async function testNotesAPI() {
const notesStatus = document.getElementById('notesStatus');
const results = document.getElementById('notesResults');
notesStatus.textContent = 'Testing Notes API...';
notesStatus.className = 'status info';
results.innerHTML = '';
try {
if (!window.api) {
throw new Error('API not available');
}
const response = await window.api.getNotes();
if (response.success) {
notesStatus.textContent = `✅ Notes API working - ${response.data.notes.length} notes found`;
notesStatus.className = 'status success';
results.innerHTML = `<div class="status info">Notes loaded successfully</div>`;
} else {
notesStatus.textContent = '❌ Notes API failed';
notesStatus.className = 'status error';
results.innerHTML = `<div class="status error">Error: ${response.message}</div>`;
}
} catch (error) {
notesStatus.textContent = '❌ Notes API error';
notesStatus.className = 'status error';
results.innerHTML = `<div class="status error">Error: ${error.message}</div>`;
}
}
async function createTestNote() {
const notesStatus = document.getElementById('notesStatus');
const results = document.getElementById('notesResults');
notesStatus.textContent = 'Creating test note...';
notesStatus.className = 'status info';
try {
if (!window.api) {
throw new Error('API not available');
}
const testNote = {
title: 'Debug Test Note',
content: 'This is a test note created at ' + new Date().toISOString(),
type: 'standard',
starred: false,
tags: ['debug', 'test'],
metadata: { debug: true }
};
const response = await window.api.createNote(testNote);
if (response.success) {
notesStatus.textContent = '✅ Test note created successfully';
notesStatus.className = 'status success';
results.innerHTML = `<div class="status success">Note created with ID: ${response.data.note.id}</div>`;
} else {
notesStatus.textContent = '❌ Failed to create test note';
notesStatus.className = 'status error';
results.innerHTML = `<div class="status error">Error: ${response.message}</div>`;
}
} catch (error) {
notesStatus.textContent = '❌ Create note error';
notesStatus.className = 'status error';
results.innerHTML = `<div class="status error">Error: ${error.message}</div>`;
}
}
async function loadNotes() {
const notesStatus = document.getElementById('notesStatus');
const results = document.getElementById('notesResults');
notesStatus.textContent = 'Loading notes...';
notesStatus.className = 'status info';
try {
if (!window.api) {
throw new Error('API not available');
}
const response = await window.api.getNotes();
if (response.success) {
notesStatus.textContent = `✅ Loaded ${response.data.notes.length} notes`;
notesStatus.className = 'status success';
const notesList = response.data.notes.map(note =>
`- ${note.title} (${note.type}) - ${new Date(note.updatedAt).toLocaleString()}`
).join('\n');
results.innerHTML = `<div class="status info">Notes:\n${notesList}</div>`;
} else {
notesStatus.textContent = '❌ Failed to load notes';
notesStatus.className = 'status error';
results.innerHTML = `<div class="status error">Error: ${response.message}</div>`;
}
} catch (error) {
notesStatus.textContent = '❌ Load notes error';
notesStatus.className = 'status error';
results.innerHTML = `<div class="status error">Error: ${error.message}</div>`;
}
}
function refreshLocalStorage() {
const content = document.getElementById('localStorageContent');
const keys = ['notelab_token', 'notelab_user', 'notelab_session', 'notelab_notes'];
let output = '';
keys.forEach(key => {
const value = localStorage.getItem(key);
output += `${key}:\n`;
if (value) {
try {
const parsed = JSON.parse(value);
output += JSON.stringify(parsed, null, 2);
} catch (e) {
output += value;
}
} else {
output += ' (not set)\n';
}
output += '\n\n';
});
content.textContent = output;
}
function clearLocalStorage() {
if (confirm('Are you sure you want to clear all local storage? This will log you out.')) {
localStorage.clear();
refreshLocalStorage();
console.log('Local storage cleared');
}
}
function logout() {
if (window.api) {
window.api.logout();
}
localStorage.clear();
window.location.href = '/login.html';
}
function clearConsole() {
consoleOutput.textContent = '';
}
// Auto-refresh localStorage on load
refreshLocalStorage();
// Auto-check auth on load
setTimeout(checkAuth, 1000);
</script>
</body>
</html>