40 lines
1.6 KiB
Rust
40 lines
1.6 KiB
Rust
/*
|
|
* Yggdrasil: Minecraft authentication server
|
|
* Copyright (C) 2023 0xf8.dev@proton.me
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
use anyhow::anyhow;
|
|
use log::debug;
|
|
use tide::{prelude::*, Request, Result};
|
|
|
|
use yggdrasil::Database;
|
|
use yggdrasil::errors::YggdrasilError;
|
|
use yggdrasil::structs::profile::Profile;
|
|
use yggdrasil::structs::textured_object::TexturedObject;
|
|
use yggdrasil::structs::token::Token;
|
|
|
|
// TODO: unsigned?
|
|
pub async fn profile(mut req: Request<Database>) -> Result {
|
|
let Ok(uuid) = req.param("uuid") else {
|
|
// No uuid
|
|
debug!("No uuid");
|
|
return Err(YggdrasilError::new_bad_request("One or more required fields was missing.").into())
|
|
};
|
|
|
|
let uuid = match uuid.find("-") {
|
|
None => Token::rehyphenate(uuid.to_string()),
|
|
Some(_) => uuid.to_string(),
|
|
};
|
|
|
|
let Some(profile) = Profile::from_uuid(req.state(), uuid).await else {
|
|
return Err(YggdrasilError::new_bad_request("Profile does not exist").into())
|
|
};
|
|
|
|
Ok(TexturedObject::from_profile(req.state(), &profile).await.into())
|
|
} |