add processVideo env

This commit is contained in:
waveringana 2025-05-11 19:16:02 -04:00
parent 3605a3f3a5
commit 170479b585
8 changed files with 89 additions and 27 deletions

View file

@ -92,6 +92,8 @@ function onListening() {
const bind = typeof addr === "string"
? "pipe " + addr
: "port " + addr.port;
const processVideo = process.env["EB_PROCESS_VIDEO"] === "true" ? true : false;
console.log("Process video: " + processVideo);
console.log("Embedder version: " + version);
console.log("Listening on " + bind);
}

View file

@ -24,7 +24,10 @@ class FileUploader {
this.dropArea = document.getElementById('dropArea');
this.gallery = document.getElementById('gallery');
this.setupEventListeners();
this.setupProgressUpdates(); // SSE logic for transcoding
// Only set up SSE if we're processing videos
if (document.body.dataset.processVideo === 'true') {
this.setupProgressUpdates();
}
}
setupEventListeners() {

View file

@ -26,6 +26,8 @@ import {
processUploadedMedia,
} from "../lib/middleware";
const processVideo: boolean = process.env["EB_PROCESS_VIDEO"] !== "false";
const upload = multer({ storage: fileStorage /**, fileFilter: fileFilter**/ }); //maybe make this a env variable?
/**Middleware to grab media from media database */
@ -65,6 +67,11 @@ const fetchMedia: Middleware = (req, res, next) => {
const router = express.Router();
router.get('/progress-updates', (req, res) => {
if (!processVideo) {
res.status(404).send('Video processing is disabled');
return;
}
console.log("SSE connection requested"); // Debug log
res.setHeader('Content-Type', 'text/event-stream');
@ -96,12 +103,12 @@ router.get(
fetchMedia,
(req: Request, res: Response) => {
res.locals.filter = null;
res.render("index", { user: req.user });
res.render("index", { user: req.user, processVideo });
}
);
router.get("/media-list", fetchMedia, (req: Request, res: Response) => {
res.render("partials/_fileList", { user: req.user });
res.render("partials/_fileList", { user: req.user, processVideo });
});
router.get(
@ -189,21 +196,36 @@ router.get("/oembed/:file",
}
);
router.post(
"/",
[
checkAuth,
upload.array("fileupload"),
handleUpload,
fetchMedia,
processUploadedMedia,
createEmbedData,
],
(req: Request, res: Response) => {
return res.render("partials/_fileList", { user: req.user }); // Render only the file list partial
}
);
if (processVideo) {
router.post(
"/",
[
checkAuth,
upload.array("fileupload"),
handleUpload,
fetchMedia,
processUploadedMedia,
createEmbedData,
],
(req: Request, res: Response) => {
return res.render("partials/_fileList", { user: req.user, processVideo }); // Render only the file list partial
}
);
} else {
router.post(
"/",
[
checkAuth,
upload.array("fileupload"),
handleUpload,
fetchMedia,
createEmbedData
],
(req: Request, res: Response) => {
return res.render("partials/_fileList", { user: req.user, processVideo }); // Render only the file list partial
}
);
}
router.post(
"/sharex",
[checkSharexAuth, upload.single("fileupload"), createEmbedData, handleUpload],

View file

@ -11,10 +11,12 @@ class ProgressManager {
private static instance: ProgressManager;
private emitter: EventEmitter;
private activeJobs: Map<string, ProgressUpdate>;
private processVideo: boolean;
private constructor() {
this.emitter = new EventEmitter();
this.activeJobs = new Map();
this.processVideo = process.env["EB_PROCESS_VIDEO"] === "true";
}
static getInstance(): ProgressManager {
@ -25,19 +27,27 @@ class ProgressManager {
}
updateProgress(update: ProgressUpdate) {
if (!this.processVideo) return;
this.activeJobs.set(update.filename, update);
this.emitter.emit('progress', update);
}
subscribeToUpdates(callback: (update: ProgressUpdate) => void) {
if (!this.processVideo) return;
this.emitter.on('progress', callback);
}
unsubscribeFromUpdates(callback: (update: ProgressUpdate) => void) {
if (!this.processVideo) return;
this.emitter.off('progress', callback);
}
getJobStatus(filename: string): ProgressUpdate | undefined {
if (!this.processVideo) return undefined;
return this.activeJobs.get(filename);
}
}

View file

@ -15,7 +15,7 @@
<script src="https://unpkg.com/htmx.org@1.9.8"></script>
</head>
<body>
<body data-process-video="<%= processVideo %>">
<section class="embedderapp">
<header class="header">
<h1>Embedder</h1>

View file

@ -23,6 +23,7 @@ function sanitizeId(filename) {
<div class="video">
<% const sanitizedId = file.path.replace(/[^a-z0-9]/gi, '_'); %>
<% if (processVideo) { %>
<div id="spinner-<%= sanitizedId %>" class="spinner" style="display: <%= file.isProcessed ? 'none' : 'block' %>;">
<div class="spinner-content">
Optimizing Video for Sharing...
@ -30,8 +31,12 @@ function sanitizeId(filename) {
</div>
<div id="media-container-<%= sanitizedId %>" class="video-container" style="display: <%= file.isProcessed ? 'block' : 'none' %>;">
<% } else { %>
<div class="video-container">
<% } %>
<video class="image" autoplay loop muted playsinline>
<source src="/uploads/720p-<%= file.path %>">
<source src="/uploads/<%= file.path %>">
</video>
</div>
@ -40,7 +45,9 @@ function sanitizeId(filename) {
<small class="username"><%= file.username %></small>
<br>
<% } %>
<a href="/gifv/<%= file.path %>" onclick="copyA(event)">Copy as GIFv</a>
<% if (processVideo) { %>
<a href="/gifv/<%= file.path %>" onclick="copyA(event)">Copy as GIFv</a>
<% } %>
</div>
</div>
<% } else if (mediaType === 'image') { %>