Added a post function

This commit is contained in:
2021-06-12 14:03:59 +05:30
parent 1239446d33
commit b2b9077060
4 changed files with 411 additions and 14 deletions

View File

@@ -1,15 +1,11 @@
mod post;
use actix_files::NamedFile;
use actix_web::{web, App, HttpRequest, HttpServer};
use std::{env, io, path::PathBuf};
use std::{io, path::PathBuf};
const ROOT_DIR: &str = "/files/";
fn get_token() -> String {
env::var("FILEHOST_TOKEN").expect("FILEHOST_TOKEN is not set")
}
async fn get_file(req: HttpRequest) -> Result<NamedFile, io::Error> {
async fn get_file(req: HttpRequest) -> Result<NamedFile,io::Error> {
let file_name = req.match_info().get("file").unwrap_or("default");
let file_path: PathBuf = format!("{}{}", ROOT_DIR, file_name).parse().unwrap();
match NamedFile::open(file_path) {
@@ -28,7 +24,7 @@ async fn main() -> io::Result<()> {
.route("/{file}", web::get().to(get_file))
.route("/", web::post().to(post::post))
})
.bind(("127.0.0.1", 8888))?
.bind(("0.0.0.0", 8888))?
.run()
.await
}