Compare commits
3 Commits
50145460b9
...
87e52a6d8c
Author | SHA1 | Date | |
---|---|---|---|
87e52a6d8c | |||
16f2a674c0 | |||
4985f43f1e |
@ -10,10 +10,14 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = ["gzip"]
|
||||
gzip = ["dep:flate2"]
|
||||
|
||||
[dependencies]
|
||||
bytes = "1.10.1"
|
||||
chrono = { version = "0.4.38", features = ["serde"] }
|
||||
flate2 = "1.0.29"
|
||||
flate2 = { version = "1.0.29", optional = true }
|
||||
reqwest = { version = "0.12.4", features = ["json","multipart"] }
|
||||
serde = { version = "1.0.199", features = ["derive"] }
|
||||
serde_json = "1.0.111"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{ResponseError,maybe_gzip_decode};
|
||||
use crate::util::{serialize_u64,deserialize_u64,response_ok,ResponseError,MaybeGzippedBytes};
|
||||
|
||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||
#[allow(nonstandard_style,dead_code)]
|
||||
@ -65,8 +65,8 @@ pub struct UpdateAssetRequest{
|
||||
#[derive(Clone,Debug,serde::Deserialize,serde::Serialize)]
|
||||
#[allow(nonstandard_style,dead_code)]
|
||||
pub enum Creator{
|
||||
userId(String),//u64 string
|
||||
groupId(String),//u64 string
|
||||
userId(#[serde(deserialize_with="deserialize_u64",serialize_with="serialize_u64")]u64),
|
||||
groupId(#[serde(deserialize_with="deserialize_u64",serialize_with="serialize_u64")]u64),
|
||||
}
|
||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||
#[allow(nonstandard_style,dead_code)]
|
||||
@ -146,14 +146,19 @@ pub struct GetAssetLatestRequest{
|
||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||
#[allow(nonstandard_style,dead_code)]
|
||||
pub struct AssetResponse{
|
||||
pub assetId:String,//u64 wrapped in quotes wohoo!!
|
||||
//u64 wrapped in quotes wohoo!!
|
||||
#[serde(deserialize_with="deserialize_u64")]
|
||||
#[serde(serialize_with="serialize_u64")]
|
||||
pub assetId:u64,
|
||||
pub assetType:AssetType,
|
||||
pub creationContext:CreationContext,
|
||||
pub description:Option<String>,
|
||||
pub displayName:String,
|
||||
pub path:String,
|
||||
pub revisionCreateTime:chrono::DateTime<chrono::Utc>,
|
||||
pub revisionId:String,//u64
|
||||
#[serde(deserialize_with="deserialize_u64")]
|
||||
#[serde(serialize_with="serialize_u64")]
|
||||
pub revisionId:u64,
|
||||
pub moderationResult:ModerationResult,
|
||||
pub icon:Option<String>,
|
||||
#[serde(default)]
|
||||
@ -169,7 +174,6 @@ pub enum GetError{
|
||||
ParseError(url::ParseError),
|
||||
Response(ResponseError),
|
||||
Reqwest(reqwest::Error),
|
||||
IO(std::io::Error)
|
||||
}
|
||||
impl std::fmt::Display for GetError{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
@ -375,7 +379,7 @@ impl Context{
|
||||
.text("request",request_config)
|
||||
.part("fileContent",part);
|
||||
|
||||
let operation=crate::response_ok(
|
||||
let operation=response_ok(
|
||||
self.post_form(url,form).await.map_err(CreateError::Reqwest)?
|
||||
).await.map_err(CreateError::Response)?
|
||||
.json::<RobloxOperation>().await.map_err(CreateError::Reqwest)?;
|
||||
@ -394,7 +398,7 @@ impl Context{
|
||||
.text("request",request_config)
|
||||
.part("fileContent",reqwest::multipart::Part::bytes(body));
|
||||
|
||||
let operation=crate::response_ok(
|
||||
let operation=response_ok(
|
||||
self.patch_form(url,form).await.map_err(UpdateError::Reqwest)?
|
||||
).await.map_err(UpdateError::Response)?
|
||||
.json::<RobloxOperation>().await.map_err(UpdateError::Reqwest)?;
|
||||
@ -407,7 +411,7 @@ impl Context{
|
||||
let raw_url=format!("https://apis.roblox.com/assets/v1/operations/{}",config.operation_id);
|
||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
.json::<RobloxOperation>().await.map_err(GetError::Reqwest)
|
||||
@ -416,7 +420,7 @@ impl Context{
|
||||
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}",config.asset_id);
|
||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
.json::<AssetResponse>().await.map_err(GetError::Reqwest)
|
||||
@ -425,7 +429,7 @@ impl Context{
|
||||
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}/versions/{}",config.asset_id,config.version);
|
||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
.json::<AssetResponse>().await.map_err(GetError::Reqwest)
|
||||
@ -434,7 +438,7 @@ impl Context{
|
||||
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)?;
|
||||
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
.json().await.map_err(GetError::Reqwest)
|
||||
@ -443,26 +447,26 @@ impl Context{
|
||||
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)?;
|
||||
|
||||
crate::response_ok(
|
||||
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>{
|
||||
pub async fn get_asset(&self,config:&AssetLocation)->Result<MaybeGzippedBytes,GetError>{
|
||||
let url=reqwest::Url::parse(config.location()).map_err(GetError::ParseError)?;
|
||||
|
||||
let body=crate::response_ok(
|
||||
let bytes=response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
.bytes().await.map_err(GetError::Reqwest)?;
|
||||
|
||||
maybe_gzip_decode(body).map_err(GetError::IO)
|
||||
Ok(MaybeGzippedBytes{bytes})
|
||||
}
|
||||
pub async fn get_asset_versions(&self,config:AssetVersionsRequest)->Result<AssetVersionsResponse,AssetVersionsError>{
|
||||
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}/versions",config.asset_id);
|
||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(AssetVersionsError::ParseError)?;
|
||||
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(AssetVersionsError::Reqwest)?
|
||||
).await.map_err(AssetVersionsError::Response)?
|
||||
.json::<AssetVersionsResponse>().await.map_err(AssetVersionsError::Reqwest)
|
||||
@ -477,7 +481,7 @@ impl Context{
|
||||
}
|
||||
}
|
||||
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(InventoryPageError::Reqwest)?
|
||||
).await.map_err(InventoryPageError::Response)?
|
||||
.json::<InventoryPageResponse>().await.map_err(InventoryPageError::Reqwest)
|
||||
@ -491,7 +495,7 @@ impl Context{
|
||||
query.append_pair("versionType","Published");
|
||||
}
|
||||
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.post(url,body).await.map_err(UpdateError::Reqwest)?
|
||||
).await.map_err(UpdateError::Response)?
|
||||
.json::<UpdatePlaceResponse>().await.map_err(UpdateError::Reqwest)
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{ResponseError,maybe_gzip_decode};
|
||||
use crate::util::{response_ok,ResponseError,MaybeGzippedBytes};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PostError{
|
||||
@ -91,7 +91,6 @@ pub enum GetError{
|
||||
ParseError(url::ParseError),
|
||||
Response(ResponseError),
|
||||
Reqwest(reqwest::Error),
|
||||
IO(std::io::Error)
|
||||
}
|
||||
impl std::fmt::Display for GetError{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
@ -371,7 +370,7 @@ impl Context{
|
||||
query.append_pair("groupId",group_id.to_string().as_str());
|
||||
}
|
||||
}
|
||||
let response=crate::response_ok(
|
||||
let response=response_ok(
|
||||
self.post(url,body).await.map_err(CreateError::PostError)?
|
||||
).await.map_err(CreateError::Response)?;
|
||||
|
||||
@ -423,7 +422,7 @@ impl Context{
|
||||
query.append_pair("groupId",group_id.to_string().as_str());
|
||||
}
|
||||
}
|
||||
let response=crate::response_ok(
|
||||
let response=response_ok(
|
||||
self.post(url,body).await.map_err(UploadError::PostError)?
|
||||
).await.map_err(UploadError::Response)?;
|
||||
|
||||
@ -449,7 +448,7 @@ impl Context{
|
||||
})
|
||||
}
|
||||
}
|
||||
pub async fn get_asset(&self,config:GetAssetRequest)->Result<Vec<u8>,GetError>{
|
||||
pub async fn get_asset(&self,config:GetAssetRequest)->Result<MaybeGzippedBytes,GetError>{
|
||||
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/").map_err(GetError::ParseError)?;
|
||||
//url borrow scope
|
||||
{
|
||||
@ -459,13 +458,13 @@ impl Context{
|
||||
query.append_pair("version",version.to_string().as_str());
|
||||
}
|
||||
}
|
||||
let body=crate::response_ok(
|
||||
|
||||
let bytes=response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
.bytes().await.map_err(GetError::Reqwest)?;
|
||||
|
||||
|
||||
maybe_gzip_decode(body).map_err(GetError::IO)
|
||||
Ok(MaybeGzippedBytes{bytes})
|
||||
}
|
||||
pub async fn get_asset_v2(&self,config:GetAssetRequest)->Result<GetAssetV2,GetAssetV2Error>{
|
||||
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v2/asset").map_err(GetAssetV2Error::ParseError)?;
|
||||
@ -477,7 +476,7 @@ impl Context{
|
||||
query.append_pair("version",version.to_string().as_str());
|
||||
}
|
||||
}
|
||||
let response=crate::response_ok(
|
||||
let response=response_ok(
|
||||
self.get(url).await.map_err(GetAssetV2Error::Reqwest)?
|
||||
).await.map_err(GetAssetV2Error::Response)?;
|
||||
|
||||
@ -497,19 +496,19 @@ impl Context{
|
||||
info,
|
||||
})
|
||||
}
|
||||
pub async fn get_asset_v2_download(&self,config:&GetAssetV2Location)->Result<Vec<u8>,GetError>{
|
||||
pub async fn get_asset_v2_download(&self,config:&GetAssetV2Location)->Result<MaybeGzippedBytes,GetError>{
|
||||
let url=reqwest::Url::parse(config.location.as_str()).map_err(GetError::ParseError)?;
|
||||
|
||||
let body=crate::response_ok(
|
||||
let bytes=response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
.bytes().await.map_err(GetError::Reqwest)?;
|
||||
|
||||
maybe_gzip_decode(body).map_err(GetError::IO)
|
||||
Ok(MaybeGzippedBytes{bytes})
|
||||
}
|
||||
pub async fn get_asset_details(&self,config:GetAssetDetailsRequest)->Result<AssetDetails,GetError>{
|
||||
let url=reqwest::Url::parse(format!("https://economy.roblox.com/v2/assets/{}/details",config.asset_id).as_str()).map_err(GetError::ParseError)?;
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
.json().await.map_err(GetError::Reqwest)
|
||||
@ -526,7 +525,7 @@ impl Context{
|
||||
query.append_pair("cursor",cursor);
|
||||
}
|
||||
}
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(PageError::Reqwest)?
|
||||
).await.map_err(PageError::Response)?
|
||||
.json::<AssetVersionsPageResponse>().await.map_err(PageError::Reqwest)
|
||||
@ -541,7 +540,7 @@ impl Context{
|
||||
query.append_pair("cursor",cursor);
|
||||
}
|
||||
}
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(PageError::Reqwest)?
|
||||
).await.map_err(PageError::Response)?
|
||||
.json::<CreationsPageResponse>().await.map_err(PageError::Reqwest)
|
||||
@ -555,7 +554,7 @@ impl Context{
|
||||
query.append_pair("cursor",cursor);
|
||||
}
|
||||
}
|
||||
crate::response_ok(
|
||||
response_ok(
|
||||
self.get(url).await.map_err(PageError::Reqwest)?
|
||||
).await.map_err(PageError::Response)?
|
||||
.json::<UserInventoryPageResponse>().await.map_err(PageError::Reqwest)
|
||||
|
@ -1,49 +1,3 @@
|
||||
pub mod cloud;
|
||||
pub mod cookie;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct StatusCodeWithUrlAndBody{
|
||||
pub status_code:reqwest::StatusCode,
|
||||
pub url:url::Url,
|
||||
pub body:String,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum ResponseError{
|
||||
Reqwest(reqwest::Error),
|
||||
StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody),
|
||||
}
|
||||
impl std::fmt::Display for ResponseError{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ResponseError{}
|
||||
// lazy function to draw out meaningful info from http response on failure
|
||||
pub(crate) async fn response_ok(response:reqwest::Response)->Result<reqwest::Response,ResponseError>{
|
||||
let status_code=response.status();
|
||||
if status_code.is_success(){
|
||||
Ok(response)
|
||||
}else{
|
||||
let url=response.url().to_owned();
|
||||
let bytes=response.bytes().await.map_err(ResponseError::Reqwest)?;
|
||||
let body=String::from_utf8_lossy(&bytes).to_string();
|
||||
Err(ResponseError::StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody{
|
||||
status_code,
|
||||
url,
|
||||
body,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn maybe_gzip_decode(data:bytes::Bytes)->std::io::Result<Vec<u8>>{
|
||||
match data.get(0..2){
|
||||
Some(b"\x1f\x8b")=>{
|
||||
use std::io::Read;
|
||||
let mut buf=Vec::new();
|
||||
flate2::read::GzDecoder::new(std::io::Cursor::new(data)).read_to_end(&mut buf)?;
|
||||
Ok(buf)
|
||||
},
|
||||
_=>Ok(data.to_vec()),
|
||||
}
|
||||
}
|
||||
mod util;
|
||||
|
103
rbx_asset/src/util.rs
Normal file
103
rbx_asset/src/util.rs
Normal file
@ -0,0 +1,103 @@
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct StatusCodeWithUrlAndBody{
|
||||
pub status_code:reqwest::StatusCode,
|
||||
pub url:url::Url,
|
||||
pub body:String,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum ResponseError{
|
||||
Reqwest(reqwest::Error),
|
||||
StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody),
|
||||
}
|
||||
impl std::fmt::Display for ResponseError{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ResponseError{}
|
||||
// lazy function to draw out meaningful info from http response on failure
|
||||
pub(crate) async fn response_ok(response:reqwest::Response)->Result<reqwest::Response,ResponseError>{
|
||||
let status_code=response.status();
|
||||
if status_code.is_success(){
|
||||
Ok(response)
|
||||
}else{
|
||||
let url=response.url().to_owned();
|
||||
let bytes=response.bytes().await.map_err(ResponseError::Reqwest)?;
|
||||
let body=String::from_utf8_lossy(&bytes).to_string();
|
||||
Err(ResponseError::StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody{
|
||||
status_code,
|
||||
url,
|
||||
body,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="gzip")]
|
||||
use std::io::Cursor;
|
||||
#[cfg(feature="gzip")]
|
||||
use flate2::read::GzDecoder;
|
||||
|
||||
/// An asset that might be gzipped. Use the read_with method to transparently decode gzip.
|
||||
pub struct MaybeGzippedBytes{
|
||||
pub(crate) bytes:bytes::Bytes,
|
||||
}
|
||||
impl MaybeGzippedBytes{
|
||||
pub fn into_inner(self)->bytes::Bytes{
|
||||
self.bytes
|
||||
}
|
||||
/// get a reference to the bytes, ignoring gzip decoding
|
||||
pub fn as_raw_ref(&self)->&[u8]{
|
||||
self.bytes.as_ref()
|
||||
}
|
||||
/// Transparently decode gzip data, if present (intermediate allocation)
|
||||
#[cfg(feature="gzip")]
|
||||
pub fn to_vec(&self)->std::io::Result<Vec<u8>>{
|
||||
use std::io::Read;
|
||||
match self.bytes.get(0..2){
|
||||
Some(b"\x1f\x8b")=>{
|
||||
let mut buf=Vec::new();
|
||||
GzDecoder::new(Cursor::new(self.bytes.as_ref())).read_to_end(&mut buf)?;
|
||||
Ok(buf)
|
||||
},
|
||||
_=>Ok(self.bytes.to_vec())
|
||||
}
|
||||
}
|
||||
/// Read the bytes with the provided decoders.
|
||||
/// The idea is to make a function that is generic over std::io::Read
|
||||
/// and pass the same function to both closures.
|
||||
/// This two closure hack must be done because of the different concrete types.
|
||||
#[cfg(feature="gzip")]
|
||||
pub fn read_with<'a,ReadGzip,ReadRaw,T>(&'a self,read_gzip:ReadGzip,read_raw:ReadRaw)->T
|
||||
where
|
||||
ReadGzip:Fn(GzDecoder<Cursor<&'a [u8]>>)->T,
|
||||
ReadRaw:Fn(Cursor<&'a [u8]>)->T,
|
||||
{
|
||||
match self.bytes.get(0..2){
|
||||
Some(b"\x1f\x8b")=>read_gzip(GzDecoder::new(Cursor::new(self.bytes.as_ref()))),
|
||||
_=>read_raw(Cursor::new(self.bytes.as_ref()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use serde::de::{Error,Unexpected};
|
||||
use serde::{Deserializer,Serializer};
|
||||
|
||||
struct U64StringVisitor;
|
||||
impl serde::de::Visitor<'_> for U64StringVisitor{
|
||||
type Value=u64;
|
||||
fn expecting(&self,formatter:&mut std::fmt::Formatter)->std::fmt::Result{
|
||||
write!(formatter,"string value with int")
|
||||
}
|
||||
fn visit_str<E:Error>(self,v:&str)->Result<Self::Value,E>{
|
||||
v.parse().map_err(|_|E::invalid_value(Unexpected::Str(v),&"u64"))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize_u64<'de,D:Deserializer<'de>>(deserializer:D)->Result<u64,D::Error>{
|
||||
deserializer.deserialize_any(U64StringVisitor)
|
||||
}
|
||||
|
||||
pub fn serialize_u64<S:Serializer>(v:&u64,serializer:S)->Result<S::Ok,S::Error>{
|
||||
serializer.serialize_str(v.to_string().as_str())
|
||||
}
|
36
src/main.rs
36
src/main.rs
@ -563,8 +563,8 @@ async fn main()->AResult<()>{
|
||||
subcommand.api_key_file,
|
||||
).await?,
|
||||
creator:match (subcommand.creator_user_id,subcommand.creator_group_id){
|
||||
(Some(user_id),None)=>rbx_asset::cloud::Creator::userId(user_id.to_string()),
|
||||
(None,Some(group_id))=>rbx_asset::cloud::Creator::groupId(group_id.to_string()),
|
||||
(Some(user_id),None)=>rbx_asset::cloud::Creator::userId(user_id),
|
||||
(None,Some(group_id))=>rbx_asset::cloud::Creator::groupId(group_id),
|
||||
other=>Err(anyhow!("Invalid creator {other:?}"))?,
|
||||
},
|
||||
input_file:subcommand.input_file,
|
||||
@ -585,8 +585,8 @@ async fn main()->AResult<()>{
|
||||
subcommand.cookie_file,
|
||||
).await?,
|
||||
creator:match (subcommand.creator_user_id,subcommand.creator_group_id){
|
||||
(Some(user_id),None)=>rbx_asset::cloud::Creator::userId(user_id.to_string()),
|
||||
(None,Some(group_id))=>rbx_asset::cloud::Creator::groupId(group_id.to_string()),
|
||||
(Some(user_id),None)=>rbx_asset::cloud::Creator::userId(user_id),
|
||||
(None,Some(group_id))=>rbx_asset::cloud::Creator::groupId(group_id),
|
||||
other=>Err(anyhow!("Invalid creator {other:?}"))?,
|
||||
},
|
||||
description:subcommand.description.unwrap_or_else(||String::with_capacity(0)),
|
||||
@ -903,11 +903,11 @@ async fn create_asset_medias(config:CreateAssetMediasConfig)->AResult<()>{
|
||||
async move{(path,
|
||||
async move{
|
||||
let asset_response=asset_response_result.map_err(DownloadDecalError::PollOperation)?;
|
||||
let file=cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{
|
||||
asset_id:asset_response.assetId.parse().map_err(DownloadDecalError::ParseInt)?,
|
||||
let maybe_gzip=cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{
|
||||
asset_id:asset_response.assetId,
|
||||
version:None,
|
||||
}).await.map_err(DownloadDecalError::Get)?;
|
||||
let dom=load_dom(std::io::Cursor::new(file)).map_err(DownloadDecalError::LoadDom)?;
|
||||
let dom=maybe_gzip.read_with(load_dom,load_dom).map_err(DownloadDecalError::LoadDom)?;
|
||||
let instance=dom.get_by_ref(
|
||||
*dom.root().children().first().ok_or(DownloadDecalError::NoFirstInstance)?
|
||||
).ok_or(DownloadDecalError::NoFirstInstance)?;
|
||||
@ -993,8 +993,8 @@ async fn asset_details(cookie:Cookie,asset_id:AssetID)->AResult<()>{
|
||||
|
||||
async fn download_version(cookie:Cookie,asset_id:AssetID,version:Option<u64>,dest:PathBuf)->AResult<()>{
|
||||
let context=CookieContext::new(cookie);
|
||||
let data=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id,version}).await?;
|
||||
tokio::fs::write(dest,data).await?;
|
||||
let maybe_gzip=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id,version}).await?;
|
||||
tokio::fs::write(dest,maybe_gzip.to_vec()?).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1006,9 +1006,9 @@ async fn download_version_v2(cookie:Cookie,asset_id:AssetID,version:Option<u64>,
|
||||
println!("version:{}",info.version);
|
||||
|
||||
let location=info.info.locations.first().ok_or(anyhow::Error::msg("No locations"))?;
|
||||
let data=context.get_asset_v2_download(location).await?;
|
||||
let maybe_gzip=context.get_asset_v2_download(location).await?;
|
||||
|
||||
tokio::fs::write(dest,data).await?;
|
||||
tokio::fs::write(dest,maybe_gzip.to_vec()?).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1024,7 +1024,7 @@ async fn download_list(cookie:Cookie,asset_id_file_map:AssetIDFileMap)->AResult<
|
||||
.buffer_unordered(CONCURRENT_REQUESTS)
|
||||
.for_each(|b:AResult<_>|async{
|
||||
match b{
|
||||
Ok((dest,data))=>if let Err(e)=tokio::fs::write(dest,data).await{
|
||||
Ok((dest,maybe_gzip))=>if let Err(e)=(async||{tokio::fs::write(dest,maybe_gzip.to_vec()?).await})().await{
|
||||
eprintln!("fs error: {}",e);
|
||||
},
|
||||
Err(e)=>eprintln!("dl error: {}",e),
|
||||
@ -1228,9 +1228,9 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
|
||||
let mut path=output_folder.clone();
|
||||
path.push(format!("{}_v{}.rbxl",config.asset_id,version_number));
|
||||
join_set.spawn(async move{
|
||||
let file=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id:config.asset_id,version:Some(version_number)}).await?;
|
||||
let maybe_gzip=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id:config.asset_id,version:Some(version_number)}).await?;
|
||||
|
||||
tokio::fs::write(path,file).await?;
|
||||
tokio::fs::write(path,maybe_gzip.to_vec()?).await?;
|
||||
|
||||
Ok::<_,anyhow::Error>(())
|
||||
});
|
||||
@ -1350,9 +1350,9 @@ struct DownloadDecompileConfig{
|
||||
|
||||
async fn download_decompile(config:DownloadDecompileConfig)->AResult<()>{
|
||||
let context=CookieContext::new(config.cookie);
|
||||
let file=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id:config.asset_id,version:None}).await?;
|
||||
let maybe_gzip=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id:config.asset_id,version:None}).await?;
|
||||
|
||||
let dom=load_dom(std::io::Cursor::new(file))?;
|
||||
let dom=maybe_gzip.read_with(load_dom,load_dom)?;
|
||||
let context=rox_compiler::DecompiledContext::from_dom(dom);
|
||||
|
||||
context.write_files(rox_compiler::WriteConfig{
|
||||
@ -1532,8 +1532,8 @@ async fn download_and_decompile_history_into_git(config:DownloadAndDecompileHist
|
||||
.map(|asset_version|{
|
||||
let context=context.clone();
|
||||
tokio::task::spawn(async move{
|
||||
let file=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id,version:Some(asset_version.assetVersionNumber)}).await?;
|
||||
let dom=load_dom(std::io::Cursor::new(file))?;
|
||||
let maybe_gzip=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id,version:Some(asset_version.assetVersionNumber)}).await?;
|
||||
let dom=maybe_gzip.read_with(load_dom,load_dom)?;
|
||||
Ok::<_,anyhow::Error>((asset_version,rox_compiler::DecompiledContext::from_dom(dom)))
|
||||
})
|
||||
}))
|
||||
|
Loading…
x
Reference in New Issue
Block a user