dump meta on file commit

This commit is contained in:
yggverse 2025-02-22 09:13:00 +02:00
parent 7bf68725db
commit a1ccc27cb8
2 changed files with 56 additions and 7 deletions

View file

@ -97,7 +97,7 @@ fn gemini(
match storage::Item::from_url(gemini.url.as_str(), &argument.directory) {
Ok(item) => send(
&response::success::Default {
mime: "text/gemini".to_string(),
mime: item.mime,
//data: item.file.read(vec![1000]),
}
.into_bytes(),
@ -128,8 +128,29 @@ fn titan(
stream: &mut TlsStream<TcpStream>,
) {
use titanite::*;
// require content type for application,
// even MIME value is optional by Titan specification
let mime = match titan.mime {
Some(mime) => mime,
None => {
const MESSAGE: &str = "Content type is required";
return send(
&response::failure::permanent::BadRequest {
message: Some(MESSAGE.to_string()),
}
.into_bytes(),
stream,
|result| match result {
Ok(()) => println!("[{}] [warning] [{peer}] {MESSAGE}", now()),
Err(e) => println!("[{}] [error] [{peer}] {e}", now()),
},
);
}
};
// validate total bytes
let mut total = 0;
match storage::Item::create(&argument.directory) {
// create new destination file
match storage::Item::create(&argument.directory, mime) {
Ok(mut tmp) => loop {
let mut input = vec![0; argument.chunk];
match stream.read(&mut input) {
@ -205,10 +226,13 @@ fn titan(
);
}
// just to make sure
if titan.size > total {
panic!()
}
// all data received
if titan.size >= total {
// @TODO detect/validate/cache mime based on data received
// success
if titan.size == total {
return match tmp.commit() {
Ok(pmt) => send(
&response::redirect::Permanent {