Skip to content

Commit fc5ac59

Browse files
committed
rework updated upload feedback on server
1 parent 7573ec6 commit fc5ac59

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

tests/perceptor-host-test/index.html

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@
6565
</head>
6666
<body>
6767
<h1>Perceptor Test Host Server</h1>
68-
<div class="status">
69-
<strong>✓ Server is running</strong>
70-
</div>
7168
<div class="info">
7269
<h2>WebSocket Connection</h2>
7370
<p>The server is ready to accept WebSocket connections at <code id="ws-url">ws://localhost:8080</code></p>
@@ -133,8 +130,8 @@ <h2>Active Connections</h2>
133130
<div class="connection-item">
134131
<div class="connection-id">${conn.clientName || 'Unknown Device'} <span style="color: #999; font-size: 0.85em;">(${conn.id})</span></div>
135132
<div class="connection-details">
136-
<p>Metadata: ${conn.hasMetadata ? '✓' : '✗'} ${conn.filename ? `(${conn.filename})` : ''}</p>
137-
<p>Data Received: ${conn.receivedData ? '✓' : '✗'}</p>
133+
${conn.lastFilename ? `<p>Last File: <strong>${conn.lastFilename}</strong></p>
134+
<p>Size: ${formatFileSize(conn.lastFilesize)}</p>` : '<p style="color: #999;">No files received yet</p>'}
138135
</div>
139136
<div style="margin-top: 10px;">
140137
<label for="duration-${conn.id}" style="display: inline-block; margin-right: 10px;">Duration (ms):</label>
@@ -168,10 +165,30 @@ <h2>Active Connections</h2>
168165
// Then update every 5 seconds
169166
setInterval(updateStatus, 5000);
170167

168+
function formatFileSize(bytes) {
169+
if (!bytes) return 'Unknown';
170+
if (bytes === 0) return '0 B';
171+
const k = 1024;
172+
const sizes = ['B', 'KB', 'MB', 'GB'];
173+
const i = Math.floor(Math.log(bytes) / Math.log(k));
174+
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i];
175+
}
176+
171177
async function sendRecordCommand(connectionId) {
172178
try {
173179
const durationInput = document.getElementById(`duration-${connectionId}`);
174180
const autoUploadCheckbox = document.getElementById(`autoUpload-${connectionId}`);
181+
182+
// Defensive checks to ensure elements exist
183+
if (!durationInput) {
184+
alert('Error: Duration input not found. The connection list may have been updated. Please try again.');
185+
return;
186+
}
187+
if (!autoUploadCheckbox) {
188+
alert('Error: Auto Upload checkbox not found. The connection list may have been updated. Please try again.');
189+
return;
190+
}
191+
175192
const duration = parseInt(durationInput.value, 10);
176193
const autoUpload = autoUploadCheckbox.checked;
177194

tests/perceptor-host-test/server.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ function requestHandler(req, res) {
100100
const connections = Array.from(uploadStates.entries()).map(([id, state]) => ({
101101
id,
102102
clientName: state.clientName || "Unknown Device",
103-
hasMetadata: state.metadata !== null,
104-
filename: state.metadata?.filename || null,
105-
receivedData: state.receivedData
103+
lastFilename: state.lastFilename,
104+
lastFilesize: state.lastFilesize
106105
}));
107106
res.end(JSON.stringify({
108107
totalConnections: uploadStates.size,
@@ -174,7 +173,9 @@ wss.on("connection", function connection(ws) {
174173
metadata: null,
175174
fileStream: null,
176175
receivedData: false,
177-
clientName: null
176+
clientName: null,
177+
lastFilename: null,
178+
lastFilesize: null
178179
});
179180
clientConnections.set(connectionId, ws);
180181
console.log(`Client connected ${connectionId}`);
@@ -265,6 +266,9 @@ wss.on("connection", function connection(ws) {
265266
state.fileStream.end();
266267

267268
const filepath = path.join(config.uploadPath, state.metadata.filename);
269+
// Store the last filename and filesize
270+
state.lastFilename = state.metadata.filename;
271+
state.lastFilesize = state.metadata.filesize || message.length;
268272
console.log(`File uploaded successfully: ${filepath}`);
269273
ws.send(JSON.stringify({ status: "success", message: "Video uploaded successfully" }));
270274

0 commit comments

Comments
 (0)