forked from jmug/stoatchat
Compare commits
3
Commits
20230120-2
...
20230120-4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0b918771d | ||
|
|
7a6bd70dcd | ||
|
|
c0ef3d295a |
No files matched your search
Generated
+4
-4
@@ -2580,8 +2580,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rauth"
|
name = "rauth"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
source = "git+https://github.com/insertish/rauth?tag=1.0.3#a62eae5076d94730d06e76d438cbca0d70161856"
|
source = "git+https://github.com/insertish/rauth?tag=1.0.4#2d3bc59623672e3ff57c49a90c4d3cd20780dbba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3080,8 +3080,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rocket_rauth"
|
name = "rocket_rauth"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
source = "git+https://github.com/insertish/rauth?tag=1.0.3#a62eae5076d94730d06e76d438cbca0d70161856"
|
source = "git+https://github.com/insertish/rauth?tag=1.0.4#2d3bc59623672e3ff57c49a90c4d3cd20780dbba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iso8601-timestamp",
|
"iso8601-timestamp",
|
||||||
"rauth",
|
"rauth",
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ mobc-redis = { version = "0.7.0", default-features = false, features = ["async-s
|
|||||||
# web
|
# web
|
||||||
rocket = { version = "0.5.0-rc.2", default-features = false, features = ["json"] }
|
rocket = { version = "0.5.0-rc.2", default-features = false, features = ["json"] }
|
||||||
rocket_empty = { version = "0.1.1", features = ["schema"] }
|
rocket_empty = { version = "0.1.1", features = ["schema"] }
|
||||||
rocket_rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.3" }
|
rocket_rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.4" }
|
||||||
|
|
||||||
# spec generation
|
# spec generation
|
||||||
schemars = "0.8.8"
|
schemars = "0.8.8"
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vergen(Config::default()).unwrap();
|
vergen(Config::default()).ok();
|
||||||
}
|
}
|
||||||
@@ -65,16 +65,20 @@ pub async fn message_send(
|
|||||||
data.validate()
|
data.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|
||||||
|
// Validate Message is within reasonable length limits
|
||||||
Message::validate_sum(&data.content, &data.embeds)?;
|
Message::validate_sum(&data.content, &data.embeds)?;
|
||||||
|
|
||||||
|
// Ensure the request is unique
|
||||||
idempotency.consume_nonce(data.nonce).await?;
|
idempotency.consume_nonce(data.nonce).await?;
|
||||||
|
|
||||||
|
// Ensure we have permissions to send a message
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
let mut permissions = perms(&user).channel(&channel);
|
let mut permissions = perms(&user).channel(&channel);
|
||||||
permissions
|
permissions
|
||||||
.throw_permission_and_view_channel(db, Permission::SendMessage)
|
.throw_permission_and_view_channel(db, Permission::SendMessage)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// Check the message is not empty
|
||||||
if (data.content.as_ref().map_or(true, |v| v.is_empty()))
|
if (data.content.as_ref().map_or(true, |v| v.is_empty()))
|
||||||
&& (data.attachments.as_ref().map_or(true, |v| v.is_empty()))
|
&& (data.attachments.as_ref().map_or(true, |v| v.is_empty()))
|
||||||
&& (data.embeds.as_ref().map_or(true, |v| v.is_empty()))
|
&& (data.embeds.as_ref().map_or(true, |v| v.is_empty()))
|
||||||
@@ -82,6 +86,22 @@ pub async fn message_send(
|
|||||||
return Err(Error::EmptyMessage);
|
return Err(Error::EmptyMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure restrict_reactions is not specified without reactions list
|
||||||
|
if let Some(interactions) = &data.interactions {
|
||||||
|
if interactions.restrict_reactions {
|
||||||
|
let disallowed = if let Some(list) = &interactions.reactions {
|
||||||
|
list.len() == 0
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
if disallowed {
|
||||||
|
return Err(Error::InvalidProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start constructing the message
|
||||||
let message_id = Ulid::new().to_string();
|
let message_id = Ulid::new().to_string();
|
||||||
let mut message = Message {
|
let mut message = Message {
|
||||||
id: message_id.clone(),
|
id: message_id.clone(),
|
||||||
|
|||||||
@@ -119,11 +119,12 @@ pub async fn root() -> Result<Json<RevoltConfig>> {
|
|||||||
app: APP_URL.to_string(),
|
app: APP_URL.to_string(),
|
||||||
vapid: VAPID_PUBLIC_KEY.to_string(),
|
vapid: VAPID_PUBLIC_KEY.to_string(),
|
||||||
build: BuildInformation {
|
build: BuildInformation {
|
||||||
commit_sha: env!("VERGEN_GIT_SHA").to_string(),
|
commit_sha: env!("VERGEN_GIT_SHA", "<failed to generate>").to_string(),
|
||||||
commit_timestamp: env!("VERGEN_GIT_COMMIT_TIMESTAMP").to_string(),
|
commit_timestamp: env!("VERGEN_GIT_COMMIT_TIMESTAMP", "<failed to generate>")
|
||||||
semver: env!("VERGEN_GIT_SEMVER").to_string(),
|
.to_string(),
|
||||||
origin_url: env!("GIT_ORIGIN_URL", "<missing>").to_string(),
|
semver: env!("VERGEN_GIT_SEMVER", "<failed to generate>").to_string(),
|
||||||
timestamp: env!("VERGEN_BUILD_TIMESTAMP").to_string(),
|
origin_url: env!("GIT_ORIGIN_URL", "<failed to generate>").to_string(),
|
||||||
|
timestamp: env!("VERGEN_BUILD_TIMESTAMP", "<failed to generate>").to_string(),
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
use revolt_quark::{Database, Ref, Result};
|
||||||
|
|
||||||
|
use rocket::{serde::json::Json, State};
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
/// # Flag Response
|
||||||
|
#[derive(Serialize, JsonSchema)]
|
||||||
|
pub struct FlagResponse {
|
||||||
|
/// Flags
|
||||||
|
flags: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Fetch User Flags
|
||||||
|
///
|
||||||
|
/// Retrieve a user's flags.
|
||||||
|
#[openapi(tag = "User Information")]
|
||||||
|
#[get("/<target>/flags")]
|
||||||
|
pub async fn fetch_user_flags(db: &State<Database>, target: Ref) -> Result<Json<FlagResponse>> {
|
||||||
|
let flags = if let Ok(target) = target.as_user(db).await {
|
||||||
|
target.flags.unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Json(FlagResponse { flags }))
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ mod fetch_dms;
|
|||||||
mod fetch_profile;
|
mod fetch_profile;
|
||||||
mod fetch_self;
|
mod fetch_self;
|
||||||
mod fetch_user;
|
mod fetch_user;
|
||||||
|
mod fetch_user_flags;
|
||||||
mod find_mutual;
|
mod find_mutual;
|
||||||
mod get_default_avatar;
|
mod get_default_avatar;
|
||||||
mod open_dm;
|
mod open_dm;
|
||||||
@@ -21,6 +22,7 @@ pub fn routes() -> (Vec<Route>, OpenApi) {
|
|||||||
// User Information
|
// User Information
|
||||||
fetch_self::req,
|
fetch_self::req,
|
||||||
fetch_user::req,
|
fetch_user::req,
|
||||||
|
fetch_user_flags::fetch_user_flags,
|
||||||
edit_user::req,
|
edit_user::req,
|
||||||
change_username::req,
|
change_username::req,
|
||||||
get_default_avatar::req,
|
get_default_avatar::req,
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ rocket_empty = { version = "0.1.1", optional = true, features = [ "schema" ] }
|
|||||||
rocket_cors = { optional = true, git = "https://github.com/lawliet89/rocket_cors", rev = "c17e8145baa4790319fdb6a473e465b960f55e7c" }
|
rocket_cors = { optional = true, git = "https://github.com/lawliet89/rocket_cors", rev = "c17e8145baa4790319fdb6a473e465b960f55e7c" }
|
||||||
|
|
||||||
# rAuth
|
# rAuth
|
||||||
rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.3", features = [ "async-std-runtime" ] }
|
rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.4", features = [ "async-std-runtime" ] }
|
||||||
|
|
||||||
# Sentry
|
# Sentry
|
||||||
sentry = "0.25.0"
|
sentry = "0.25.0"
|
||||||
@@ -98,6 +98,8 @@ pub struct Interactions {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
pub reactions: Option<IndexSet<String>>,
|
pub reactions: Option<IndexSet<String>>,
|
||||||
/// Whether reactions should be restricted to the given list
|
/// Whether reactions should be restricted to the given list
|
||||||
|
///
|
||||||
|
/// Can only be set to true if reactions list is of at least length 1
|
||||||
#[serde(skip_serializing_if = "if_false", default)]
|
#[serde(skip_serializing_if = "if_false", default)]
|
||||||
pub restrict_reactions: bool,
|
pub restrict_reactions: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ pub enum Error {
|
|||||||
/// This error was not labeled :(
|
/// This error was not labeled :(
|
||||||
LabelMe,
|
LabelMe,
|
||||||
|
|
||||||
// ? Onboarding related errors.
|
// ? Onboarding related errors
|
||||||
AlreadyOnboarded,
|
AlreadyOnboarded,
|
||||||
|
|
||||||
// ? User related errors.
|
// ? User related errors
|
||||||
UsernameTaken,
|
UsernameTaken,
|
||||||
InvalidUsername,
|
InvalidUsername,
|
||||||
UnknownUser,
|
UnknownUser,
|
||||||
@@ -33,7 +33,7 @@ pub enum Error {
|
|||||||
BlockedByOther,
|
BlockedByOther,
|
||||||
NotFriends,
|
NotFriends,
|
||||||
|
|
||||||
// ? Channel related errors.
|
// ? Channel related errors
|
||||||
UnknownChannel,
|
UnknownChannel,
|
||||||
UnknownAttachment,
|
UnknownAttachment,
|
||||||
UnknownMessage,
|
UnknownMessage,
|
||||||
@@ -50,7 +50,7 @@ pub enum Error {
|
|||||||
AlreadyInGroup,
|
AlreadyInGroup,
|
||||||
NotInGroup,
|
NotInGroup,
|
||||||
|
|
||||||
// ? Server related errors.
|
// ? Server related errors
|
||||||
UnknownServer,
|
UnknownServer,
|
||||||
InvalidRole,
|
InvalidRole,
|
||||||
Banned,
|
Banned,
|
||||||
@@ -59,12 +59,12 @@ pub enum Error {
|
|||||||
},
|
},
|
||||||
TooManyEmoji,
|
TooManyEmoji,
|
||||||
|
|
||||||
// ? Bot related errors.
|
// ? Bot related errors
|
||||||
ReachedMaximumBots,
|
ReachedMaximumBots,
|
||||||
IsBot,
|
IsBot,
|
||||||
BotIsPrivate,
|
BotIsPrivate,
|
||||||
|
|
||||||
// ? Permission errors.
|
// ? Permission errors
|
||||||
MissingPermission {
|
MissingPermission {
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
},
|
},
|
||||||
@@ -75,7 +75,7 @@ pub enum Error {
|
|||||||
CannotGiveMissingPermissions,
|
CannotGiveMissingPermissions,
|
||||||
NotOwner,
|
NotOwner,
|
||||||
|
|
||||||
// ? General errors.
|
// ? General errors
|
||||||
DatabaseError {
|
DatabaseError {
|
||||||
operation: &'static str,
|
operation: &'static str,
|
||||||
with: &'static str,
|
with: &'static str,
|
||||||
@@ -83,6 +83,7 @@ pub enum Error {
|
|||||||
InternalError,
|
InternalError,
|
||||||
InvalidOperation,
|
InvalidOperation,
|
||||||
InvalidCredentials,
|
InvalidCredentials,
|
||||||
|
InvalidProperty,
|
||||||
InvalidSession,
|
InvalidSession,
|
||||||
DuplicateNonce,
|
DuplicateNonce,
|
||||||
VosoUnavailable,
|
VosoUnavailable,
|
||||||
@@ -175,6 +176,7 @@ impl<'r> Responder<'r, 'static> for Error {
|
|||||||
Error::InternalError => Status::InternalServerError,
|
Error::InternalError => Status::InternalServerError,
|
||||||
Error::InvalidOperation => Status::BadRequest,
|
Error::InvalidOperation => Status::BadRequest,
|
||||||
Error::InvalidCredentials => Status::Unauthorized,
|
Error::InvalidCredentials => Status::Unauthorized,
|
||||||
|
Error::InvalidProperty => Status::BadRequest,
|
||||||
Error::InvalidSession => Status::Unauthorized,
|
Error::InvalidSession => Status::Unauthorized,
|
||||||
Error::DuplicateNonce => Status::Conflict,
|
Error::DuplicateNonce => Status::Conflict,
|
||||||
Error::VosoUnavailable => Status::BadRequest,
|
Error::VosoUnavailable => Status::BadRequest,
|
||||||
|
|||||||
Reference in new issue
Block a user