2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-23 03:41:23 +00:00

Fix content range serving

This commit is contained in:
Aode (lion) 2022-03-26 20:46:34 -05:00
parent 356e57e53d
commit 32045d2bef
4 changed files with 7 additions and 3 deletions

2
Cargo.lock generated
View file

@ -1580,7 +1580,7 @@ dependencies = [
[[package]] [[package]]
name = "pict-rs" name = "pict-rs"
version = "0.3.0-rc.7" version = "0.3.0-rc.8"
dependencies = [ dependencies = [
"actix-form-data", "actix-form-data",
"actix-rt", "actix-rt",

View file

@ -1,7 +1,7 @@
[package] [package]
name = "pict-rs" name = "pict-rs"
description = "A simple image hosting service" description = "A simple image hosting service"
version = "0.3.0-rc.7" version = "0.3.0-rc.8"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
license = "AGPL-3.0" license = "AGPL-3.0"
readme = "README.md" readme = "README.md"

View file

@ -9,7 +9,7 @@ _a simple image hosting service_
## Usage ## Usage
### Running ### Running
``` ```
pict-rs 0.3.0-rc.7 pict-rs 0.3.0-rc.8
USAGE: USAGE:
pict-rs [FLAGS] [OPTIONS] [SUBCOMMAND] pict-rs [FLAGS] [OPTIONS] [SUBCOMMAND]

View file

@ -15,6 +15,8 @@ pub(crate) fn chop_bytes(
length: u64, length: u64,
) -> Result<impl Stream<Item = Result<Bytes, Error>>, Error> { ) -> Result<impl Stream<Item = Result<Bytes, Error>>, Error> {
if let Some((start, end)) = byte_range.to_satisfiable_range(length) { if let Some((start, end)) = byte_range.to_satisfiable_range(length) {
// END IS INCLUSIVE
let end = end as usize + 1;
return Ok(once(ready(Ok(bytes.slice(start as usize..end as usize))))); return Ok(once(ready(Ok(bytes.slice(start as usize..end as usize)))));
} }
@ -31,6 +33,8 @@ where
Error: From<S::Error>, Error: From<S::Error>,
{ {
if let Some((start, end)) = byte_range.to_satisfiable_range(length) { if let Some((start, end)) = byte_range.to_satisfiable_range(length) {
// END IS INCLUSIVE
let end = end + 1;
return Ok(store return Ok(store
.to_stream(identifier, Some(start), Some(end.saturating_sub(start))) .to_stream(identifier, Some(start), Some(end.saturating_sub(start)))
.await?); .await?);