FUCKING SHIT RUST SHIT LANGUAGE FOR RETARDS
This commit is contained in:
parent
3892d15c7e
commit
a33fbf5997
|
@ -263,6 +263,17 @@ pub async fn read_random_channel_line(db: &Client, channel_id: &str) -> Result<S
|
|||
// Ok(())
|
||||
// }
|
||||
|
||||
pub async fn read_last_message(db: &Client, user_id: &str) -> Result<String> {
|
||||
let text = db
|
||||
.query("SELECT (*) FROM message WHERE user_id = ? ORDER BY timestamp DESC LIMIT 1")
|
||||
.bind(user_id)
|
||||
.fetch_optional::<String>()
|
||||
.await?
|
||||
.ok_or(Error::NotFound)?;
|
||||
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
fn apply_limit_offset(query: &mut String, limit: Option<u64>, offset: Option<u64>) {
|
||||
if let Some(limit) = limit {
|
||||
*query = format!("{query} LIMIT {limit}");
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
app::App,
|
||||
db::{
|
||||
read_available_channel_logs, read_available_user_logs, read_channel,
|
||||
read_random_channel_line, read_random_user_line, read_user,
|
||||
read_random_channel_line, read_random_user_line, read_user, read_last_message
|
||||
},
|
||||
error::Error,
|
||||
logs::{schema::LogRangeParams, stream::LogsStream},
|
||||
|
@ -369,6 +369,43 @@ async fn random_user_line(
|
|||
Ok((no_cache_header(), logs))
|
||||
}
|
||||
|
||||
pub async fn last_message_by_name(
|
||||
app: State<App>,
|
||||
Path(UserLogPathParams2 {
|
||||
user,
|
||||
}): Path<UserLogPathParams2>,
|
||||
query: Query<LogsParams>,
|
||||
) -> Result<impl IntoApiResponse> {
|
||||
let user_id = app.get_user_id_by_name(&user).await?;
|
||||
last_message(app, user_id, query).await
|
||||
}
|
||||
|
||||
pub async fn last_message_by_id(
|
||||
app: State<App>,
|
||||
Path(UserLogPathParams2 {
|
||||
user,
|
||||
}): Path<UserLogPathParams2>,
|
||||
query: Query<LogsParams>,
|
||||
) -> Result<impl IntoApiResponse> {
|
||||
last_message(app, user, query).await
|
||||
}
|
||||
|
||||
async fn last_message(
|
||||
app: State<App>,
|
||||
user_id: String,
|
||||
Query(logs_params): Query<LogsParams>,
|
||||
) -> Result<impl IntoApiResponse> {
|
||||
|
||||
let last_message = read_last_message(&app.db, &user_id).await?;
|
||||
let stream = LogsStream::new_provided(vec![last_message])?;
|
||||
|
||||
let logs = LogsResponse {
|
||||
stream,
|
||||
response_type: logs_params.response_type(),
|
||||
};
|
||||
Ok((no_cache_header(), logs))
|
||||
}
|
||||
|
||||
// pub async fn optout(app: State<App>) -> Json<String> {
|
||||
// let mut rng = thread_rng();
|
||||
// let optout_code: String = (0..5).map(|_| rng.sample(Alphanumeric) as char).collect();
|
||||
|
|
|
@ -137,6 +137,24 @@ pub async fn run(app: App, mut shutdown_rx: ShutdownRx, bot_tx: Sender<BotMessag
|
|||
op.description("Get a random line from the user's logs in a channel")
|
||||
}),
|
||||
)
|
||||
.api_route(
|
||||
"/:channel_id_type/:channel/userid/:user/stalk",
|
||||
get_with(handlers::last_message_by_id, |op| {
|
||||
op.description("Get the last message of a user")
|
||||
}),
|
||||
)
|
||||
.api_route(
|
||||
"/:channel_id_type/:channel/user/:user/stalk",
|
||||
get_with(handlers::last_message_by_name, |op| {
|
||||
op.description("Get the last message of a user")
|
||||
}),
|
||||
)
|
||||
.api_route(
|
||||
"/:channel_id_type/:channel/user/:user/stalk",
|
||||
get_with(handlers::last_message, |op| {
|
||||
op.description("Get the last message of a user")
|
||||
}),
|
||||
)
|
||||
// .api_route("/optout", post(handlers::optout))
|
||||
.api_route("/capabilities", get(capabilities))
|
||||
.route("/docs", Redoc::new("/openapi.json").axum_route())
|
||||
|
|
|
@ -63,6 +63,11 @@ pub struct LogsPathChannel {
|
|||
pub channel: String,
|
||||
}
|
||||
|
||||
pub struct LogsPathUser {
|
||||
pub channel_id_type: ChannelIdType,
|
||||
pub channel: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, JsonSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LogsParams {
|
||||
|
@ -157,3 +162,7 @@ pub struct UserLogPathParams {
|
|||
pub channel: String,
|
||||
pub user: String,
|
||||
}
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct UserLogPathParams2 {
|
||||
pub user: String
|
||||
}
|
||||
|
|
2
web
2
web
|
@ -1 +1 @@
|
|||
Subproject commit 06e83668e03f2beb518a6e414ca6932c7408fef6
|
||||
Subproject commit efedc8c5252e101950e2e9d1c202cc746ad7d441
|
Loading…
Reference in New Issue