mirror of
https://github.com/YGGverse/titanit.git
synced 2026-04-01 01:25:31 +00:00
dump meta on file commit
This commit is contained in:
parent
7bf68725db
commit
a1ccc27cb8
2 changed files with 56 additions and 7 deletions
34
src/main.rs
34
src/main.rs
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue