Move list_photos to files module
All checks were successful
Core Repos/ImageApi/pipeline/pr-master This commit looks good
All checks were successful
Core Repos/ImageApi/pipeline/pr-master This commit looks good
Added some tests, refactored the error handling/logging, and refactored the extension tests.
This commit is contained in:
37
src/main.rs
37
src/main.rs
@@ -22,7 +22,7 @@ use actix_web::{
|
||||
delete,
|
||||
error::BlockingError,
|
||||
get, middleware, post, put,
|
||||
web::{self, BufMut, BytesMut, HttpRequest, HttpResponse, Query},
|
||||
web::{self, BufMut, BytesMut, HttpRequest, HttpResponse},
|
||||
App, HttpServer, Responder,
|
||||
};
|
||||
use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
|
||||
@@ -33,7 +33,7 @@ use log::{debug, error, info};
|
||||
use crate::auth::login;
|
||||
use crate::data::*;
|
||||
use crate::database::*;
|
||||
use crate::files::{is_image_or_video, is_valid_path, list_files};
|
||||
use crate::files::{is_image_or_video, is_valid_path};
|
||||
use crate::video::*;
|
||||
|
||||
mod auth;
|
||||
@@ -58,33 +58,6 @@ lazy_static! {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[get("/photos")]
|
||||
async fn list_photos(_claims: Claims, req: Query<ThumbnailRequest>) -> impl Responder {
|
||||
info!("{}", req.path);
|
||||
|
||||
let path = &req.path;
|
||||
if let Some(path) = is_valid_path(path) {
|
||||
let files = list_files(&path).unwrap_or_default();
|
||||
|
||||
let photos = &files
|
||||
.iter()
|
||||
.filter(|&f| f.metadata().map_or(false, |md| md.is_file()))
|
||||
.map(|f| f.to_str().unwrap().to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
let dirs = &files
|
||||
.iter()
|
||||
.filter(|&f| f.metadata().map_or(false, |md| md.is_dir()))
|
||||
.map(|f| f.to_str().unwrap().to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
HttpResponse::Ok().json(PhotosResponse { photos, dirs })
|
||||
} else {
|
||||
error!("Bad photos request: {}", req.path);
|
||||
HttpResponse::BadRequest().finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/image")]
|
||||
async fn get_image(
|
||||
_claims: Claims,
|
||||
@@ -258,8 +231,8 @@ async fn favorites(
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
HttpResponse::Ok().json(PhotosResponse {
|
||||
photos: &favorites,
|
||||
dirs: &Vec::new(),
|
||||
photos: favorites,
|
||||
dirs: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -491,7 +464,7 @@ fn main() -> std::io::Result<()> {
|
||||
App::new()
|
||||
.wrap(middleware::Logger::default())
|
||||
.service(web::resource("/login").route(web::post().to(login)))
|
||||
.service(list_photos)
|
||||
.service(web::resource("/photos").route(web::get().to(files::list_photos)))
|
||||
.service(get_image)
|
||||
.service(upload_image)
|
||||
.service(generate_video)
|
||||
|
||||
Reference in New Issue
Block a user