From ec006b3999fb9f7912d8ef60d7746b25f1ddc119 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 14 Dec 2024 18:34:08 +0530 Subject: [PATCH] Check if expire time is in the past. Closes #265 --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.rs b/src/main.rs index e95a6d9..b5f62b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use std::io::ErrorKind; use std::net::TcpListener; use std::os::unix::net::UnixListener; use std::str::FromStr; +use std::time::{SystemTime, UNIX_EPOCH}; use std::{env, io}; #[cfg(not(any(feature = "reqwest-native-tls", feature = "reqwest-rustls")))] @@ -281,6 +282,20 @@ async fn index(req: HttpRequest) -> Result> { } let video_playback = req.path().eq("/videoplayback"); + + if video_playback { + if let Some(expiry) = query.get("expire") { + let expiry = expiry.parse::()?; + let now = SystemTime::now(); + let now = now.duration_since(UNIX_EPOCH) + .expect("Time went backwards") + .as_secs() as i64; + if now < expiry { + return Err("Expire time in past".into()); + } + } + } + let is_android = video_playback && query.get("c").unwrap_or("").eq("ANDROID"); let is_web = video_playback && query.get("c").unwrap_or("").eq("WEB");