feat: add videos table to schema and implement video upload route with metadata persistence
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { Router } from 'express';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { db } from '../db/client';
|
||||
import { videos } from '../db/schema';
|
||||
import { requireAuth } from '../middleware/auth';
|
||||
import {
|
||||
ensureMinioBucket,
|
||||
@@ -55,6 +57,33 @@ router.post('/upload-url', async (req, res) => {
|
||||
|
||||
const objectKey = buildObjectKey(user.userId, parsed.data.fileName, parsed.data.prefix);
|
||||
const uploadUrl = await minioClient.presignedPutObject(minioBucket, objectKey, minioPresignedExpirySeconds);
|
||||
const now = new Date();
|
||||
const expiresAt = new Date(now.getTime() + minioPresignedExpirySeconds * 1000);
|
||||
|
||||
const [videoRecord] = await db
|
||||
.insert(videos)
|
||||
.values({
|
||||
userId: user.userId,
|
||||
objectKey,
|
||||
bucket: minioBucket,
|
||||
uploadUrl,
|
||||
status: 'upload_link_sent',
|
||||
expiresAt,
|
||||
updatedAt: now,
|
||||
})
|
||||
.returning({
|
||||
id: videos.id,
|
||||
objectKey: videos.objectKey,
|
||||
bucket: videos.bucket,
|
||||
status: videos.status,
|
||||
createdAt: videos.createdAt,
|
||||
expiresAt: videos.expiresAt,
|
||||
});
|
||||
|
||||
if (!videoRecord) {
|
||||
res.status(500).json({ message: 'Unable to persist video metadata' });
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(201).json({
|
||||
message: 'Dummy upload URL generated',
|
||||
@@ -62,6 +91,7 @@ router.post('/upload-url', async (req, res) => {
|
||||
objectKey,
|
||||
uploadUrl,
|
||||
expiresInSeconds: minioPresignedExpirySeconds,
|
||||
video: videoRecord,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user