use actix_web::web::{HttpResponse, Json}; use actix_web::{get, post, App, HttpServer, Responder}; use data::{LoginRequest, ThumbnailRequest}; use std::path::PathBuf; use crate::files::list_files; mod data; mod files; #[post("/register")] async fn register() -> impl Responder { "".to_owned() } #[post("/login")] async fn login(_creds: Json) -> impl Responder { "".to_owned() } #[get("/photos")] async fn list_photos(req: Json) -> impl Responder { println!("{}", req.path); let path = &req.path; match path { path if path.contains("..") => HttpResponse::BadRequest().finish(), path => { let path = PathBuf::from(path); if path.is_relative() { let mut full_path = std::env::current_dir().unwrap(); full_path.push(path); let files = list_files(full_path); HttpResponse::Ok().json(files.unwrap_or_default()) } else { HttpResponse::BadRequest().finish() } } } } #[actix_rt::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| App::new().service(login).service(list_photos)) .bind("127.0.0.1:8088")? .run() .await }