forked from jmug/stoatchat
chore(thanos): strip down codebase to just API routes
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
use crate::database::*;
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{EmptyResponse, Error, Result};
|
||||
use revolt_quark::{EmptyResponse, Result};
|
||||
|
||||
use chrono::prelude::*;
|
||||
use mongodb::bson::{doc, to_bson};
|
||||
@@ -18,57 +16,6 @@ pub struct Options {
|
||||
}
|
||||
|
||||
#[post("/settings/set?<options..>", data = "<data>")]
|
||||
pub async fn req(user: User, data: Json<Data>, options: Options) -> Result<EmptyResponse> {
|
||||
if user.bot.is_some() {
|
||||
return Err(Error::IsBot);
|
||||
}
|
||||
|
||||
let data = data.into_inner();
|
||||
let current_time = Utc::now().timestamp_millis();
|
||||
let timestamp = if let Some(timestamp) = options.timestamp {
|
||||
if timestamp > current_time {
|
||||
current_time
|
||||
} else {
|
||||
timestamp
|
||||
}
|
||||
} else {
|
||||
current_time
|
||||
};
|
||||
|
||||
let mut set = doc! {};
|
||||
for (key, data) in &data {
|
||||
set.insert(
|
||||
key.clone(),
|
||||
vec![
|
||||
to_bson(×tamp).unwrap(),
|
||||
to_bson(&data.clone()).unwrap(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
if set.len() > 0 {
|
||||
get_collection("user_settings")
|
||||
.update_one(
|
||||
doc! {
|
||||
"_id": &user.id
|
||||
},
|
||||
doc! {
|
||||
"$set": &set
|
||||
},
|
||||
UpdateOptions::builder().upsert(true).build(),
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user_settings",
|
||||
})?;
|
||||
}
|
||||
|
||||
ClientboundNotification::UserSettingsUpdate {
|
||||
id: user.id.clone(),
|
||||
update: json!(set),
|
||||
}
|
||||
.publish(user.id);
|
||||
|
||||
Ok(EmptyResponse {})
|
||||
pub async fn req(/*user: UserRef,*/ data: Json<Data>, options: Options) -> Result<EmptyResponse> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user