Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

make session backwards compatible#1528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
make session backwards compatible
  • Loading branch information
@chillenberger
chillenberger committedJun 14, 2024
commita4b3e743557d88c946b7c03fd1445df02dc4ab29
107 changes: 2 additions & 105 deletionspgml-dashboard/Cargo.lock
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

2 changes: 1 addition & 1 deletionpgml-dashboard/src/main.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -137,7 +137,7 @@ mod test {
async fn rocket() -> Rocket<Build> {
dotenv::dotenv().ok();

pgml_dashboard::migrate(Cluster::default(None).pool()).await.unwrap();
pgml_dashboard::migrate(Cluster::default().pool()).await.unwrap();

let mut site_search = markdown::SiteSearch::new()
.await
Expand Down
46 changes: 26 additions & 20 deletionspgml-dashboard/src/utils/cookies.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,28 +9,14 @@ pub struct NotificationCookie {
pub time_modal_viewed: Option<chrono::DateTime<chrono::Utc>>,
}

impl std::fmt::Display for NotificationCookie {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut rsp = format!(r#"{{"id": "{}""#, self.id.clone());
if self.time_viewed.is_some() {
rsp.push_str(&format!(r#", "time_viewed": "{}""#, self.time_viewed.clone().unwrap()));
}
if self.time_modal_viewed.is_some() {
rsp.push_str(&format!(
r#", "time_modal_viewed": "{}""#,
self.time_modal_viewed.clone().unwrap()
));
}
rsp.push_str("}");
return write!(f, "{}", rsp);
}
}

pub struct Notifications {}

impl Notifications {
pub fn update_viewed(new: &Vec<NotificationCookie>, cookies: &CookieJar<'_>) {
let serialized = new.iter().map(|x| x.to_string()).collect::<Vec<String>>();
let serialized = new
.iter()
.map(|x| serde_json::to_string(x).unwrap())
.collect::<Vec<String>>();

let mut cookie = Cookie::new("session", format!(r#"{{"notifications": [{}]}}"#, serialized.join(",")));
cookie.set_max_age(::time::Duration::weeks(4));
Expand All@@ -40,10 +26,30 @@ impl Notifications {
pub fn get_viewed(cookies: &CookieJar<'_>) -> Vec<NotificationCookie> {
let viewed: Vec<NotificationCookie> = match cookies.get_private("session") {
Some(session) => {
match serde_json::from_str::<serde_json::Value>(session.value()).unwrap()["notifications"].as_array() {
match serde_json::from_str::<serde_json::Value>(session.value())
.unwrap_or_else(|_| serde_json::from_str::<serde_json::Value>(r#"{"notifications": []}"#).unwrap())
["notifications"]
.as_array()
{
Some(items) => items
.into_iter()
.map(|x| serde_json::from_str::<NotificationCookie>(&x.to_string()).unwrap())
.map(|x| {
serde_json::from_str::<NotificationCookie>(&x.to_string()).unwrap_or_else(|_| {
serde_json::from_str::<String>(&x.to_string())
.and_then(|z| {
Ok(NotificationCookie {
id: z,
time_viewed: None,
time_modal_viewed: None,
})
})
.unwrap_or_else(|_| NotificationCookie {
id: "".to_string(),
time_viewed: None,
time_modal_viewed: None,
})
})
})
.collect::<Vec<NotificationCookie>>(),
_ => vec![],
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp