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
85 lines
2.6 KiB
JavaScript
85 lines
2.6 KiB
JavaScript
const multer = require("multer");
|
|
const fs = require("fs");
|
|
const { v4: uuidv4 } = require("uuid");
|
|
const path = require("path");
|
|
const configService = require("./configService");
|
|
|
|
// ? users
|
|
const entryPicturesUpload = multer({
|
|
storage: multer.diskStorage({
|
|
destination: function (req, file, cb) {
|
|
let folder = "posters";
|
|
if (file.fieldname == "backdrop") folder = "backdrops";
|
|
if (file.fieldname == "logo") folder = "logos";
|
|
|
|
const dataPath = configService.getSettings().userDataPath;
|
|
|
|
cb(null, path.join(dataPath, "images", "entries", folder));
|
|
},
|
|
filename: function (req, file, cb) {
|
|
const uniqueFilename = uuidv4();
|
|
const extension = file.originalname.split(".").pop();
|
|
cb(null, `${uniqueFilename}.${extension}`);
|
|
},
|
|
}),
|
|
});
|
|
|
|
const collectionPicturesUpload = multer({
|
|
storage: multer.diskStorage({
|
|
destination: function (req, file, cb) {
|
|
let folder = "posters";
|
|
if (file.fieldname == "backdrop") folder = "backdrops";
|
|
if (file.fieldname == "logo") folder = "logos";
|
|
|
|
const dataPath = configService.getSettings().userDataPath;
|
|
|
|
cb(null, path.join(dataPath, "images", "collections", folder));
|
|
},
|
|
filename: function (req, file, cb) {
|
|
const uniqueFilename = uuidv4();
|
|
const extension = file.originalname.split(".").pop();
|
|
cb(null, `${uniqueFilename}.${extension}`);
|
|
},
|
|
}),
|
|
});
|
|
|
|
const peoplePicturesUpload = multer({
|
|
storage: multer.diskStorage({
|
|
destination: function (req, file, cb) {
|
|
let folder = "profiles";
|
|
const dataPath = configService.getSettings().userDataPath;
|
|
cb(null, path.join(dataPath, "images", "people", folder));
|
|
},
|
|
filename: function (req, file, cb) {
|
|
const uniqueFilename = uuidv4();
|
|
const extension = file.originalname.split(".").pop();
|
|
cb(null, `${uniqueFilename}.${extension}`);
|
|
},
|
|
}),
|
|
});
|
|
|
|
// ? discovery videos
|
|
const videosUpload = multer({
|
|
storage: multer.diskStorage({
|
|
destination: function (req, file, cb) {
|
|
const dataPath = configService.getSettings().userDataPath;
|
|
const videosDir = path.join(dataPath, "videos");
|
|
// ensure the folder exists even if createMediaFolders() was never called
|
|
fs.mkdirSync(videosDir, { recursive: true });
|
|
cb(null, videosDir);
|
|
},
|
|
filename: function (req, file, cb) {
|
|
const uniqueFilename = uuidv4();
|
|
const extension = file.originalname.split(".").pop();
|
|
cb(null, `${uniqueFilename}.${extension}`);
|
|
},
|
|
}),
|
|
});
|
|
|
|
module.exports = {
|
|
entryPicturesUpload,
|
|
collectionPicturesUpload,
|
|
peoplePicturesUpload,
|
|
videosUpload,
|
|
};
|