-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
64 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod model; | ||
pub use model::Element; | ||
pub mod admin; | ||
pub mod rpc; | ||
pub mod service; | ||
pub mod v2; | ||
pub mod v3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use crate::discord; | ||
use crate::Result; | ||
use crate::{auth::Token, element::model::Element}; | ||
use deadpool_sqlite::Pool; | ||
use jsonrpc_v2::{Data, Params}; | ||
use rusqlite::Connection; | ||
use serde::Deserialize; | ||
use serde_json::Value; | ||
use std::sync::Arc; | ||
use time::format_description::well_known::Iso8601; | ||
use time::Duration; | ||
use time::OffsetDateTime; | ||
use tracing::info; | ||
|
||
#[derive(Deserialize)] | ||
pub struct BoostElementArgs { | ||
pub token: String, | ||
pub element_id: String, | ||
pub days: i64, | ||
} | ||
|
||
pub async fn boost( | ||
Params(args): Params<BoostElementArgs>, | ||
pool: Data<Arc<Pool>>, | ||
) -> Result<Element> { | ||
let token = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| Token::select_by_secret(&args.token, conn)) | ||
.await?? | ||
.unwrap(); | ||
let element = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| _boost(&args.element_id, args.days, conn)) | ||
.await??; | ||
let log_message = format!( | ||
"{} boosted element {} https://api.btcmap.org/v3/elements/{} for {} days", | ||
token.owner, | ||
element.name(), | ||
element.id, | ||
args.days, | ||
); | ||
info!(log_message); | ||
discord::send_message_to_channel(&log_message, discord::CHANNEL_API).await; | ||
Ok(element) | ||
} | ||
|
||
fn _boost(id_or_osm_id: &str, days: i64, conn: &Connection) -> Result<Element> { | ||
let element = Element::select_by_id_or_osm_id(id_or_osm_id, conn)?.unwrap(); | ||
let boost_expires = element.tag("boost:expires"); | ||
let boost_expires = match boost_expires { | ||
Value::String(v) => { | ||
OffsetDateTime::parse(v, &Iso8601::DEFAULT).unwrap_or(OffsetDateTime::now_utc()) | ||
} | ||
_ => OffsetDateTime::now_utc(), | ||
}; | ||
|
||
let boost_expires = boost_expires.checked_add(Duration::days(days)).unwrap(); | ||
let element = Element::set_tag( | ||
element.id, | ||
"boost:expires", | ||
&Value::String(boost_expires.format(&Iso8601::DEFAULT)?), | ||
&conn, | ||
)?; | ||
Ok(element) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters