-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement mastodon's /api/v1/custom_emojis
- Loading branch information
Showing
9 changed files
with
147 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use utoipa::ToSchema; | ||
|
||
#[derive(Clone, Deserialize, Serialize, ToSchema)] | ||
pub struct CustomEmoji { | ||
pub shortcode: String, | ||
pub url: String, | ||
pub static_url: String, | ||
pub visible_in_picker: bool, | ||
pub category: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::{error::Result, http::extractor::MastodonAuthExtractor, state::Zustand}; | ||
use axum::{debug_handler, extract::State, routing, Json, Router}; | ||
use futures_util::TryStreamExt; | ||
use kitsune_core::{ | ||
mapping::MastodonMapper, | ||
service::custom_emoji::{CustomEmojiService, GetEmojiList}, | ||
}; | ||
use kitsune_type::mastodon::CustomEmoji; | ||
|
||
#[debug_handler(state = crate::state::Zustand)] | ||
#[utoipa::path( | ||
get, | ||
path = "/api/v1/custom_emojis", | ||
security( | ||
("oauth_token" = []) | ||
), | ||
responses( | ||
(status = 200, description = "List of custom emojis available on the server", body = Vec<CustomEmoji>) | ||
), | ||
)] | ||
pub async fn get( | ||
State(custom_emoji_service): State<CustomEmojiService>, | ||
State(mastodon_mapper): State<MastodonMapper>, | ||
user_data: Option<MastodonAuthExtractor>, | ||
) -> Result<Json<Vec<CustomEmoji>>> { | ||
let get_emoji_list = GetEmojiList::builder() | ||
.fetching_account_id(user_data.map(|x| x.0.account.id)) | ||
.build(); | ||
|
||
let custom_emojis: Vec<CustomEmoji> = custom_emoji_service | ||
.get_list(get_emoji_list) | ||
.await? | ||
.and_then(|acc| mastodon_mapper.map(acc)) | ||
.try_collect() | ||
.await?; | ||
|
||
Ok(Json(custom_emojis)) | ||
} | ||
|
||
pub fn routes() -> Router<Zustand> { | ||
Router::new().route("/", routing::get(get)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters