Compare commits
No commits in common. "b0738d9710746491e615df62f073bbd48bf8b20f" and "e9b50164a2b51bedf80c6e345a73f1455d23cbee" have entirely different histories.
b0738d9710
...
e9b50164a2
1 changed files with 5 additions and 8 deletions
13
index.ts
13
index.ts
|
@ -60,7 +60,6 @@ async function processSnapshots(
|
||||||
videos: VideoInfo[],
|
videos: VideoInfo[],
|
||||||
snapshotsDir: string,
|
snapshotsDir: string,
|
||||||
count: number,
|
count: number,
|
||||||
sizeLimit: number,
|
|
||||||
) {
|
) {
|
||||||
const totalDuration = videos.reduce((acc, video) => acc + video.duration, 0);
|
const totalDuration = videos.reduce((acc, video) => acc + video.duration, 0);
|
||||||
const currentHour = new Date().getHours();
|
const currentHour = new Date().getHours();
|
||||||
|
@ -92,7 +91,7 @@ async function processSnapshots(
|
||||||
|
|
||||||
const stats = await stat(snapshotPath);
|
const stats = await stat(snapshotPath);
|
||||||
size = stats.size;
|
size = stats.size;
|
||||||
if (size < sizeLimit) {
|
if (size < 5 * 1024) {
|
||||||
logger.info(
|
logger.info(
|
||||||
`Snapshot ${
|
`Snapshot ${
|
||||||
i + 1
|
i + 1
|
||||||
|
@ -109,7 +108,6 @@ async function setupSnapshotServer(
|
||||||
videoPaths: string[],
|
videoPaths: string[],
|
||||||
snapshotsDir: string,
|
snapshotsDir: string,
|
||||||
count: number,
|
count: number,
|
||||||
sizeLimit: number,
|
|
||||||
) {
|
) {
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
@ -118,10 +116,10 @@ async function setupSnapshotServer(
|
||||||
const videos = await getVideoInfo(videoPaths);
|
const videos = await getVideoInfo(videoPaths);
|
||||||
|
|
||||||
// noinspection ES6MissingAwait
|
// noinspection ES6MissingAwait
|
||||||
processSnapshots(videos, snapshotsDir, count, sizeLimit);
|
processSnapshots(videos, snapshotsDir, count);
|
||||||
|
|
||||||
schedule.scheduleJob("0 * * * *", () =>
|
schedule.scheduleJob("0 * * * *", () =>
|
||||||
processSnapshots(videos, snapshotsDir, count, sizeLimit),
|
processSnapshots(videos, snapshotsDir, count),
|
||||||
);
|
);
|
||||||
|
|
||||||
app.get("/:magic?", async (req, res) => {
|
app.get("/:magic?", async (req, res) => {
|
||||||
|
@ -138,10 +136,11 @@ async function setupSnapshotServer(
|
||||||
if (magic) {
|
if (magic) {
|
||||||
const hash = createHash("md5").update(magic).digest("hex");
|
const hash = createHash("md5").update(magic).digest("hex");
|
||||||
const index = parseInt(hash.substring(0, 8), 16) % files.length;
|
const index = parseInt(hash.substring(0, 8), 16) % files.length;
|
||||||
|
// Cache until the next hour rolls over
|
||||||
res.sendFile(files[index], {
|
res.sendFile(files[index], {
|
||||||
headers: {
|
headers: {
|
||||||
"Cache-Control": `public, max-age=${
|
"Cache-Control": `public, max-age=${
|
||||||
3600 - new Date().getMinutes() * 60 - new Date().getSeconds()
|
3600 - new Date().getMinutes() * 60
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
root: currentDir,
|
root: currentDir,
|
||||||
|
@ -173,13 +172,11 @@ program
|
||||||
.argument("<paths...>", "Video file paths")
|
.argument("<paths...>", "Video file paths")
|
||||||
.option("-d, --directory <dir>", "Directory to store snapshots", "snapshots")
|
.option("-d, --directory <dir>", "Directory to store snapshots", "snapshots")
|
||||||
.option("-c, --count <count>", "Number of snapshots to take per hour", "32")
|
.option("-c, --count <count>", "Number of snapshots to take per hour", "32")
|
||||||
.option("--size-limit <size>", "Size limit for snapshots in KiB", "7")
|
|
||||||
.action(async (videoPaths: string[], options) => {
|
.action(async (videoPaths: string[], options) => {
|
||||||
await setupSnapshotServer(
|
await setupSnapshotServer(
|
||||||
videoPaths,
|
videoPaths,
|
||||||
options.directory,
|
options.directory,
|
||||||
parseInt(options.count, 10),
|
parseInt(options.count, 10),
|
||||||
parseInt(options.sizeLimit, 10) * 1024,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue