mirror of
https://github.com/Noratrieb/upload.files.noratrieb.dev.git
synced 2026-01-14 17:55:02 +01:00
require auth on the index page
this ensures that the user is authenticated for the upload, eliminating the dumb body consumption problems
This commit is contained in:
parent
90f6a6a82f
commit
9068887037
1 changed files with 14 additions and 5 deletions
19
src/main.rs
19
src/main.rs
|
|
@ -1,14 +1,14 @@
|
||||||
use axum::{
|
use axum::{
|
||||||
Router,
|
|
||||||
body::Bytes,
|
body::Bytes,
|
||||||
extract::{DefaultBodyLimit, FromRequestParts, Multipart, State},
|
extract::{DefaultBodyLimit, FromRequestParts, Multipart, State},
|
||||||
http::{StatusCode, header},
|
http::{header, StatusCode},
|
||||||
response::{Html, IntoResponse, Redirect, Response},
|
response::{Html, IntoResponse, Redirect, Response},
|
||||||
routing::{get, post},
|
routing::{get, post},
|
||||||
|
Router,
|
||||||
};
|
};
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use color_eyre::eyre::{self, Context, bail};
|
use color_eyre::eyre::{self, bail, Context};
|
||||||
use color_eyre::{Result, eyre::OptionExt};
|
use color_eyre::{eyre::OptionExt, Result};
|
||||||
use object_store::ObjectStore;
|
use object_store::ObjectStore;
|
||||||
use rand_core::TryRngCore;
|
use rand_core::TryRngCore;
|
||||||
use tracing::{error, info, level_filters::LevelFilter};
|
use tracing::{error, info, level_filters::LevelFilter};
|
||||||
|
|
@ -49,7 +49,7 @@ async fn main() -> Result<()> {
|
||||||
.wrap_err("failed to build client")?;
|
.wrap_err("failed to build client")?;
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(|| async { Html(include_str!("../index.html")) }))
|
.route("/", get(index))
|
||||||
.route("/", post(upload))
|
.route("/", post(upload))
|
||||||
.with_state(Config {
|
.with_state(Config {
|
||||||
username,
|
username,
|
||||||
|
|
@ -68,6 +68,11 @@ async fn main() -> Result<()> {
|
||||||
axum::serve(listener, app).await.wrap_err("failed to serve")
|
axum::serve(listener, app).await.wrap_err("failed to serve")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: use middleware
|
||||||
|
async fn index(_: Auth) -> impl IntoResponse {
|
||||||
|
Html(include_str!("../index.html"))
|
||||||
|
}
|
||||||
|
|
||||||
async fn upload(
|
async fn upload(
|
||||||
auth: Auth,
|
auth: Auth,
|
||||||
State(config): State<Config>,
|
State(config): State<Config>,
|
||||||
|
|
@ -186,6 +191,10 @@ async fn parse_req(mut multipart: Multipart) -> Result<UploadRequest> {
|
||||||
name = format!("{random}/{name}");
|
name = format!("{random}/{name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name.is_empty() {
|
||||||
|
bail!("name must not be empty");
|
||||||
|
}
|
||||||
|
|
||||||
name = format!("/{name}");
|
name = format!("/{name}");
|
||||||
|
|
||||||
Ok(UploadRequest {
|
Ok(UploadRequest {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue