Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
lektor
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
d969fbe6
Vérifiée
Valider
d969fbe6
rédigé
Il y a 1 an
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
LEKTORD: Set the content type when we return hand-crafter json things
parent
aeb27082
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!197
Draft: Refactor the whole code.
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
lektord/src/app/routes.rs
+22
-14
22 ajouts, 14 suppressions
lektord/src/app/routes.rs
avec
22 ajouts
et
14 suppressions
lektord/src/app/routes.rs
+
22
−
14
Voir le fichier @
d969fbe6
...
...
@@ -9,9 +9,11 @@ use crate::*;
use
anyhow
::{
anyhow
,
Error
};
use
axum
::{
extract
::{
Path
,
State
},
http
::
StatusCode
,
http
::{
HeaderValue
,
StatusCode
},
response
::{
IntoResponse
,
Response
},
Json
,
};
use
hyper
::
header
::
CONTENT_TYPE
;
use
lektor_nkdb
::
*
;
use
lektor_payloads
::
*
;
use
lektor_utils
::{
decode_base64_json
,
log
};
...
...
@@ -105,11 +107,13 @@ pub(crate) async fn toggle_play_state() -> Result<(), LektordError> {
pub
(
crate
)
async
fn
get_kara_by_id
(
State
(
state
):
State
<
LektorStatePtr
>
,
Path
(
id
):
Path
<
u64
>
,
)
->
Result
<
String
,
LektordError
>
{
Ok
(
serde_json
::
to_string
(
state
.database
.get_kara_by_id
(
id
)
.await
?
)
.map_err
(|
err
|
anyhow!
(
"{err}"
))
?
,
)
)
->
Result
<
Response
,
LektordError
>
{
let
mut
kara
=
serde_json
::
to_string
(
state
.database
.get_kara_by_id
(
id
)
.await
?
)
.map_err
(|
err
|
anyhow!
(
"{err}"
))
?
.into_response
();
kara
.headers_mut
()
.insert
(
CONTENT_TYPE
,
HeaderValue
::
from_static
(
"application/json"
));
Ok
(
kara
)
}
/// Get all the informations about a kara by its id. Returns the kara as a json object to avoid
...
...
@@ -118,14 +122,18 @@ pub(crate) async fn get_kara_by_id(
pub
(
crate
)
async
fn
get_kara_by_kid
(
State
(
state
):
State
<
LektorStatePtr
>
,
Path
(
id
):
Path
<
String
>
,
)
->
Result
<
String
,
LektordError
>
{
match
state
.database
.get_kid_from_str
(
&
decode_base64
(
&
id
)
?
)
.await
{
Some
(
id
)
=>
Ok
(
serde_json
::
to_string
(
state
.database
.get_kara_by_kid
(
id
)
.await
?
)
.map_err
(|
err
|
anyhow!
(
"{err}"
))
?
,
),
None
=>
Err
(
anyhow!
(
"no kara found with id {id}"
)
.into
()),
}
)
->
Result
<
Response
,
LektordError
>
{
let
id
=
state
.database
.get_kid_from_str
(
&
decode_base64
(
&
id
)
?
)
.await
.ok_or_else
(||
anyhow!
(
"no kara found with id {id}"
))
?
;
let
mut
kara
=
serde_json
::
to_string
(
state
.database
.get_kara_by_kid
(
id
)
.await
?
)
.map_err
(|
err
|
anyhow!
(
"{err}"
))
?
.into_response
();
kara
.headers_mut
()
.insert
(
CONTENT_TYPE
,
HeaderValue
::
from_static
(
"application/json"
));
Ok
(
kara
)
}
/// Search some karas from a search set with a regex. We take the json argument as base64 encoded
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter