Implemented API Key creation/usage and changed layout of audio requests
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use std::sync::Arc;
|
||||
use axum::extract::State;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::middleware::from_extractor;
|
||||
use axum::{Extension, Json, Router};
|
||||
use axum::response::IntoResponse;
|
||||
use axum::routing::post;
|
||||
use reqwest::StatusCode;
|
||||
use serde::Deserialize;
|
||||
use crate::api::auth::{AuthorizationMiddleware, Session};
|
||||
use crate::api::auth::{AuthCredential, AuthorizationMiddleware, Session};
|
||||
use crate::AppState;
|
||||
use crate::bot::commands::audio::join_voice_channel;
|
||||
use crate::bot::commands::audio::pause::pause_track;
|
||||
@@ -28,24 +28,25 @@ pub fn get_routes() -> Router<Arc<AppState>> {
|
||||
#[derive(Deserialize)]
|
||||
struct PlayTrackRequest {
|
||||
url: String,
|
||||
guild_id: u64,
|
||||
}
|
||||
|
||||
async fn play_audio(
|
||||
Extension(session): Extension<Session>,
|
||||
Extension(credential): Extension<AuthCredential>,
|
||||
State(state): State<Arc<AppState>>,
|
||||
Path(guild_id): Path<u64>,
|
||||
Json(payload): Json<PlayTrackRequest>,
|
||||
) -> SirenResult<()> {
|
||||
log::debug!("Playing audio in guild: {}", payload.guild_id);
|
||||
log::debug!("Playing audio in guild: {}", guild_id);
|
||||
|
||||
// Check if the user exists in the cache
|
||||
let user_id = match state.cache.user(session.user_id) {
|
||||
let user_id = credential.user_id();
|
||||
let user_id = match state.cache.user(user_id) {
|
||||
Some(user) => user.id,
|
||||
None => return Err(Error::not_found("User not found".to_string())),
|
||||
};
|
||||
|
||||
// Validate if the guild exists in the cache
|
||||
let guild_id = match state.cache.guild(payload.guild_id) {
|
||||
let guild_id = match state.cache.guild(guild_id) {
|
||||
Some(guild) => guild.id,
|
||||
None => return Err(Error::not_found("Guild not found".to_string())),
|
||||
};
|
||||
@@ -57,20 +58,15 @@ async fn play_audio(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct GuildTrackRequest {
|
||||
guild_id: u64,
|
||||
}
|
||||
|
||||
async fn pause_audio(
|
||||
Extension(_): Extension<Session>,
|
||||
Extension(_): Extension<AuthCredential>,
|
||||
State(state): State<Arc<AppState>>,
|
||||
Json(payload): Json<GuildTrackRequest>,
|
||||
Path(guild_id): Path<u64>,
|
||||
) -> SirenResult<()> {
|
||||
log::debug!("Pausing audio in guild: {}", payload.guild_id);
|
||||
log::debug!("Pausing audio in guild: {}", guild_id);
|
||||
|
||||
// Validate if the guild exists in the cache
|
||||
let guild_id = match state.cache.guild(payload.guild_id) {
|
||||
let guild_id = match state.cache.guild(guild_id) {
|
||||
Some(guild) => guild.id,
|
||||
None => return Err(Error::not_found("Guild not found".to_string())),
|
||||
};
|
||||
@@ -81,14 +77,14 @@ async fn pause_audio(
|
||||
}
|
||||
|
||||
async fn resume_audio(
|
||||
Extension(_): Extension<Session>,
|
||||
Extension(_): Extension<AuthCredential>,
|
||||
State(state): State<Arc<AppState>>,
|
||||
Json(payload): Json<GuildTrackRequest>,
|
||||
Path(guild_id): Path<u64>,
|
||||
) -> SirenResult<()> {
|
||||
log::debug!("Pausing audio in guild: {}", payload.guild_id);
|
||||
log::debug!("Pausing audio in guild: {}", guild_id);
|
||||
|
||||
// Validate if the guild exists in the cache
|
||||
let guild_id = match state.cache.guild(payload.guild_id) {
|
||||
let guild_id = match state.cache.guild(guild_id) {
|
||||
Some(guild) => guild.id,
|
||||
None => return Err(Error::not_found("Guild not found".to_string())),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user