parent
99077cf467
commit
4d26e7ad19
@ -178,6 +178,23 @@ impl std::fmt::Display for GetError{
|
|||||||
}
|
}
|
||||||
impl std::error::Error for GetError{}
|
impl std::error::Error for GetError{}
|
||||||
|
|
||||||
|
#[derive(Debug,serde::Deserialize)]
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct AssetLocation{
|
||||||
|
// this field is private so users cannot mutate it
|
||||||
|
location:String,
|
||||||
|
pub requestId:String,
|
||||||
|
pub IsHashDynamic:bool,
|
||||||
|
pub IsCopyrightProtected:bool,
|
||||||
|
pub isArchived:bool,
|
||||||
|
pub assetTypeId:u32,
|
||||||
|
}
|
||||||
|
impl AssetLocation{
|
||||||
|
pub fn location(&self)->&str{
|
||||||
|
&self.location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct AssetVersionsRequest{
|
pub struct AssetVersionsRequest{
|
||||||
pub asset_id:u64,
|
pub asset_id:u64,
|
||||||
pub cursor:Option<String>,
|
pub cursor:Option<String>,
|
||||||
@ -407,31 +424,33 @@ impl Context{
|
|||||||
).await.map_err(GetError::Response)?
|
).await.map_err(GetError::Response)?
|
||||||
.json::<AssetResponse>().await.map_err(GetError::Reqwest)
|
.json::<AssetResponse>().await.map_err(GetError::Reqwest)
|
||||||
}
|
}
|
||||||
pub async fn get_asset(&self,config:GetAssetLatestRequest)->Result<Vec<u8>,GetError>{
|
pub async fn get_asset_location(&self,config:GetAssetLatestRequest)->Result<AssetLocation,GetError>{
|
||||||
let raw_url=format!("https://apis.roblox.com/asset-delivery-api/v1/assetId/{}",config.asset_id);
|
let raw_url=format!("https://apis.roblox.com/asset-delivery-api/v1/assetId/{}",config.asset_id);
|
||||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||||
|
|
||||||
let body=crate::response_ok(
|
crate::response_ok(
|
||||||
self.get(url).await.map_err(GetError::Reqwest)?
|
self.get(url).await.map_err(GetError::Reqwest)?
|
||||||
).await.map_err(GetError::Response)?
|
).await.map_err(GetError::Response)?
|
||||||
.bytes().await.map_err(GetError::Reqwest)?;
|
.json().await.map_err(GetError::Reqwest)
|
||||||
|
|
||||||
match maybe_gzip_decode(&mut std::io::Cursor::new(body)){
|
|
||||||
Ok(ReaderType::GZip(readable))=>read_readable(readable),
|
|
||||||
Ok(ReaderType::Raw(readable))=>read_readable(readable),
|
|
||||||
Err(e)=>Err(e),
|
|
||||||
}.map_err(GetError::IO)
|
|
||||||
}
|
}
|
||||||
pub async fn get_asset_version(&self,config:GetAssetVersionRequest)->Result<Vec<u8>,GetError>{
|
pub async fn get_asset_version_location(&self,config:GetAssetVersionRequest)->Result<AssetLocation,GetError>{
|
||||||
let raw_url=format!("https://apis.roblox.com/asset-delivery-api/v1/assetId/{}/version/{}",config.asset_id,config.version);
|
let raw_url=format!("https://apis.roblox.com/asset-delivery-api/v1/assetId/{}/version/{}",config.asset_id,config.version);
|
||||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||||
|
|
||||||
|
crate::response_ok(
|
||||||
|
self.get(url).await.map_err(GetError::Reqwest)?
|
||||||
|
).await.map_err(GetError::Response)?
|
||||||
|
.json().await.map_err(GetError::Reqwest)
|
||||||
|
}
|
||||||
|
pub async fn get_asset(&self,config:&AssetLocation)->Result<Vec<u8>,GetError>{
|
||||||
|
let url=reqwest::Url::parse(config.location.as_str()).map_err(GetError::ParseError)?;
|
||||||
|
|
||||||
let body=crate::response_ok(
|
let body=crate::response_ok(
|
||||||
self.get(url).await.map_err(GetError::Reqwest)?
|
self.get(url).await.map_err(GetError::Reqwest)?
|
||||||
).await.map_err(GetError::Response)?
|
).await.map_err(GetError::Response)?
|
||||||
.bytes().await.map_err(GetError::Reqwest)?;
|
.bytes().await.map_err(GetError::Reqwest)?;
|
||||||
|
|
||||||
match maybe_gzip_decode(&mut std::io::Cursor::new(body)){
|
match maybe_gzip_decode(std::io::Cursor::new(body)){
|
||||||
Ok(ReaderType::GZip(readable))=>read_readable(readable),
|
Ok(ReaderType::GZip(readable))=>read_readable(readable),
|
||||||
Ok(ReaderType::Raw(readable))=>read_readable(readable),
|
Ok(ReaderType::Raw(readable))=>read_readable(readable),
|
||||||
Err(e)=>Err(e),
|
Err(e)=>Err(e),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user