From 188fe30dbfc32065ee702fe8c7c1d25226650669 Mon Sep 17 00:00:00 2001
From: Paul Makles <paulmakles@gmail.com>
Date: Sun, 21 Jun 2020 17:47:27 +0100
Subject: [PATCH] Add OPTIONS preflight.

---
 src/routes/account.rs | 11 ++++++-----
 src/routes/channel.rs |  6 ++++++
 src/routes/guild.rs   | 11 +++++++++++
 src/routes/mod.rs     | 34 +++++++++++++++++++++++++++++++---
 src/routes/user.rs    |  7 +++++++
 5 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/src/routes/account.rs b/src/routes/account.rs
index dff2adc..dff40f6 100644
--- a/src/routes/account.rs
+++ b/src/routes/account.rs
@@ -216,11 +216,6 @@ pub struct Login {
     password: String,
 }
 
-#[options("/login")]
-pub fn login_preflight() -> Response {
-    Response::Result(super::Status::Ok)
-}
-
 /// login to a Revolt account
 /// (1) find user by email
 /// (2) verify password
@@ -295,3 +290,9 @@ pub fn token(info: Json<Token>) -> Response {
         }))
     }
 }
+
+#[options("/create")] pub fn create_preflight() -> Response { Response::Result(super::Status::Ok) }
+#[options("/verify/<_code>")] pub fn verify_email_preflight(_code: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/resend")] pub fn resend_email_preflight() -> Response { Response::Result(super::Status::Ok) }
+#[options("/login")] pub fn login_preflight() -> Response { Response::Result(super::Status::Ok) }
+#[options("/token")] pub fn token_preflight() -> Response { Response::Result(super::Status::Ok) }
diff --git a/src/routes/channel.rs b/src/routes/channel.rs
index 971ce17..eba1d5c 100644
--- a/src/routes/channel.rs
+++ b/src/routes/channel.rs
@@ -686,3 +686,9 @@ pub fn delete_message(user: UserRef, target: ChannelRef, message: Message) -> Op
         )),
     }
 }
+
+#[options("/create")] pub fn create_group_preflight() -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>")] pub fn channel_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/recipients/<_member>")] pub fn member_preflight(_target: String, _member: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/messages")] pub fn messages_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/messages/<_message>")] pub fn message_preflight(_target: String, _message: String) -> Response { Response::Result(super::Status::Ok) }
diff --git a/src/routes/guild.rs b/src/routes/guild.rs
index eb0d49c..5e8cfe0 100644
--- a/src/routes/guild.rs
+++ b/src/routes/guild.rs
@@ -838,3 +838,14 @@ pub fn unban_member(user: UserRef, target: GuildRef, other: String) -> Option<Re
         ))
     }
 }
+
+#[options("/<_target>")] pub fn guild_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/channels")] pub fn create_channel_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/channels/<_channel>/invite")] pub fn create_invite_preflight(_target: String, _channel: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/invites/<_code>")] pub fn remove_invite_preflight(_target: String, _code: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/invites")] pub fn fetch_invites_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/join/<_code>", rank = 1)] pub fn invite_preflight(_code: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/create")] pub fn create_guild_preflight() -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/members")] pub fn fetch_members_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/members/<_other>")] pub fn fetch_member_preflight(_target: String, _other: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/members/<_other>/ban")] pub fn ban_member_preflight(_target: String, _other: String) -> Response { Response::Result(super::Status::Ok) }
diff --git a/src/routes/mod.rs b/src/routes/mod.rs
index 8ae073c..5b9d713 100644
--- a/src/routes/mod.rs
+++ b/src/routes/mod.rs
@@ -71,7 +71,11 @@ pub fn mount(rocket: Rocket) -> Rocket {
                 account::login,
                 account::token,
 
+                account::create_preflight,
+                account::verify_email_preflight,
+                account::resend_email_preflight,
                 account::login_preflight,
+                account::token_preflight,
             ],
         )
         .mount(
@@ -87,7 +91,14 @@ pub fn mount(rocket: Rocket) -> Rocket {
                 user::add_friend,
                 user::remove_friend,
                 user::block_user,
-                user::unblock_user
+                user::unblock_user,
+
+                user::user_preflight,
+                user::lookup_preflight,
+                user::dms_preflight,
+                user::dm_preflight,
+                user::friend_preflight,
+                user::block_user_preflight,
             ],
         )
         .mount(
@@ -102,7 +113,13 @@ pub fn mount(rocket: Rocket) -> Rocket {
                 channel::get_message,
                 channel::send_message,
                 channel::edit_message,
-                channel::delete_message
+                channel::delete_message,
+
+                channel::create_group_preflight,
+                channel::channel_preflight,
+                channel::member_preflight,
+                channel::messages_preflight,
+                channel::message_preflight,
             ],
         )
         .mount(
@@ -122,7 +139,18 @@ pub fn mount(rocket: Rocket) -> Rocket {
                 guild::fetch_member,
                 guild::kick_member,
                 guild::ban_member,
-                guild::unban_member
+                guild::unban_member,
+
+                guild::guild_preflight,
+                guild::create_channel_preflight,
+                guild::create_invite_preflight,
+                guild::remove_invite_preflight,
+                guild::fetch_invites_preflight,
+                guild::invite_preflight,
+                guild::create_guild_preflight,
+                guild::fetch_members_preflight,
+                guild::fetch_member_preflight,
+                guild::ban_member_preflight,
             ],
         )
 }
diff --git a/src/routes/user.rs b/src/routes/user.rs
index e41b145..fcf237e 100644
--- a/src/routes/user.rs
+++ b/src/routes/user.rs
@@ -705,3 +705,10 @@ pub fn unblock_user(user: UserRef, target: UserRef) -> Response {
         | Relationship::NONE => Response::BadRequest(json!({ "error": "This has no effect." })),
     }
 }
+
+#[options("/<_target>")] pub fn user_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/lookup")] pub fn lookup_preflight() -> Response { Response::Result(super::Status::Ok) }
+#[options("/@me/dms")] pub fn dms_preflight() -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/dm")] pub fn dm_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/friend")] pub fn friend_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
+#[options("/<_target>/block")] pub fn block_user_preflight(_target: String) -> Response { Response::Result(super::Status::Ok) }
-- 
GitLab