feat: Implement device-specific video uploads and generate comprehensive OpenAPI documentation.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { NextFunction, Request, Response, Router } from 'express';
|
||||
import type { NextFunction, Request, Response } from 'express';
|
||||
import { Router } from 'express';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ensureMinioBucket, minioBucket, minioClient, minioPresignedExpirySeconds } from '../utils/minio';
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user