Implemented to_stream for site info instead of shared site info
This commit is contained in:
parent
7722a5ee95
commit
9016a32b59
33
src/main.rs
33
src/main.rs
@ -178,13 +178,10 @@ fn fail(mut stream: TcpStream) {
|
||||
let _ = writeln!(stream, "Page not found!");
|
||||
}
|
||||
|
||||
impl<S: SizeSettings> ToStream<S> for SharedSiteInfo {
|
||||
impl<S: SizeSettings> ToStream<S> for SiteInfo {
|
||||
fn to_stream<W: Write>(&self, stream: &mut W) -> Result<()> {
|
||||
let Ok(comments) = self.comments.lock() else {
|
||||
return Err(std::io::ErrorKind::ResourceBusy.into());
|
||||
};
|
||||
S::size_to_stream(comments.len(), stream)?;
|
||||
for Comment { name, text } in comments.iter() {
|
||||
S::size_to_stream(self.comments.len(), stream)?;
|
||||
for Comment { name, text } in &self.comments {
|
||||
let name_bytes = name.as_bytes();
|
||||
S::size_to_stream(name_bytes.len(), stream)?;
|
||||
stream.write_all(name_bytes)?;
|
||||
@ -194,9 +191,9 @@ impl<S: SizeSettings> ToStream<S> for SharedSiteInfo {
|
||||
stream.write_all(text_bytes)?;
|
||||
}
|
||||
|
||||
S::size_to_stream(self.visits.load(Ordering::Acquire), stream)?;
|
||||
S::size_to_stream(self.up.load(Ordering::Acquire), stream)?;
|
||||
S::size_to_stream(self.down.load(Ordering::Acquire), stream)?;
|
||||
S::size_to_stream(self.visits, stream)?;
|
||||
S::size_to_stream(self.up, stream)?;
|
||||
S::size_to_stream(self.down, stream)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -597,19 +594,21 @@ fn handle_relative_connection(
|
||||
progress,
|
||||
} = RequestData::parse(body);
|
||||
|
||||
let info = info.update(name, text, up, down);
|
||||
|
||||
if let Ok(mut file) = File::create(file_paths.data) {
|
||||
if to_stream::<PortableSettings, _, _>(&info, &mut file).is_err() {
|
||||
eprintln!("Error saving data!");
|
||||
eprintln!();
|
||||
}
|
||||
}
|
||||
|
||||
let SiteInfo {
|
||||
comments,
|
||||
visits,
|
||||
up,
|
||||
down,
|
||||
} = info.update(name, text, up, down);
|
||||
|
||||
if let Ok(mut file) = File::create(file_paths.data) {
|
||||
if to_stream::<PortableSettings, _, _>(&*info, &mut file).is_err() {
|
||||
eprintln!("Error saving data!");
|
||||
eprintln!();
|
||||
}
|
||||
}
|
||||
} = info;
|
||||
|
||||
let _ = write!(stream, "HTTP/1.1 200 OK\r\n");
|
||||
let _ = write!(stream, "Content-Type: text/html; charset=\"utf-8\"\r\n");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user