mirror of
https://github.com/YGGverse/titanit.git
synced 2026-03-31 17:15:30 +00:00
update titanite api
This commit is contained in:
parent
e023545148
commit
572bd77a3c
1 changed files with 9 additions and 13 deletions
22
src/main.rs
22
src/main.rs
|
|
@ -127,14 +127,10 @@ fn gemini(
|
||||||
match storage::Item::from_url(gemini.url.as_str(), &argument.directory) {
|
match storage::Item::from_url(gemini.url.as_str(), &argument.directory) {
|
||||||
Ok(item) => {
|
Ok(item) => {
|
||||||
let mut read: usize = 0;
|
let mut read: usize = 0;
|
||||||
// send header
|
// create header packet
|
||||||
match stream.write_all(
|
match stream
|
||||||
&response::success::Default {
|
.write_all(&response::success::default::Meta { mime: item.mime }.into_bytes())
|
||||||
mime: item.mime,
|
{
|
||||||
data: &[], // init empty
|
|
||||||
}
|
|
||||||
.into_bytes(),
|
|
||||||
) {
|
|
||||||
// chunk begin
|
// chunk begin
|
||||||
Ok(()) => loop {
|
Ok(()) => loop {
|
||||||
let mut data = vec![0; argument.chunk];
|
let mut data = vec![0; argument.chunk];
|
||||||
|
|
@ -184,10 +180,10 @@ fn titan(
|
||||||
stream: &mut TlsStream<TcpStream>,
|
stream: &mut TlsStream<TcpStream>,
|
||||||
) {
|
) {
|
||||||
use titanite::*;
|
use titanite::*;
|
||||||
println!("[{}] [info] [{peer}] Request: {}", now(), titan.url);
|
println!("[{}] [info] [{peer}] Request: {}", now(), titan.meta.url);
|
||||||
// require content type for application,
|
// require content type for application,
|
||||||
// even MIME value is optional by Titan specification
|
// even MIME value is optional by Titan specification
|
||||||
let mime = match titan.mime {
|
let mime = match titan.meta.mime {
|
||||||
Some(mime) => mime,
|
Some(mime) => mime,
|
||||||
None => {
|
None => {
|
||||||
const MESSAGE: &str = "Content type is required";
|
const MESSAGE: &str = "Content type is required";
|
||||||
|
|
@ -240,7 +236,7 @@ fn titan(
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate client-side limits (from header)
|
// validate client-side limits (from header)
|
||||||
if total > titan.size {
|
if total > titan.meta.size {
|
||||||
if let Err(e) = tmp.delete() {
|
if let Err(e) = tmp.delete() {
|
||||||
println!("[{}] [error] [{peer}] {e}", now());
|
println!("[{}] [error] [{peer}] {e}", now());
|
||||||
}
|
}
|
||||||
|
|
@ -282,12 +278,12 @@ fn titan(
|
||||||
}
|
}
|
||||||
|
|
||||||
// just to make sure
|
// just to make sure
|
||||||
if total > titan.size {
|
if total > titan.meta.size {
|
||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
|
|
||||||
// all data received
|
// all data received
|
||||||
if titan.size == total {
|
if titan.meta.size == total {
|
||||||
return match tmp.commit() {
|
return match tmp.commit() {
|
||||||
Ok(pmt) => send(
|
Ok(pmt) => send(
|
||||||
&response::redirect::Permanent {
|
&response::redirect::Permanent {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue