aboutsummaryrefslogtreecommitdiff
path: root/server/src/api.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-05-13 14:57:19 +0200
committermetamuffin <metamuffin@disroot.org>2025-05-13 14:57:19 +0200
commit09f86ee5b25fbddf667ef98a22eaa076cedba23c (patch)
tree2abca01286840cb918acbbdc3735f414fd26595e /server/src/api.rs
parent55434f87ff252c784e5e00b4775b9555da31ebb0 (diff)
downloadjellything-09f86ee5b25fbddf667ef98a22eaa076cedba23c.tar
jellything-09f86ee5b25fbddf667ef98a22eaa076cedba23c.tar.bz2
jellything-09f86ee5b25fbddf667ef98a22eaa076cedba23c.tar.zst
move AcceptJson and AcceptLanguage guard in preperation to remove them
Diffstat (limited to 'server/src/api.rs')
-rw-r--r--server/src/api.rs50
1 files changed, 3 insertions, 47 deletions
diff --git a/server/src/api.rs b/server/src/api.rs
index 6c22010..38bab08 100644
--- a/server/src/api.rs
+++ b/server/src/api.rs
@@ -4,7 +4,7 @@
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
use super::ui::error::MyResult;
-use crate::{helper::A, locale::AcceptLanguage};
+use crate::helper::{accept::AcceptJson, language::AcceptLanguage, A};
use jellycommon::{user::CreateSessionParams, NodeID, Visibility};
use jellyimport::asset_token::AssetInner;
use jellylogic::{
@@ -13,18 +13,9 @@ use jellylogic::{
Database,
};
use jellyui::locale::get_translation_table;
-use rocket::{
- get,
- http::MediaType,
- outcome::Outcome,
- post,
- request::{self, FromRequest},
- response::Redirect,
- serde::json::Json,
- Either, Request, State,
-};
+use rocket::{get, post, response::Redirect, serde::json::Json, Either, State};
use serde_json::{json, Value};
-use std::{collections::HashMap, ops::Deref};
+use std::collections::HashMap;
#[get("/api")]
pub fn r_api_root() -> Redirect {
@@ -92,38 +83,3 @@ pub fn r_nodes_modified_since(
});
Ok(Json(nodes))
}
-
-pub struct AcceptJson(bool);
-impl Deref for AcceptJson {
- type Target = bool;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-impl<'r> FromRequest<'r> for AcceptJson {
- type Error = ();
-
- fn from_request<'life0, 'async_trait>(
- request: &'r Request<'life0>,
- ) -> ::core::pin::Pin<
- Box<
- dyn ::core::future::Future<Output = request::Outcome<Self, Self::Error>>
- + ::core::marker::Send
- + 'async_trait,
- >,
- >
- where
- 'r: 'async_trait,
- 'life0: 'async_trait,
- Self: 'async_trait,
- {
- Box::pin(async move {
- Outcome::Success(AcceptJson(
- request
- .accept()
- .map(|a| a.preferred().exact_eq(&MediaType::JSON))
- .unwrap_or(false),
- ))
- })
- }
-}