From e1ef165ef0b63d51d021d50a9b2a5d629a958d24 Mon Sep 17 00:00:00 2001 From: Richard Kramer <34233066+richard-kramer@users.noreply.github.com> Date: Wed, 3 Jan 2024 20:25:25 +0100 Subject: [PATCH] feat(api): allow token authentication for `get_sound` and `list_sounds` (#18) makes the routes `GET /api/sounds` and `GET /api/sounds/` accessible via API token-based authentication closes #17 --- backend/src/api/sounds.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/api/sounds.rs b/backend/src/api/sounds.rs index c80bda2..112c74f 100644 --- a/backend/src/api/sounds.rs +++ b/backend/src/api/sounds.rs @@ -22,6 +22,7 @@ use serde_with::TimestampSeconds; use serenity::model::id::GuildId; use tokio::fs; +use crate::api::auth::TokenUserId; use crate::api::auth::UserId; use crate::api::Snowflake; use crate::audio_utils; @@ -160,7 +161,7 @@ impl TryFrom<(models::Sound, Option)> for Sound { async fn list_sounds( cache_http: &State, db: DbConn, - user: UserId, + user: TokenUserId, ) -> Result>, SoundsError> { let guild_ids = get_guilds_for_user(cache_http.inner(), &db, user.into()) .await? @@ -195,7 +196,7 @@ async fn get_sound( sound_id: i32, cache_http: &State, db: DbConn, - user: UserId, + user: TokenUserId, ) -> Result { let (filename, guild_id) = db .run(move |c| {