cos tam dziala

This commit is contained in:
Patryk Koreń
2026-07-09 20:14:56 +02:00
parent ff707dd762
commit 65303e655b
18 changed files with 235 additions and 153 deletions

View File

@@ -16,17 +16,21 @@ export async function encodeFrames({
"-y",
"-pattern_type", "glob",
"-framerate", fps.toString(),
"-i", inputPattern,
"-i", inputPattern.toString(),
"-i", path.resolve("./music.mp3"),
"-vf",
"transpose=2,scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2",
// "-autorotate",
"-c:v", "libx264",
"-pix_fmt", "yuv420p",
"-c:a", "mp3",
"-shortest",
"-fps_mode", "cfr",
// "-preset", "medium",
// "-crf", "18",
output,

View File

@@ -18,9 +18,9 @@ export async function downloadMissing(remoteDir: string = REMOTE_DIR) {
const exisitngFiles = await fs.readdir(LOCAL_DIR);
const missing = contents.filter(f => !exisitngFiles.includes(f.basename))
const missing = contents.filter(f => !exisitngFiles.includes(f.basename));
console.log(missing)
console.log(missing);
let i = 0;
for (const item of missing) {

View File

@@ -2,30 +2,17 @@ import jwt from "jsonwebtoken";
import type { Request, Response, NextFunction } from "express";
export function authMiddleware(req: Request, res: Response, next: NextFunction) {
// const header = req.headers.authorization;
// const error = "You must be logged in to access this page"
// if (!header) {
// return res.status(401).json({ error });
// }
// const token = header.split(" ")[1]; // "Bearer TOKEN"
// try {
// if (!token) throw new Error("No Bearer Token")
// const decoded = jwt.verify(token, process.env.JWT_SECRET!);
// (req as any).user = decoded;
// next();
// } catch (err) {
// return res.status(401).json({ error });
// }
const token = req.cookies.token;
if (!token) return res.sendStatus(401);
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET!) as jwt.JwtPayload;
req.user = decoded;
const token = req.cookies.token;
if (!token) { return res.sendStatus(401); }
console.log("Token: ", token)
console.log("Secret: ", process.env.JWT_SECRET)
jwt.verify(token, process.env.JWT_SECRET!)
next();
} catch {
res.sendStatus(403);
}

View File

@@ -39,4 +39,41 @@ router.post("/login", async (req, res) => {
}
});
router.post("/logout", async (req, res) => {
res.clearCookie("token", {
httpOnly: true,
secure: false,
sameSite: "lax",
});
res.sendStatus(204);
});
router.get("/me", async (req, res) => {
try {
const token = req.cookies.token;
if (!token) {
return res.status(401).json(null);
}
const payload = jwt.verify(
token,
process.env.JWT_SECRET!
) as {
sub: string;
username: string;
};
res.json({
username: payload.username,
dn: payload.sub,
});
} catch (err) {
console.log(err)
return res.status(401).json(null);
}
});
export default router;

View File

@@ -3,11 +3,23 @@ import { Router } from "express";
import { downloadMissing, LOCAL_DIR } from "../lib/nextcloud";
import path from "node:path";
import { encodeFrames } from "../lib/crateClip";
import fs from "node:fs"
const router = Router();
router.get("/video", async (req, res) => {
const videoPath = path.resolve("./out.mp4");
const stat = fs.statSync(videoPath);
// Simple ETag based on file size + modification time
const etag = `"${stat.size}-${stat.mtimeMs}"`;
res.set("ETag", etag);
if (req.headers["if-none-match"] === etag) {
return res.status(304).end();
}
res.sendFile(videoPath);
});
@@ -18,18 +30,18 @@ router.post("/createclip", async (req, res) => {
output: path.resolve("./out.mp4"),
fps: 12,
});
res.end(200);
res.status(200).end();
} catch {
res.end(501);
res.status(501).end();
}
})
router.post("/refreshfiles", async (req, res) => {
try {
await downloadMissing();
res.end(200);
res.status(200).end();
} catch {
res.end(501);
res.status(501).end();
}
})