use lexical_sort for ordering
This commit is contained in:
parent
ad4975bd88
commit
8f0060568c
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -308,6 +308,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "any_ascii"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70033777eb8b5124a81a1889416543dddef2de240019b674c81285a2635a7e1e"
|
||||
|
||||
[[package]]
|
||||
name = "argon2"
|
||||
version = "0.4.1"
|
||||
@ -1006,6 +1012,7 @@ dependencies = [
|
||||
"ffplayout-lib",
|
||||
"futures-util",
|
||||
"jsonwebtoken",
|
||||
"lexical-sort",
|
||||
"once_cell",
|
||||
"rand",
|
||||
"regex",
|
||||
@ -1729,6 +1736,15 @@ dependencies = [
|
||||
"socket2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lexical-sort"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c09e4591611e231daf4d4c685a66cb0410cc1e502027a20ae55f2bb9e997207a"
|
||||
dependencies = [
|
||||
"any_ascii",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.137"
|
||||
|
@ -21,6 +21,7 @@ derive_more = "0.99"
|
||||
faccess = "0.2"
|
||||
futures-util = { version = "0.3", default-features = false, features = ["std"] }
|
||||
jsonwebtoken = "8"
|
||||
lexical-sort = "0.3"
|
||||
once_cell = "1.10"
|
||||
rand = "0.8"
|
||||
regex = "1"
|
||||
|
@ -3,6 +3,7 @@ use std::{fs, io::Write, path::PathBuf};
|
||||
use actix_multipart::Multipart;
|
||||
use actix_web::{web, HttpResponse};
|
||||
use futures_util::TryStreamExt as _;
|
||||
use lexical_sort::{natural_lexical_cmp, PathSort};
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use relative_path::RelativePath;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -98,31 +99,28 @@ pub async fn browser(
|
||||
let (path, parent, path_component) = norm_abs_path(&config.storage.path, &path_obj.source);
|
||||
let mut obj = PathObject::new(path_component, Some(parent));
|
||||
|
||||
let mut paths: Vec<_> = match fs::read_dir(path) {
|
||||
Ok(p) => p.filter_map(|r| r.ok()).collect(),
|
||||
let mut paths: Vec<PathBuf> = match fs::read_dir(path) {
|
||||
Ok(p) => p.filter_map(|r| r.ok()).map(|p| p.path()).collect(),
|
||||
Err(e) => {
|
||||
error!("{e} in {}", path_obj.source);
|
||||
return Err(ServiceError::NoContent(e.to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
paths.sort_by_key(|dir| dir.path().display().to_string().to_lowercase());
|
||||
paths.path_sort(natural_lexical_cmp);
|
||||
let mut files = vec![];
|
||||
let mut folders = vec![];
|
||||
|
||||
for path in paths {
|
||||
let file_path = path.path().to_owned();
|
||||
let path = file_path.clone();
|
||||
|
||||
// ignore hidden files/folders on unix
|
||||
if path.display().to_string().contains("/.") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if file_path.is_dir() {
|
||||
if path.is_dir() {
|
||||
folders.push(path.file_name().unwrap().to_string_lossy().to_string());
|
||||
} else if file_path.is_file() {
|
||||
if let Some(ext) = file_extension(&file_path) {
|
||||
} else if path.is_file() {
|
||||
if let Some(ext) = file_extension(&path) {
|
||||
if extensions.contains(&ext.to_string().to_lowercase()) {
|
||||
let media = MediaProbe::new(&path.display().to_string());
|
||||
let mut duration = 0.0;
|
||||
|
Loading…
Reference in New Issue
Block a user