Skip to content

Commit 1bd9dcd

Browse files
committed
fix 24
1 parent a2878a1 commit 1bd9dcd

File tree

2 files changed

+298
-13
lines changed

2 files changed

+298
-13
lines changed

debug-network.html

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=240, initial-scale=1.0, user-scalable=no">
6+
<title>Network Debug</title>
7+
<style>
8+
body {
9+
width: 240px;
10+
height: 282px;
11+
font-family: 'Courier New', monospace;
12+
font-size: 12px;
13+
background: #000;
14+
color: #fff;
15+
overflow: hidden;
16+
position: relative;
17+
border: 3px solid #ff0;
18+
padding: 10px;
19+
}
20+
21+
.debug-container {
22+
display: flex;
23+
flex-direction: column;
24+
height: 100%;
25+
}
26+
27+
.status-box {
28+
border: 2px solid #0f0;
29+
padding: 10px;
30+
margin-bottom: 10px;
31+
min-height: 60px;
32+
background: #111;
33+
}
34+
35+
.action-button {
36+
padding: 10px;
37+
background: #f00;
38+
color: #fff;
39+
border: 3px solid #0f0;
40+
font-family: 'Courier New', monospace;
41+
font-size: 12px;
42+
font-weight: bold;
43+
cursor: pointer;
44+
margin-bottom: 10px;
45+
text-transform: uppercase;
46+
}
47+
48+
.action-button:hover {
49+
background: #ff0;
50+
color: #000;
51+
}
52+
53+
.log-area {
54+
flex: 1;
55+
border: 2px solid #0f0;
56+
padding: 5px;
57+
overflow-y: auto;
58+
background: #111;
59+
font-size: 10px;
60+
white-space: pre-wrap;
61+
}
62+
</style>
63+
</head>
64+
<body>
65+
<div class="debug-container">
66+
<h2>Network Debug</h2>
67+
68+
<div class="status-box" id="status">
69+
Ready to test
70+
</div>
71+
72+
<button class="action-button" id="testNetwork">Test Network</button>
73+
<button class="action-button" id="testCatbox">Test Catbox Upload</button>
74+
75+
<div class="log-area" id="log">
76+
Logs will appear here...
77+
</div>
78+
</div>
79+
80+
<script>
81+
const statusEl = document.getElementById('status');
82+
const logEl = document.getElementById('log');
83+
84+
function log(message) {
85+
const timestamp = new Date().toISOString().split('T')[1].split('.')[0];
86+
logEl.textContent += `[${timestamp}] ${message}\n`;
87+
logEl.scrollTop = logEl.scrollHeight;
88+
console.log(message);
89+
}
90+
91+
function updateStatus(message, type = 'info') {
92+
statusEl.textContent = message;
93+
statusEl.style.borderColor = type === 'error' ? '#f00' : type === 'success' ? '#0f0' : '#ff0';
94+
statusEl.style.color = type === 'error' ? '#f00' : type === 'success' ? '#0f0' : '#ff0';
95+
}
96+
97+
async function testNetworkConnectivity() {
98+
log('Testing network connectivity...');
99+
updateStatus('Testing network...', 'info');
100+
101+
try {
102+
const controller = new AbortController();
103+
const timeoutId = setTimeout(() => controller.abort(), 5000);
104+
105+
const response = await fetch('https://httpbin.org/get', {
106+
method: 'GET',
107+
mode: 'no-cors',
108+
signal: controller.signal
109+
});
110+
111+
clearTimeout(timeoutId);
112+
log(`Network test response: ${response.status}`);
113+
updateStatus('Network connected!', 'success');
114+
return true;
115+
} catch (error) {
116+
clearTimeout(timeoutId);
117+
log(`Network test failed: ${error.message}`);
118+
updateStatus(`Network error: ${error.message}`, 'error');
119+
return false;
120+
}
121+
}
122+
123+
async function testCatboxUpload() {
124+
log('Testing catbox upload...');
125+
updateStatus('Creating test image...', 'info');
126+
127+
try {
128+
// Create a simple test image
129+
const canvas = document.createElement('canvas');
130+
canvas.width = 100;
131+
canvas.height = 100;
132+
const ctx = canvas.getContext('2d');
133+
134+
// Draw a simple pattern
135+
ctx.fillStyle = '#ff0000';
136+
ctx.fillRect(0, 0, 50, 50);
137+
ctx.fillStyle = '#00ff00';
138+
ctx.fillRect(50, 0, 50, 50);
139+
ctx.fillStyle = '#0000ff';
140+
ctx.fillRect(0, 50, 50, 50);
141+
ctx.fillStyle = '#ffff00';
142+
ctx.fillRect(50, 50, 50, 50);
143+
144+
const imageData = canvas.toDataURL('image/jpeg', 0.8);
145+
log(`Test image created, size: ${imageData.length} bytes`);
146+
147+
// Convert to blob
148+
updateStatus('Converting to blob...', 'info');
149+
const blob = await new Promise((resolve, reject) => {
150+
try {
151+
const parts = imageData.split(';base64,');
152+
if (parts.length !== 2) {
153+
throw new Error('Invalid data URL format');
154+
}
155+
156+
const contentType = parts[0].split(':')[1];
157+
const raw = atob(parts[1]);
158+
const rawLength = raw.length;
159+
const uInt8Array = new Uint8Array(rawLength);
160+
161+
for (let i = 0; i < rawLength; ++i) {
162+
uInt8Array[i] = raw.charCodeAt(i);
163+
}
164+
165+
const blob = new Blob([uInt8Array], { type: contentType || 'image/jpeg' });
166+
log(`Blob created, size: ${blob.size} bytes`);
167+
resolve(blob);
168+
} catch (error) {
169+
reject(error);
170+
}
171+
});
172+
173+
// Upload to catbox
174+
updateStatus('Uploading to catbox...', 'info');
175+
log('Sending request to catbox.moe');
176+
177+
const formData = new FormData();
178+
formData.append('reqtype', 'fileupload');
179+
formData.append('fileToUpload', blob, 'test-image.jpg');
180+
181+
const controller = new AbortController();
182+
const timeoutId = setTimeout(() => controller.abort(), 15000);
183+
184+
const response = await fetch('https://catbox.moe/user/api.php', {
185+
method: 'POST',
186+
body: formData,
187+
signal: controller.signal
188+
});
189+
190+
clearTimeout(timeoutId);
191+
log(`Catbox response status: ${response.status}`);
192+
193+
if (response.ok) {
194+
const responseText = await response.text();
195+
const url = responseText.trim();
196+
log(`Image uploaded successfully to: ${url}`);
197+
198+
if (url && url.length > 0 && url.startsWith('http')) {
199+
updateStatus('Catbox upload successful!', 'success');
200+
log('Test completed successfully');
201+
} else {
202+
throw new Error('Invalid URL received from catbox');
203+
}
204+
} else {
205+
throw new Error(`Upload failed with status: ${response.status}`);
206+
}
207+
} catch (error) {
208+
log(`Catbox test failed: ${error.message}`);
209+
updateStatus(`Upload failed: ${error.message}`, 'error');
210+
}
211+
}
212+
213+
document.getElementById('testNetwork').addEventListener('click', testNetworkConnectivity);
214+
document.getElementById('testCatbox').addEventListener('click', testCatboxUpload);
215+
</script>
216+
</body>
217+
</html>

0 commit comments

Comments
 (0)