Removed partial/play feature
This commit is contained in:
parent
605b29ddfb
commit
3cce8e8aa8
106
src/main.rs
106
src/main.rs
@ -276,7 +276,7 @@ fn handle_connection(
|
||||
let mut pk_path = path.clone();
|
||||
let mut data_path = path.clone();
|
||||
|
||||
let (pki_path, audio_path, start_level, relative_path, partial) = if relative_path.is_empty() {
|
||||
let (pki_path, audio_path, start_level, relative_path) = if relative_path.is_empty() {
|
||||
if access == Access::Full {
|
||||
pk_path.push("index.pk");
|
||||
data_path.push("index.dat");
|
||||
@ -285,7 +285,7 @@ fn handle_connection(
|
||||
data_path.push("partial.dat");
|
||||
}
|
||||
|
||||
(None, None, 0, String::new(), None)
|
||||
(None, None, 0, String::new())
|
||||
} else {
|
||||
let mut pki_path = path.clone();
|
||||
let mut audio_path = path.clone();
|
||||
@ -298,12 +298,6 @@ fn handle_connection(
|
||||
return;
|
||||
}
|
||||
|
||||
let (path, num) = if let Some((path, num)) = path.rsplit_once('=') {
|
||||
(path, num.parse::<usize>().ok())
|
||||
} else {
|
||||
(path.as_ref(), None)
|
||||
};
|
||||
|
||||
pk_path.push(format!("{path}.pk"));
|
||||
if access == Access::Full {
|
||||
pki_path.push(format!("{path}.pki"));
|
||||
@ -313,7 +307,7 @@ fn handle_connection(
|
||||
audio_path.push(format!("{path}.mp3"));
|
||||
data_path.push(format!("{path}.dat"));
|
||||
|
||||
(Some(pki_path), Some(audio_path), 1, path.to_string(), num)
|
||||
(Some(pki_path), Some(audio_path), 1, path.to_string())
|
||||
};
|
||||
|
||||
let file_paths = DocumentPaths {
|
||||
@ -373,7 +367,6 @@ fn handle_connection(
|
||||
&relative_path,
|
||||
&path,
|
||||
file_paths,
|
||||
partial,
|
||||
start_level,
|
||||
cookie,
|
||||
access != Access::Full,
|
||||
@ -422,7 +415,6 @@ fn handle_relative_connection(
|
||||
relative_path: &str,
|
||||
path: &Path,
|
||||
file_paths: DocumentPaths,
|
||||
partial: Option<usize>,
|
||||
start_level: usize,
|
||||
cookie: Option<&str>,
|
||||
censored: bool,
|
||||
@ -572,89 +564,17 @@ fn handle_relative_connection(
|
||||
|
||||
let lines = BufReader::new(pk_file).lines();
|
||||
|
||||
if let Some(i) = partial {
|
||||
let mut last_empty = true;
|
||||
let mut block = 0;
|
||||
let lines: Vec<_> = lines.map(Result::unwrap_or_default).collect();
|
||||
let mut lines = lines.into_iter();
|
||||
if i > 0 {
|
||||
for line in lines.by_ref() {
|
||||
let empty = line.trim().is_empty();
|
||||
if empty == last_empty {
|
||||
continue;
|
||||
}
|
||||
if empty {
|
||||
block += 1;
|
||||
if block == i {
|
||||
break;
|
||||
}
|
||||
}
|
||||
last_empty = empty;
|
||||
}
|
||||
}
|
||||
|
||||
for line in lines.clone() {
|
||||
let empty = line.trim().is_empty();
|
||||
if empty == last_empty {
|
||||
continue;
|
||||
}
|
||||
if empty {
|
||||
block += 1;
|
||||
}
|
||||
last_empty = empty;
|
||||
}
|
||||
|
||||
let _ = writeln!(stream, "<h1>{title} ({}/{})</h1>", i + 1, block);
|
||||
|
||||
let _ = writeln!(
|
||||
stream,
|
||||
"<a href=\"/{relative_path}\">< Stop ></a><br><br>"
|
||||
);
|
||||
if i > 0 {
|
||||
let prev = i - 1;
|
||||
let _ = writeln!(stream, "<a href=\"/{relative_path}={prev}\">< Prev</a>");
|
||||
} else {
|
||||
let _ = writeln!(stream, "<font color=\"gray\">< Prev</font>");
|
||||
}
|
||||
|
||||
if i + 1 < block {
|
||||
let next = i + 1;
|
||||
let _ = writeln!(stream, "<a href=\"/{relative_path}={next}\">Next ></a>");
|
||||
} else {
|
||||
let _ = writeln!(stream, "<font color=\"gray\">Next ></font>");
|
||||
}
|
||||
|
||||
let _ = writeln!(stream, "<br>");
|
||||
|
||||
let mut has_text = false;
|
||||
convert_extended(
|
||||
lines.take_while(|line| {
|
||||
let empty = line.trim().is_empty();
|
||||
if !empty {
|
||||
has_text = true;
|
||||
}
|
||||
!empty || !has_text
|
||||
}),
|
||||
&mut stream,
|
||||
Settings::default()
|
||||
.with_handler(handle_entry)
|
||||
.with_start_level(start_level)
|
||||
.with_use_textboxes(true),
|
||||
);
|
||||
} else {
|
||||
if !title.is_empty() {
|
||||
let _ = writeln!(stream, "<h1>{title}</h1>");
|
||||
}
|
||||
let _ = writeln!(stream, "<a href=\"/{relative_path}=0\">< Play ></a>");
|
||||
convert_extended(
|
||||
lines.map(Result::unwrap_or_default),
|
||||
&mut stream,
|
||||
Settings::default()
|
||||
.with_handler(handle_entry)
|
||||
.with_start_level(start_level)
|
||||
.with_use_textboxes(true),
|
||||
);
|
||||
if !title.is_empty() {
|
||||
let _ = writeln!(stream, "<h1>{title}</h1>");
|
||||
}
|
||||
convert_extended(
|
||||
lines.map(Result::unwrap_or_default),
|
||||
&mut stream,
|
||||
Settings::default()
|
||||
.with_handler(handle_entry)
|
||||
.with_start_level(start_level)
|
||||
.with_use_textboxes(true),
|
||||
);
|
||||
|
||||
section(&mut stream);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user