Let users upload videos, tag them with one or more entries, and watch them from a new Discovery Videos page. Backend: - Add Video and VideoEntry models and relations - Add video controller and /video routes - Add video thumbnail generation service (ffmpeg-static) - Add video upload storage location and config Frontend: - Add DiscoveryVideosPage with sidebar link and route - Add AddVideoDialog, VideoDropzone, EntryMultiSelect, VideoCard and VideoPlayerDialog components - Add discoveryVideos API client and useDiscoveryVideos hook - Add format helpers, video types and normalizers - Add skeleton for the page Docs: - Document the feature in docs-vault
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { api } from "@/lib/api";
|
|
import { normalizeDiscoveryVideo } from "@/lib/normalizers";
|
|
import type {
|
|
DiscoveryVideo,
|
|
DiscoveryVideoPaginatedResponse,
|
|
} from "@/types";
|
|
|
|
export interface UpdateVideoData {
|
|
title?: string;
|
|
description?: string;
|
|
entryIds: number[];
|
|
}
|
|
|
|
export const discoveryVideosApi = {
|
|
getAll: (page = 1, limit = 24) =>
|
|
api
|
|
.get<DiscoveryVideoPaginatedResponse>("/discovery-videos", {
|
|
params: { page, limit },
|
|
})
|
|
.then((r) => ({
|
|
...r.data,
|
|
videos: r.data.videos.map(normalizeDiscoveryVideo),
|
|
})),
|
|
|
|
create: (formData: FormData, onProgress?: (percent: number) => void) =>
|
|
api
|
|
.post<DiscoveryVideo[]>("/discovery-videos", formData, {
|
|
headers: { "Content-Type": "multipart/form-data" },
|
|
onUploadProgress: (e) => {
|
|
if (onProgress && e.total) {
|
|
onProgress(Math.round((e.loaded / e.total) * 100));
|
|
}
|
|
},
|
|
})
|
|
.then((r) => r.data.map(normalizeDiscoveryVideo)),
|
|
|
|
update: (id: number, data: UpdateVideoData) =>
|
|
api
|
|
.put<DiscoveryVideo>(`/discovery-videos/${id}`, data)
|
|
.then((r) => normalizeDiscoveryVideo(r.data)),
|
|
|
|
remove: (id: number) => api.delete(`/discovery-videos/${id}`).then((r) => r.data),
|
|
};
|