53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import path from "node:path";
|
|
import { mkdir } from "node:fs/promises";
|
|
|
|
export const VIDEOS_DIRECTORY = path.join(process.cwd(), "videos");
|
|
export const THUMBNAILS_DIRECTORY = path.join(process.cwd(), "thumbnails");
|
|
|
|
export async function ensureStorageDirectories(): Promise<void> {
|
|
await Promise.all([
|
|
mkdir(VIDEOS_DIRECTORY, { recursive: true }),
|
|
mkdir(THUMBNAILS_DIRECTORY, { recursive: true }),
|
|
]);
|
|
}
|
|
|
|
export function getVideoPath(filename: string): string {
|
|
return path.join(VIDEOS_DIRECTORY, filename);
|
|
}
|
|
|
|
export function getThumbnailPath(filename: string): string {
|
|
return path.join(THUMBNAILS_DIRECTORY, filename);
|
|
}
|
|
|
|
export function getThumbnailExtension(file: File): string | null {
|
|
const normalizedType = file.type.toLowerCase();
|
|
|
|
if (normalizedType === "image/jpeg") {
|
|
return ".jpg";
|
|
}
|
|
|
|
if (normalizedType === "image/png") {
|
|
return ".png";
|
|
}
|
|
|
|
if (normalizedType === "image/webp") {
|
|
return ".webp";
|
|
}
|
|
|
|
const normalizedName = file.name.toLowerCase();
|
|
|
|
if (normalizedName.endsWith(".jpg") || normalizedName.endsWith(".jpeg")) {
|
|
return ".jpg";
|
|
}
|
|
|
|
if (normalizedName.endsWith(".png")) {
|
|
return ".png";
|
|
}
|
|
|
|
if (normalizedName.endsWith(".webp")) {
|
|
return ".webp";
|
|
}
|
|
|
|
return null;
|
|
}
|