rbx_asset: deduplicate common code
This commit is contained in:
parent
64e4887b83
commit
fb9dd8660d
@ -1,4 +1,4 @@
|
|||||||
use crate::ResponseError;
|
use crate::{ResponseError,ReaderType,maybe_gzip_decode,read_readable};
|
||||||
|
|
||||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||||
#[allow(nonstandard_style,dead_code)]
|
#[allow(nonstandard_style,dead_code)]
|
||||||
@ -297,25 +297,6 @@ impl RobloxOperation{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//idk how to do this better
|
|
||||||
enum ReaderType<R:std::io::Read>{
|
|
||||||
GZip(flate2::read::GzDecoder<std::io::BufReader<R>>),
|
|
||||||
Raw(std::io::BufReader<R>),
|
|
||||||
}
|
|
||||||
fn maybe_gzip_decode<R:std::io::Read>(input:R)->std::io::Result<ReaderType<R>>{
|
|
||||||
let mut buf=std::io::BufReader::new(input);
|
|
||||||
let peek=std::io::BufRead::fill_buf(&mut buf)?;
|
|
||||||
match &peek[0..2]{
|
|
||||||
b"\x1f\x8b"=>Ok(ReaderType::GZip(flate2::read::GzDecoder::new(buf))),
|
|
||||||
_=>Ok(ReaderType::Raw(buf)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn read_readable(mut readable:impl std::io::Read)->std::io::Result<Vec<u8>>{
|
|
||||||
let mut contents=Vec::new();
|
|
||||||
readable.read_to_end(&mut contents)?;
|
|
||||||
Ok(contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ApiKey(String);
|
pub struct ApiKey(String);
|
||||||
impl ApiKey{
|
impl ApiKey{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::ResponseError;
|
use crate::{ResponseError,ReaderType,maybe_gzip_decode,read_readable};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum PostError{
|
pub enum PostError{
|
||||||
@ -306,25 +306,6 @@ pub struct UserInventoryPageResponse{
|
|||||||
pub data:Vec<UserInventoryItem>,
|
pub data:Vec<UserInventoryItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
//idk how to do this better
|
|
||||||
enum ReaderType<R:std::io::Read>{
|
|
||||||
GZip(flate2::read::GzDecoder<std::io::BufReader<R>>),
|
|
||||||
Raw(std::io::BufReader<R>),
|
|
||||||
}
|
|
||||||
fn maybe_gzip_decode<R:std::io::Read>(input:R)->std::io::Result<ReaderType<R>>{
|
|
||||||
let mut buf=std::io::BufReader::new(input);
|
|
||||||
let peek=std::io::BufRead::fill_buf(&mut buf)?;
|
|
||||||
match &peek[0..2]{
|
|
||||||
b"\x1f\x8b"=>Ok(ReaderType::GZip(flate2::read::GzDecoder::new(buf))),
|
|
||||||
_=>Ok(ReaderType::Raw(buf)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn read_readable(mut readable:impl std::io::Read)->std::io::Result<Vec<u8>>{
|
|
||||||
let mut contents=Vec::new();
|
|
||||||
readable.read_to_end(&mut contents)?;
|
|
||||||
Ok(contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Cookie(String);
|
pub struct Cookie(String);
|
||||||
impl Cookie{
|
impl Cookie{
|
||||||
|
@ -20,7 +20,7 @@ impl std::fmt::Display for ResponseError{
|
|||||||
}
|
}
|
||||||
impl std::error::Error for ResponseError{}
|
impl std::error::Error for ResponseError{}
|
||||||
// lazy function to draw out meaningful info from http response on failure
|
// lazy function to draw out meaningful info from http response on failure
|
||||||
pub async fn response_ok(response:reqwest::Response)->Result<reqwest::Response,ResponseError>{
|
pub(crate) async fn response_ok(response:reqwest::Response)->Result<reqwest::Response,ResponseError>{
|
||||||
let status_code=response.status();
|
let status_code=response.status();
|
||||||
if status_code.is_success(){
|
if status_code.is_success(){
|
||||||
Ok(response)
|
Ok(response)
|
||||||
@ -35,3 +35,22 @@ pub async fn response_ok(response:reqwest::Response)->Result<reqwest::Response,R
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//idk how to do this better
|
||||||
|
pub(crate) enum ReaderType<R:std::io::Read>{
|
||||||
|
GZip(flate2::read::GzDecoder<std::io::BufReader<R>>),
|
||||||
|
Raw(std::io::BufReader<R>),
|
||||||
|
}
|
||||||
|
pub(crate) fn maybe_gzip_decode<R:std::io::Read>(input:R)->std::io::Result<ReaderType<R>>{
|
||||||
|
let mut buf=std::io::BufReader::new(input);
|
||||||
|
let peek=std::io::BufRead::fill_buf(&mut buf)?;
|
||||||
|
match &peek[0..2]{
|
||||||
|
b"\x1f\x8b"=>Ok(ReaderType::GZip(flate2::read::GzDecoder::new(buf))),
|
||||||
|
_=>Ok(ReaderType::Raw(buf)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub(crate) fn read_readable(mut readable:impl std::io::Read)->std::io::Result<Vec<u8>>{
|
||||||
|
let mut contents=Vec::new();
|
||||||
|
readable.read_to_end(&mut contents)?;
|
||||||
|
Ok(contents)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user