add seperate non token webhook routes
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
use revolt_quark::{Db, Ref, Result, Error, models::Webhook};
|
||||
use revolt_quark::{Db, Ref, Result, models::{Webhook, File}};
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
|
||||
// This route is used to get the info about the webhook by clients to get the name and avatar,
|
||||
// so this function cant return the token or require any permissions.
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
|
||||
pub struct WebhookData {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub avatar: Option<File>,
|
||||
pub channel: String,
|
||||
}
|
||||
|
||||
/// # gets a webhook
|
||||
///
|
||||
/// gets a webhook
|
||||
#[openapi(tag = "Webhooks")]
|
||||
#[get("/<target>/<token>")]
|
||||
pub async fn req(db: &Db, target: Ref, token: String) -> Result<Json<Webhook>> {
|
||||
let webhook = target.as_webhook(db).await?;
|
||||
#[get("/<target>")]
|
||||
pub async fn req(db: &Db, target: Ref) -> Result<Json<WebhookData>> {
|
||||
let Webhook { id, name, avatar, channel, .. } = target.as_webhook(db).await?;
|
||||
|
||||
(webhook.token == token)
|
||||
.then_some(())
|
||||
.ok_or(Error::InvalidCredentials)?;
|
||||
|
||||
Ok(Json(webhook))
|
||||
Ok(Json(WebhookData { id, name, avatar, channel }))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user