formateo e limpeza
This commit is contained in:
parent
c3e9a0b1ee
commit
1f90332fc1
@ -7,7 +7,7 @@ use axum::{
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use crate::vistas::{root::basic, upload::upload, download::get_file};
|
||||
use crate::vistas::{download::get_file, root::basic, upload::upload};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
@ -16,7 +16,6 @@ async fn main() {
|
||||
|
||||
// build our application with a route
|
||||
let app = Router::new()
|
||||
// `GET /` goes to `root`
|
||||
.route("/", get(basic))
|
||||
.route("/u", post(upload))
|
||||
.route("/f/:hash", get(get_file));
|
||||
|
@ -3,14 +3,12 @@ use axum::{
|
||||
http::{header, StatusCode},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use tokio_util::io::ReaderStream;
|
||||
use tokio::fs::read_dir;
|
||||
use tokio_util::io::ReaderStream;
|
||||
|
||||
const BASE_PATH: &str = "uploads";
|
||||
|
||||
pub async fn get_file(
|
||||
axum::extract::Path(hash): axum::extract::Path<String>
|
||||
) -> impl IntoResponse {
|
||||
pub async fn get_file(axum::extract::Path(hash): axum::extract::Path<String>) -> impl IntoResponse {
|
||||
// hash.into_response()
|
||||
let (fpath, fname) = find_file(hash).await;
|
||||
|
||||
@ -35,6 +33,7 @@ pub async fn get_file(
|
||||
Ok((headers, body))
|
||||
}
|
||||
|
||||
// uploads/O/OfsdaDF/proba.txt
|
||||
async fn find_file(hash: String) -> (String, String) {
|
||||
let mut file_path = String::from("");
|
||||
let mut file_name = String::from("");
|
||||
|
@ -1,3 +1,3 @@
|
||||
pub mod download;
|
||||
pub mod root;
|
||||
pub mod upload;
|
||||
pub mod download;
|
||||
|
@ -1,14 +1,9 @@
|
||||
use crate::lib::randstr;
|
||||
use axum::{
|
||||
extract::Multipart,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use tokio::{
|
||||
fs::create_dir_all,
|
||||
fs::File,
|
||||
io::AsyncWriteExt,
|
||||
};
|
||||
use crate::lib::randstr;
|
||||
|
||||
use tokio::{fs::create_dir_all, fs::File, io::AsyncWriteExt};
|
||||
|
||||
const BASE_PATH: &str = "uploads";
|
||||
|
||||
@ -29,7 +24,9 @@ pub async fn upload(mut multipart: Multipart) -> Response {
|
||||
let path = format!("{}/{}/{}", BASE_PATH, pai, fillo);
|
||||
let dest = format!("{}/{}", path, filename);
|
||||
|
||||
create_dir_all(&path).await.expect("error creando directorios");
|
||||
create_dir_all(&path)
|
||||
.await
|
||||
.expect("error creando directorios");
|
||||
let mut file = File::create(dest).await.expect("error creando arquivo");
|
||||
file.write_all(&data).await.expect("error gardando contido");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user