Check if expire time is in the past.

Closes #265
This commit is contained in:
Kavin 2024-12-14 18:34:08 +05:30
parent feaceaa14b
commit ec006b3999
No known key found for this signature in database
GPG Key ID: 6E4598CA5C92C41F

View File

@ -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<HttpResponse, Box<dyn Error>> {
}
let video_playback = req.path().eq("/videoplayback");
if video_playback {
if let Some(expiry) = query.get("expire") {
let expiry = expiry.parse::<i64>()?;
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");