556ZESEOBASTGBUTQ5H5UIHLSUQCFL2JKYY3UMCZILYDUVEBN6NAC
HZDCKIXQ3LCD7YPL7ZZBCRMD7YMKDJ2QAALETTG3FYMBF4TNFUBAC
WVHXYKCVPKAFVMXBEMD3IHG54RKOIDSOCVNR3OIPEZQG36IGYJZQC
CMA5SKJ32PZJNZ2HUMESFZRXN4OYEHXDG2YONGED2336DBUY764AC
EVP2FSBHQUCAXQ6IIMBD6IS24ODKHP6HFWYCHIMYG6KOFRQG3RVQC
4MZ4VIR7FU3PQ3WKJI6TJIKYOIIBODFEPKLMQ32S4AKPZSDFO6AQC
BCXEUKX6RVE4UQE46ITSQY2NXYK3MJT7HHL7CJOM7T4OOOCADMIAC
IM5ZPD4NEWQ67NSRP3M4R6FBET5HLY5YCX6WOTGGVWIMRGFD3L3AC
72WRIXYST6CUSN3CYPEFEP3WCJYCHSIZINJSPSHVMWSJ22X5SHDQC
OJO4B4QO2JQLMZTGTJJIXEUNDIN45RFLEJBUZBYA7IS34XDPUAVAC
XMUKNMKYXU7IGJFZ7JEYTLGQK34KBECXEPPZ7HAKKUHMUOMVFSJAC
use actix_web::{web, HttpResponse};
use crate::pages::templates::ATOM_GAMES;
use crate::WebData;
#[derive(serde_derive::Serialize)]
struct FeedData {
upddatetime: String,
entries: Vec<EntriesData>,
selflink: String,
}
#[derive(serde_derive::Serialize)]
struct EntriesData {
gameuid: String,
gameuidenc: String,
start_ts: i64,
create_ts_str: String,
fo_forum_url: String,
}
#[actix_web::get("/atoms/new-games.xml")]
pub async fn atom_games(data: web::Data<WebData<'_>>) -> HttpResponse {
let dbclient = match data.pool_ro.get().await {
Ok(client) => client,
Err(e) => {
log::error!("{}", e);
return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
}
};
let stmt = match dbclient.prepare("select g.game_uid, g.start_ts, g.fo_forum_url, g.create_ts from games.games g where g.create_ts IS NOT NULL and g.fo_forum_url IS NOT NULL order by g.create_ts desc limit 50;").await {
Ok(stmt) => stmt,
Err(e) => {
log::error!("{}", e);
return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
}
};
let rows = match dbclient.query(&stmt, &[]).await {
Ok(rows) => rows,
Err(e) => {
log::error!("{}", e);
return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
}
};
let mut upd_date_time = None;
let mut entries = Vec::with_capacity(rows.len());
for row in rows {
let gameuid = row.get::<_, &str>(0);
let start_ts = chrono::DateTime::<chrono::Utc>::from_utc(
row.get::<_, chrono::NaiveDateTime>(1),
chrono::Utc,
);
let fo_forum_url = row.get::<_, &str>(2);
let create_ts =
chrono::DateTime::from_utc(row.get::<_, chrono::NaiveDateTime>(3), chrono::Utc);
entries.insert(
0,
EntriesData {
gameuid: gameuid.to_string(),
gameuidenc: pct_str::PctString::encode(gameuid.chars(), pct_str::URIReserved)
.into_string(),
start_ts: start_ts.timestamp(),
create_ts_str: create_ts.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
fo_forum_url: fo_forum_url.to_string(),
},
);
upd_date_time.get_or_insert(create_ts);
}
let upd_date_time = upd_date_time.unwrap_or_else(chrono::Utc::now);
let body = match data.handlebars.render(
ATOM_GAMES,
&FeedData {
entries,
upddatetime: upd_date_time.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
selflink: data.base_url.to_string(),
},
) {
Ok(b) => b,
Err(e) => {
log::error!("{}", e);
return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
}
};
HttpResponse::Ok()
.insert_header(("Content-Type", "application/atom+xml"))
.insert_header((
"Date",
upd_date_time
.format("%a, %d %b %Y %H:%M:%S GMT")
.to_string(),
))
.body(body)
}
name = "mio"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2"
dependencies = [
"libc",
"log",
"miow",
"ntapi",
"winapi",
]
[[package]]
"parking_lot_core",
"parking_lot_core 0.8.5",
]
[[package]]
name = "parking_lot"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
dependencies = [
"lock_api",
"parking_lot_core 0.9.2",
name = "rand_hc"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
dependencies = [
"rand_core",
]
[[package]]
name = "tokio-util"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
"tracing",
]
[[package]]
[[package]]
name = "windows-sys"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5acdd78cb4ba54c0045ac14f62d8f94a03d10047904ae2a40afa1e99d8f70825"
dependencies = [
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_msvc"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d"
[[package]]
name = "windows_i686_gnu"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed"
[[package]]
name = "windows_i686_msvc"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956"
[[package]]
name = "windows_x86_64_gnu"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4"