Compare commits
	
		
			No commits in common. "2249d986eb58a5123999b225a87e85150588f837" and "65e83ecb1fac44975c4ab8a27ebbbc161dd6561c" have entirely different histories. 
		
	
	
		
			2249d986eb
			...
			65e83ecb1f
		
	
		| 
						 | 
				
			
			@ -10,13 +10,10 @@ use axum_extra::{
 | 
			
		|||
};
 | 
			
		||||
use cookie::time::Duration;
 | 
			
		||||
 | 
			
		||||
use crate::{
 | 
			
		||||
    gpodder,
 | 
			
		||||
    server::{
 | 
			
		||||
        error::{AppError, AppResult},
 | 
			
		||||
        gpodder::SESSION_ID_COOKIE,
 | 
			
		||||
        Context,
 | 
			
		||||
    },
 | 
			
		||||
use crate::server::{
 | 
			
		||||
    error::{AppError, AppResult},
 | 
			
		||||
    gpodder::SESSION_ID_COOKIE,
 | 
			
		||||
    Context,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub fn router() -> Router<Context> {
 | 
			
		||||
| 
						 | 
				
			
			@ -36,31 +33,6 @@ async fn post_login(
 | 
			
		|||
        return Err(AppError::BadRequest);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // If a session token is present, we check if it's valid first and do nothing if it is
 | 
			
		||||
    if let Some(session_id) = jar
 | 
			
		||||
        .get(SESSION_ID_COOKIE)
 | 
			
		||||
        .and_then(|c| c.value().parse::<i64>().ok())
 | 
			
		||||
    {
 | 
			
		||||
        let ctx = ctx.clone();
 | 
			
		||||
        match tokio::task::spawn_blocking(move || {
 | 
			
		||||
            let session = ctx.store.get_session(session_id)?;
 | 
			
		||||
            ctx.store.refresh_session(&session)?;
 | 
			
		||||
 | 
			
		||||
            Ok(session)
 | 
			
		||||
        })
 | 
			
		||||
        .await
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        {
 | 
			
		||||
            Ok(_) => {
 | 
			
		||||
                return Ok(jar);
 | 
			
		||||
            }
 | 
			
		||||
            Err(gpodder::AuthErr::UnknownSession) => {}
 | 
			
		||||
            Err(err) => {
 | 
			
		||||
                return Err(AppError::from(err));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let session = tokio::task::spawn_blocking(move || {
 | 
			
		||||
        let user = ctx
 | 
			
		||||
            .store
 | 
			
		||||
| 
						 | 
				
			
			@ -71,12 +43,7 @@ async fn post_login(
 | 
			
		|||
    .unwrap()?;
 | 
			
		||||
 | 
			
		||||
    Ok(jar.add(
 | 
			
		||||
        Cookie::build((SESSION_ID_COOKIE, session.id.to_string()))
 | 
			
		||||
            .secure(false)
 | 
			
		||||
            .same_site(cookie::SameSite::Strict)
 | 
			
		||||
            .http_only(true)
 | 
			
		||||
            .path("/api")
 | 
			
		||||
            .max_age(Duration::days(365)),
 | 
			
		||||
        Cookie::build((SESSION_ID_COOKIE, session.id.to_string())).max_age(Duration::days(365)),
 | 
			
		||||
    ))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
use chrono::{DateTime, NaiveDateTime, Utc};
 | 
			
		||||
use chrono::{DateTime, Utc};
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
 | 
			
		||||
use crate::gpodder;
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +66,7 @@ pub enum EpisodeActionType {
 | 
			
		|||
pub struct EpisodeAction {
 | 
			
		||||
    pub podcast: String,
 | 
			
		||||
    pub episode: String,
 | 
			
		||||
    pub timestamp: Option<NaiveDateTime>,
 | 
			
		||||
    pub timestamp: Option<i64>,
 | 
			
		||||
    #[serde(default)]
 | 
			
		||||
    pub device: Option<String>,
 | 
			
		||||
    #[serde(flatten)]
 | 
			
		||||
| 
						 | 
				
			
			@ -160,7 +160,7 @@ impl From<gpodder::EpisodeAction> for EpisodeAction {
 | 
			
		|||
        Self {
 | 
			
		||||
            podcast: value.podcast,
 | 
			
		||||
            episode: value.episode,
 | 
			
		||||
            timestamp: value.timestamp.map(|ts| ts.naive_utc()),
 | 
			
		||||
            timestamp: value.timestamp.map(|ts| ts.timestamp()),
 | 
			
		||||
            device: value.device,
 | 
			
		||||
            action: value.action.into(),
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -173,7 +173,9 @@ impl From<EpisodeAction> for gpodder::EpisodeAction {
 | 
			
		|||
            podcast: value.podcast,
 | 
			
		||||
            episode: value.episode,
 | 
			
		||||
            // TODO remove this unwrap
 | 
			
		||||
            timestamp: value.timestamp.map(|ts| ts.and_utc()),
 | 
			
		||||
            timestamp: value
 | 
			
		||||
                .timestamp
 | 
			
		||||
                .map(|ts| DateTime::from_timestamp(ts, 0).unwrap()),
 | 
			
		||||
            device: value.device,
 | 
			
		||||
            action: value.action.into(),
 | 
			
		||||
            time_changed: DateTime::<Utc>::MIN_UTC,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue