Accepts ad with no pubkey
This commit is contained in:
parent
59c69765d7
commit
6a70bfc032
|
@ -121,28 +121,31 @@ pub async fn start_server(
|
|||
.and(warp::get())
|
||||
.and(warp::fs::dir(opt.dir.0.join(static_files::STATIC_DIR)));
|
||||
|
||||
let handle_new_ad =
|
||||
{
|
||||
let handle_index = handle_index.clone();
|
||||
let dbs = dbs.clone();
|
||||
let cache_ads = cache_ads.clone();
|
||||
move |query: NewAdQuery| {
|
||||
let mut hasher = Sha512Trunc256::new();
|
||||
hasher.update(query.psw);
|
||||
dbs.ads
|
||||
let handle_new_ad = {
|
||||
let handle_index = handle_index.clone();
|
||||
let dbs = dbs.clone();
|
||||
let cache_ads = cache_ads.clone();
|
||||
move |query: NewAdQuery| {
|
||||
let mut hasher = Sha512Trunc256::new();
|
||||
hasher.update(query.psw);
|
||||
dbs.ads
|
||||
.insert(
|
||||
AdId::random(),
|
||||
bincode::serialize(&Ad {
|
||||
author: query.author,
|
||||
password: hasher.finalize()[..].try_into().unwrap(),
|
||||
price: query.price,
|
||||
pubkey: (!query.pubkey.is_empty()).then_some(match format_pubkey(&query.pubkey) {
|
||||
pubkey: if query.pubkey.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(match format_pubkey(&query.pubkey) {
|
||||
Ok(pubkey) => pubkey,
|
||||
Err(e) => return handle_index(&[ErrorTemplate{text: match e {
|
||||
PubkeyDecodeError::BadChecksum => "La somme de contrôle de la clé publique est incorrecte.",
|
||||
PubkeyDecodeError::BadFormat => "Le format de la clé publique est incorrect.",
|
||||
}}])
|
||||
}),
|
||||
})
|
||||
},
|
||||
quantity: query.quantity,
|
||||
time: 0,
|
||||
title: query.title,
|
||||
|
@ -150,24 +153,24 @@ pub async fn start_server(
|
|||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
dbs.ads.flush().unwrap();
|
||||
let mut cache_ads = cache_ads.write().unwrap();
|
||||
*cache_ads = to_json(
|
||||
dbs.ads
|
||||
.iter()
|
||||
.filter_map(|x| {
|
||||
let (ad_id, ad) = x.ok()?;
|
||||
Some(AdWithId {
|
||||
id: hex::encode(ad_id.as_ref()),
|
||||
ad: bincode::deserialize::<Ad>(&ad).ok()?,
|
||||
})
|
||||
dbs.ads.flush().unwrap();
|
||||
let mut cache_ads = cache_ads.write().unwrap();
|
||||
*cache_ads = to_json(
|
||||
dbs.ads
|
||||
.iter()
|
||||
.filter_map(|x| {
|
||||
let (ad_id, ad) = x.ok()?;
|
||||
Some(AdWithId {
|
||||
id: hex::encode(ad_id.as_ref()),
|
||||
ad: bincode::deserialize::<Ad>(&ad).ok()?,
|
||||
})
|
||||
.collect::<Vec<AdWithId>>(),
|
||||
);
|
||||
drop(cache_ads);
|
||||
redirect_302("/").into_response()
|
||||
}
|
||||
};
|
||||
})
|
||||
.collect::<Vec<AdWithId>>(),
|
||||
);
|
||||
drop(cache_ads);
|
||||
redirect_302("/").into_response()
|
||||
}
|
||||
};
|
||||
|
||||
let handle_rm_ad = {
|
||||
let handle_index = handle_index.clone();
|
||||
|
|
Loading…
Reference in New Issue