Skip to content

Commit

Permalink
feat(api): allow token authentication for get_sound and `list_sound…
Browse files Browse the repository at this point in the history
…s` (#18)

makes the routes `GET /api/sounds` and `GET /api/sounds/<id>` accessible via API token-based authentication

closes #17
  • Loading branch information
richard-kramer authored Jan 3, 2024
1 parent f7c1fd9 commit e1ef165
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/src/api/sounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -160,7 +161,7 @@ impl TryFrom<(models::Sound, Option<models::Soundfile>)> for Sound {
async fn list_sounds(
cache_http: &State<CacheHttp>,
db: DbConn,
user: UserId,
user: TokenUserId,
) -> Result<Json<Vec<Sound>>, SoundsError> {
let guild_ids = get_guilds_for_user(cache_http.inner(), &db, user.into())
.await?
Expand Down Expand Up @@ -195,7 +196,7 @@ async fn get_sound(
sound_id: i32,
cache_http: &State<CacheHttp>,
db: DbConn,
user: UserId,
user: TokenUserId,
) -> Result<NamedFile, SoundsError> {
let (filename, guild_id) = db
.run(move |c| {
Expand Down

0 comments on commit e1ef165

Please sign in to comment.