feat: Implement device-specific video uploads and generate comprehensive OpenAPI documentation.

This commit is contained in:
2025-12-21 13:10:00 +00:00
parent e18f6566e7
commit cdaab7f0c1
7 changed files with 492 additions and 2 deletions

View File

@@ -1,8 +1,9 @@
import { Router } from 'express';
import { and, eq } from 'drizzle-orm';
import { z } from 'zod';
import { db } from '../db/client';
import { videos } from '../db/schema';
import { devices, videos } from '../db/schema';
import { requireAuth } from '../middleware/auth';
import {
ensureMinioBucket,
@@ -15,6 +16,7 @@ const router = Router();
const uploadUrlSchema = z.object({
fileName: z.string().trim().min(1).max(255),
deviceId: z.string().uuid(),
prefix: z.string().trim().optional(),
});
@@ -55,6 +57,16 @@ router.post('/upload-url', async (req, res) => {
await ensureMinioBucket();
const device = await db.query.devices.findFirst({
where: and(eq(devices.id, parsed.data.deviceId), eq(devices.userId, authSession.user.id)),
columns: { id: true },
});
if (!device) {
res.status(400).json({ message: 'Invalid deviceId for this user' });
return;
}
const objectKey = buildObjectKey(authSession.user.id, parsed.data.fileName, parsed.data.prefix);
const uploadUrl = await minioClient.presignedPutObject(minioBucket, objectKey, minioPresignedExpirySeconds);
const now = new Date();
@@ -64,6 +76,7 @@ router.post('/upload-url', async (req, res) => {
.insert(videos)
.values({
userId: authSession.user.id,
deviceId: parsed.data.deviceId,
objectKey,
bucket: minioBucket,
uploadUrl,