Enable users to edit video titles, descriptions, and thumbnails
Introduce functionality to edit video metadata including title, description, category, tags, and public status, along with a new modal for editing and a backend endpoint for updating video information. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 11420304-80a9-4ef2-adff-cbdaa418ffa8 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/11420304-80a9-4ef2-adff-cbdaa418ffa8/vOcB2tQ
This commit is contained in:
@@ -2,6 +2,7 @@ import type { Express } from "express";
|
||||
import { createServer, type Server } from "http";
|
||||
import { storage } from "./storage";
|
||||
import { z } from "zod";
|
||||
import { updateVideoSchema } from "@shared/schema";
|
||||
|
||||
export async function registerRoutes(app: Express): Promise<Server> {
|
||||
// Get videos with pagination and filtering
|
||||
@@ -47,6 +48,25 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// Update video metadata (title, description, etc.)
|
||||
app.patch("/api/videos/:id", async (req, res) => {
|
||||
try {
|
||||
const updates = updateVideoSchema.parse(req.body);
|
||||
const updatedVideo = await storage.updateVideo(req.params.id, updates);
|
||||
|
||||
if (!updatedVideo) {
|
||||
return res.status(404).json({ message: "Video not found" });
|
||||
}
|
||||
|
||||
res.json(updatedVideo);
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
return res.status(400).json({ message: "Invalid request data", errors: error.errors });
|
||||
}
|
||||
res.status(500).json({ message: "Failed to update video" });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+39
-9
@@ -1,4 +1,4 @@
|
||||
import { type Video, type InsertVideo } from "@shared/schema";
|
||||
import { type Video, type InsertVideo, type UpdateVideo } from "@shared/schema";
|
||||
import { randomUUID } from "crypto";
|
||||
import { BunnyService } from "./bunny";
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface IStorage {
|
||||
getVideos(limit?: number, offset?: number, search?: string): Promise<Video[]>;
|
||||
getVideo(id: string): Promise<Video | undefined>;
|
||||
createVideo(video: InsertVideo): Promise<Video>;
|
||||
updateVideo(id: string, video: UpdateVideo): Promise<Video | undefined>;
|
||||
updateVideoViews(id: string): Promise<void>;
|
||||
getVideoCount(search?: string): Promise<number>;
|
||||
}
|
||||
@@ -83,10 +84,15 @@ export class MemStorage implements IStorage {
|
||||
const fullVideo: Video = {
|
||||
...video,
|
||||
id,
|
||||
views: video.views || 0,
|
||||
description: video.description || null,
|
||||
category: video.category || null,
|
||||
createdAt: new Date()
|
||||
description: video.description || "",
|
||||
category: video.category || "",
|
||||
customThumbnailUrl: null,
|
||||
videoUrlMp4: null,
|
||||
videoUrlIframe: null,
|
||||
tags: [],
|
||||
isPublic: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
};
|
||||
this.videos.set(id, fullVideo);
|
||||
});
|
||||
@@ -119,15 +125,33 @@ export class MemStorage implements IStorage {
|
||||
const fullVideo: Video = {
|
||||
...video,
|
||||
id,
|
||||
views: video.views || 0,
|
||||
description: video.description || null,
|
||||
category: video.category || null,
|
||||
createdAt: new Date()
|
||||
description: video.description || "",
|
||||
category: video.category || "",
|
||||
customThumbnailUrl: null,
|
||||
videoUrlMp4: null,
|
||||
videoUrlIframe: null,
|
||||
tags: video.tags || [],
|
||||
isPublic: video.isPublic ?? true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
};
|
||||
this.videos.set(id, fullVideo);
|
||||
return fullVideo;
|
||||
}
|
||||
|
||||
async updateVideo(id: string, updates: UpdateVideo): Promise<Video | undefined> {
|
||||
const video = this.videos.get(id);
|
||||
if (!video) return undefined;
|
||||
|
||||
const updatedVideo: Video = {
|
||||
...video,
|
||||
...updates,
|
||||
updatedAt: new Date()
|
||||
};
|
||||
this.videos.set(id, updatedVideo);
|
||||
return updatedVideo;
|
||||
}
|
||||
|
||||
async updateVideoViews(id: string): Promise<void> {
|
||||
const video = this.videos.get(id);
|
||||
if (video) {
|
||||
@@ -212,6 +236,12 @@ class BunnyStorage implements IStorage {
|
||||
throw new Error("Creating videos is not supported with Bunny.net integration");
|
||||
}
|
||||
|
||||
async updateVideo(id: string, updates: UpdateVideo): Promise<Video | undefined> {
|
||||
// Note: Updating video metadata in Bunny.net would require API calls
|
||||
// For now, we'll throw an error as this operation is not supported
|
||||
throw new Error("Updating videos is not supported with Bunny.net integration");
|
||||
}
|
||||
|
||||
async updateVideoViews(id: string): Promise<void> {
|
||||
// Since we can't update views in Bunny.net directly, we'll cache them locally
|
||||
const currentViews = this.viewsCache.get(id) || 0;
|
||||
|
||||
Reference in New Issue
Block a user