ебать мой хуй
This commit is contained in:
parent
e3ed43148a
commit
cbaea15f4f
6 changed files with 39 additions and 12 deletions
|
|
@ -19,6 +19,24 @@ pub mod start {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[data(copy)]
|
||||||
|
pub enum ImageType {
|
||||||
|
#[serde(alias = "image/png")]
|
||||||
|
Png,
|
||||||
|
#[serde(alias = "image/jpeg")]
|
||||||
|
Jpg,
|
||||||
|
#[serde(alias = "image/webp")]
|
||||||
|
Webp,
|
||||||
|
#[serde(alias = "image/bmp")]
|
||||||
|
Bmp,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[data]
|
||||||
|
pub enum FileClass {
|
||||||
|
Image(ImageType),
|
||||||
|
GameFile,
|
||||||
|
}
|
||||||
|
|
||||||
#[data]
|
#[data]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
/// Name of the file. Mainly serves as a hint to user to not
|
/// Name of the file. Mainly serves as a hint to user to not
|
||||||
|
|
@ -30,7 +48,7 @@ pub mod start {
|
||||||
pub hash: Option<file::Hash>,
|
pub hash: Option<file::Hash>,
|
||||||
|
|
||||||
/// Class of the file.
|
/// Class of the file.
|
||||||
pub class: file::ClassKind,
|
pub class: FileClass,
|
||||||
|
|
||||||
/// Size of the file to upload. Must be known
|
/// Size of the file to upload. Must be known
|
||||||
/// prior to upload, streaming is not supported.
|
/// prior to upload, streaming is not supported.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,12 @@ use eva::data;
|
||||||
|
|
||||||
use crate::requests::status_code;
|
use crate::requests::status_code;
|
||||||
|
|
||||||
use viendesu_core::{errors, requests::uploads as reqs, types::{file, upload}, uploads::UploadStream};
|
use viendesu_core::{
|
||||||
|
errors,
|
||||||
|
requests::uploads as reqs,
|
||||||
|
types::{file, upload},
|
||||||
|
uploads::UploadStream,
|
||||||
|
};
|
||||||
|
|
||||||
#[data]
|
#[data]
|
||||||
pub struct ListPending {}
|
pub struct ListPending {}
|
||||||
|
|
@ -17,7 +22,7 @@ status_code::map!(reqs::list_pending::Err => []);
|
||||||
pub struct Start {
|
pub struct Start {
|
||||||
pub file_name: Option<file::BaseName>,
|
pub file_name: Option<file::BaseName>,
|
||||||
pub hash: Option<file::Hash>,
|
pub hash: Option<file::Hash>,
|
||||||
pub class: file::ClassKind,
|
pub class: reqs::start::FileClass,
|
||||||
pub size: NonZeroU64,
|
pub size: NonZeroU64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,15 @@ use axum::{
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use viendesu_core::errors::{Aux, AuxResult};
|
use viendesu_core::{
|
||||||
|
errors::{Aux, AuxResult},
|
||||||
|
types::session,
|
||||||
|
};
|
||||||
|
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct Context<R: ServerRequest> {
|
pub struct Context<R: ServerRequest> {
|
||||||
pub request: R,
|
pub request: R,
|
||||||
|
pub token: Option<session::Token>,
|
||||||
pub parts: Option<Parts>,
|
pub parts: Option<Parts>,
|
||||||
pub response_format: Format,
|
pub response_format: Format,
|
||||||
}
|
}
|
||||||
|
|
@ -82,6 +86,7 @@ where
|
||||||
|
|
||||||
Ok(Context {
|
Ok(Context {
|
||||||
request,
|
request,
|
||||||
|
token: extract::session_token(&parts).map_err(|e| response::err(response_format, e))?,
|
||||||
parts: Some(parts),
|
parts: Some(parts),
|
||||||
response_format,
|
response_format,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -125,12 +125,7 @@ impl<R: ServerRequest, M, T: Types, Cx: MakeContext<R>> FinishedHandler<R, M, T,
|
||||||
.await
|
.await
|
||||||
.map_err(|e| response::err(resp_format, e))?;
|
.map_err(|e| response::err(resp_format, e))?;
|
||||||
|
|
||||||
if let Some(token) = context
|
if let Some(token) = context.token {
|
||||||
.parts
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|p| extract::session_token(p).transpose())
|
|
||||||
{
|
|
||||||
let token = token.map_err(|e| response::err(resp_format, e))?;
|
|
||||||
session
|
session
|
||||||
.authz()
|
.authz()
|
||||||
.authenticate(token)
|
.authenticate(token)
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ pub fn make_router<T: Types>(service: T::Service) -> axum::Router {
|
||||||
routes::make(scope)
|
routes::make(scope)
|
||||||
.into_axum()
|
.into_axum()
|
||||||
.layer(fastrace_axum::FastraceLayer)
|
.layer(fastrace_axum::FastraceLayer)
|
||||||
.layer(cors::CorsLayer::permissive())
|
.layer(cors::CorsLayer::very_permissive())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[perfect_derive(Clone)]
|
#[perfect_derive(Clone)]
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,12 @@ async fn load_upload_context(request: AxumRequest) -> Result<Ctx<Finish>, AxumRe
|
||||||
}
|
}
|
||||||
|
|
||||||
let (mut parts, body) = request.into_parts();
|
let (mut parts, body) = request.into_parts();
|
||||||
let id: upload::Id = extract::path(&mut parts).await?;
|
|
||||||
let response_format =
|
let response_format =
|
||||||
extract::response_format(&parts).map_err(|e| response::err(Default::default(), e))?;
|
extract::response_format(&parts).map_err(|e| response::err(Default::default(), e))?;
|
||||||
|
let token = extract::session_token(&parts).map_err(|e| response::err(response_format, e))?;
|
||||||
|
let id: upload::Id = extract::path(&mut parts)
|
||||||
|
.await
|
||||||
|
.map_err(|e| response::err(response_format, e))?;
|
||||||
|
|
||||||
// This fucking sucks to the extent I can't express with words, the way its done
|
// This fucking sucks to the extent I can't express with words, the way its done
|
||||||
// is horrible, the reason behind this is even more, I wish authors of axum very pleasant
|
// is horrible, the reason behind this is even more, I wish authors of axum very pleasant
|
||||||
|
|
@ -95,6 +98,7 @@ async fn load_upload_context(request: AxumRequest) -> Result<Ctx<Finish>, AxumRe
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(Ctx {
|
Ok(Ctx {
|
||||||
|
token,
|
||||||
request: Finish {
|
request: Finish {
|
||||||
id,
|
id,
|
||||||
stream: UploadStream::unknown_size(Box::pin(stream)),
|
stream: UploadStream::unknown_size(Box::pin(stream)),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue