fix(backend): add recording upload diagnostics
This commit is contained in:
@@ -101,12 +101,32 @@ router.post('/:recordingId/finalize', requireDeviceAuth, async (req, res) => {
|
|||||||
const bucket = parsed.data.bucket;
|
const bucket = parsed.data.bucket;
|
||||||
const objectKey = parsed.data.objectKey;
|
const objectKey = parsed.data.objectKey;
|
||||||
|
|
||||||
|
try {
|
||||||
await ensureMinioBucket();
|
await ensureMinioBucket();
|
||||||
|
console.info('[recording.finalize] checking storage object', {
|
||||||
|
recordingId: recording.id,
|
||||||
|
streamSessionId: recording.streamSessionId,
|
||||||
|
bucket,
|
||||||
|
objectKey,
|
||||||
|
durationSeconds: parsed.data.durationSeconds ?? null,
|
||||||
|
sizeBytes: parsed.data.sizeBytes ?? null,
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await minioClient.statObject(bucket, objectKey);
|
await minioClient.statObject(bucket, objectKey);
|
||||||
|
console.info('[recording.finalize] storage object found', {
|
||||||
|
recordingId: recording.id,
|
||||||
|
bucket,
|
||||||
|
objectKey,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (objectKey.startsWith('sim/')) {
|
if (objectKey.startsWith('sim/')) {
|
||||||
|
console.warn('[recording.finalize] creating simulator fallback object', {
|
||||||
|
recordingId: recording.id,
|
||||||
|
bucket,
|
||||||
|
objectKey,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
const placeholder = Buffer.from(
|
const placeholder = Buffer.from(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
message: 'simulated recording placeholder',
|
message: 'simulated recording placeholder',
|
||||||
@@ -121,9 +141,22 @@ router.post('/:recordingId/finalize', requireDeviceAuth, async (req, res) => {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
});
|
});
|
||||||
} else if (isMissingStorageObjectError(error)) {
|
} else if (isMissingStorageObjectError(error)) {
|
||||||
|
console.warn('[recording.finalize] storage object missing', {
|
||||||
|
recordingId: recording.id,
|
||||||
|
streamSessionId: recording.streamSessionId,
|
||||||
|
bucket,
|
||||||
|
objectKey,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
res.status(409).json({ message: 'Recording object does not exist in storage yet' });
|
res.status(409).json({ message: 'Recording object does not exist in storage yet' });
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
console.error('[recording.finalize] storage verification failed', {
|
||||||
|
recordingId: recording.id,
|
||||||
|
bucket,
|
||||||
|
objectKey,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,6 +176,14 @@ router.post('/:recordingId/finalize', requireDeviceAuth, async (req, res) => {
|
|||||||
.where(eq(recordings.id, recording.id))
|
.where(eq(recordings.id, recording.id))
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
|
console.info('[recording.finalize] recording marked ready', {
|
||||||
|
recordingId: recording.id,
|
||||||
|
streamSessionId: recording.streamSessionId,
|
||||||
|
bucket,
|
||||||
|
objectKey,
|
||||||
|
durationSeconds: parsed.data.durationSeconds ?? null,
|
||||||
|
sizeBytes: parsed.data.sizeBytes ?? null,
|
||||||
|
});
|
||||||
res.json({ message: 'Recording finalized', recording: updated });
|
res.json({ message: 'Recording finalized', recording: updated });
|
||||||
|
|
||||||
await writeAuditLog({
|
await writeAuditLog({
|
||||||
@@ -154,6 +195,16 @@ router.post('/:recordingId/finalize', requireDeviceAuth, async (req, res) => {
|
|||||||
metadata: { objectKey: parsed.data.objectKey, bucket: parsed.data.bucket },
|
metadata: { objectKey: parsed.data.objectKey, bucket: parsed.data.bucket },
|
||||||
ipAddress: req.ip,
|
ipAddress: req.ip,
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[recording.finalize] failed', {
|
||||||
|
recordingId: recording.id,
|
||||||
|
streamSessionId: recording.streamSessionId,
|
||||||
|
bucket,
|
||||||
|
objectKey,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:recordingId/download-url', requireDeviceAuth, async (req, res) => {
|
router.get('/:recordingId/download-url', requireDeviceAuth, async (req, res) => {
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ router.post('/upload-url', async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await ensureMinioBucket();
|
await ensureMinioBucket();
|
||||||
|
|
||||||
const device = await db.query.devices.findFirst({
|
const device = await db.query.devices.findFirst({
|
||||||
@@ -86,6 +87,19 @@ router.post('/upload-url', async (req, res) => {
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
const expiresAt = new Date(now.getTime() + minioPresignedExpirySeconds * 1000);
|
const expiresAt = new Date(now.getTime() + minioPresignedExpirySeconds * 1000);
|
||||||
|
|
||||||
|
console.info('[recording.upload-url]', {
|
||||||
|
ownerUserId: authSession.user.id,
|
||||||
|
deviceId: parsed.data.deviceId,
|
||||||
|
recordingId: parsed.data.recordingId ?? null,
|
||||||
|
eventId: parsed.data.eventId ?? null,
|
||||||
|
objectKey,
|
||||||
|
bucket: minioBucket,
|
||||||
|
expiresInSeconds: minioPresignedExpirySeconds,
|
||||||
|
minioEndpoint: process.env.MINIO_ENDPOINT ?? 'localhost',
|
||||||
|
minioPort: Number(process.env.MINIO_PORT ?? 9000),
|
||||||
|
minioUseSSL: (process.env.MINIO_USE_SSL ?? 'false').toLowerCase() === 'true',
|
||||||
|
});
|
||||||
|
|
||||||
let persistedRecording;
|
let persistedRecording;
|
||||||
|
|
||||||
if (parsed.data.recordingId) {
|
if (parsed.data.recordingId) {
|
||||||
@@ -145,6 +159,18 @@ router.post('/upload-url', async (req, res) => {
|
|||||||
expiresAt,
|
expiresAt,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[recording.upload-url] failed', {
|
||||||
|
ownerUserId: authSession.user.id,
|
||||||
|
deviceId: parsed.data.deviceId,
|
||||||
|
recordingId: parsed.data.recordingId ?? null,
|
||||||
|
eventId: parsed.data.eventId ?? null,
|
||||||
|
fileName: parsed.data.fileName,
|
||||||
|
prefix: parsed.data.prefix ?? null,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/download-url', async (req, res) => {
|
router.get('/download-url', async (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user