30 Commits

Author SHA1 Message Date
c2052be036 Merge pull request 'use old api for compile-upload-asset' () from staging into master
Reviewed-on: 
2024-07-10 17:18:05 +00:00
7ab064e61e v0.4.3 use old api for compile-upload-asset 2024-07-10 10:16:11 -07:00
4c00d7fe1a use old asset api for compile-upload-asset 2024-07-10 10:14:35 -07:00
74b84f6de0 typo 2024-07-10 10:07:21 -07:00
2e9485dea6 Merge pull request 'add old asset upload api' () from staging into master
Reviewed-on: 
2024-07-10 16:45:17 +00:00
6111ebd0fe v0.4.2 old asset api 2024-07-10 09:38:31 -07:00
b1a118c29e add old asset api 2024-07-10 09:33:45 -07:00
8222cb3457 don't hard code asset type, expected price 2024-07-10 09:33:45 -07:00
04d092c76f rename limited commands 2024-07-10 09:08:20 -07:00
0d92221a27 Merge pull request 'Update for ci build' () from feature/CI into master
Reviewed-on: 
2024-07-08 20:39:48 +00:00
9c862717a5 Add build status 2024-07-04 18:33:41 -04:00
11fee65354 Update for ci build 2024-07-04 18:31:06 -04:00
c947691f75 fix regex and remove --! because luau doesn't like it 2024-07-04 13:33:13 -07:00
cb984a9f20 v0.4.1 partially revert api changes because the new one is horrible 2024-07-04 13:32:20 -07:00
e46ad7a6a8 rbx_asset v0.2.1 old api is back 2024-07-04 13:32:20 -07:00
4805f3bc08 use old api for some things 2024-07-04 13:32:20 -07:00
9638672dde revive old api code 2024-07-04 13:32:20 -07:00
c945036d60 rename context to cloud 2024-07-04 13:32:20 -07:00
f9bdfd0e00 improve type safety for secrets 2024-07-04 13:32:20 -07:00
d468113e51 manually specify creator :/ 2024-07-04 13:32:20 -07:00
b72bed638d v0.4.0 new roblox api 2024-07-04 13:32:20 -07:00
452c00d53e refactor for new api 2024-07-04 13:32:20 -07:00
b89a787af2 move type conversion to argument stuff 2024-07-04 12:45:28 -07:00
5085f6587f v0.3.4 download-decompile 2024-07-04 12:45:28 -07:00
c856301aa6 download-decompile 2024-07-04 12:45:28 -07:00
d38152600e v0.3.3 compile-upload 2024-07-04 12:45:28 -07:00
c08ff63033 compile-upload 2024-07-04 12:45:28 -07:00
6720f6213f fix compiling with no template 2024-07-04 12:45:28 -07:00
db34436d64 v0.3.2 rox_compiler 2024-07-04 12:45:28 -07:00
a6ae26a93e refactor rox_compiler into module 2024-07-04 12:45:28 -07:00
11 changed files with 310 additions and 115 deletions

24
.drone.yml Normal file

@ -0,0 +1,24 @@
---
kind: pipeline
type: docker
platform:
os: linux
arch: amd64
steps:
- name: image
image: plugins/docker
settings:
registry: git.itzana.me
repo: git.itzana.me/strafesnet/asset-tool
tags:
- latest
username:
from_secret: GIT_USER
password:
from_secret: GIT_PASS
dockerfile: Containerfile
when:
branch:
- master

4
Cargo.lock generated

@ -110,7 +110,7 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]]
name = "asset-tool"
version = "0.4.0"
version = "0.4.3"
dependencies = [
"anyhow",
"clap",
@ -1166,7 +1166,7 @@ dependencies = [
[[package]]
name = "rbx_asset"
version = "0.2.0"
version = "0.2.1"
dependencies = [
"chrono",
"flate2",

@ -1,7 +1,7 @@
workspace = { members = ["rbx_asset", "rox_compiler"] }
[package]
name = "asset-tool"
version = "0.4.0"
version = "0.4.3"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,6 +1,6 @@
# Using the `rust-musl-builder` as base image, instead of
# the official Rust toolchain
FROM clux/muslrust:stable AS chef
FROM docker.io/clux/muslrust:stable AS chef
USER root
RUN cargo install cargo-chef
WORKDIR /app
@ -16,8 +16,8 @@ RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path r
COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl --bin asset-tool
FROM alpine AS runtime
FROM docker.io/alpine:latest AS runtime
RUN addgroup -S myuser && adduser -S myuser -G myuser
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/asset-tool /usr/local/bin/
USER myuser
CMD ["/usr/local/bin/asset-tool"]
ENTRYPOINT ["/usr/local/bin/asset-tool"]

@ -1,3 +1,5 @@
# asset-tool
[![Build Status](https://ci.itzana.me/api/badges/StrafesNET/asset-tool/status.svg?ref=refs/heads/master)](https://ci.itzana.me/StrafesNET/asset-tool)
For uploading and downloading roblox assets.

@ -1,6 +1,6 @@
[package]
name = "rbx_asset"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
publish = ["strafesnet"]

@ -60,20 +60,6 @@ pub struct Preview{
pub asset:String,
pub altText:String,
}
#[derive(Debug,serde::Deserialize,serde::Serialize)]
#[allow(nonstandard_style,dead_code)]
pub struct AssetResponse{
pub assetId:u64,
pub creationContext:CreationContext,
pub description:String,
pub displayName:String,
pub path:String,
pub revisionId:u64,
pub revisionCreateTime:chrono::DateTime<chrono::Utc>,
pub moderationResult:ModerationResult,
pub icon:String,
pub previews:Vec<Preview>,
}
#[allow(nonstandard_style,dead_code)]
pub struct UpdatePlaceRequest{
pub universeId:u64,
@ -119,7 +105,7 @@ pub struct AssetVersionsRequest{
pub asset_id:u64,
pub cursor:Option<String>,
}
#[derive(serde::Deserialize,serde::Serialize)]
#[derive(Debug,serde::Deserialize,serde::Serialize)]
#[allow(nonstandard_style,dead_code)]
pub struct AssetVersion{
pub Id:u64,
@ -131,7 +117,7 @@ pub struct AssetVersion{
pub created:chrono::DateTime<chrono::Utc>,
pub isPublished:bool,
}
#[derive(serde::Deserialize)]
#[derive(Debug,serde::Deserialize)]
#[allow(nonstandard_style,dead_code)]
pub struct AssetVersionsResponse{
pub previousPageCursor:Option<String>,
@ -154,13 +140,13 @@ pub struct InventoryPageRequest{
pub group:u64,
pub cursor:Option<String>,
}
#[derive(serde::Deserialize,serde::Serialize)]
#[derive(Debug,serde::Deserialize,serde::Serialize)]
#[allow(nonstandard_style,dead_code)]
pub struct InventoryItem{
pub id:u64,
pub name:String,
}
#[derive(serde::Deserialize,serde::Serialize)]
#[derive(Debug,serde::Deserialize,serde::Serialize)]
#[allow(nonstandard_style,dead_code)]
pub struct InventoryPageResponse{
pub totalResults:u64,//up to 50
@ -185,6 +171,16 @@ impl std::fmt::Display for InventoryPageError{
}
impl std::error::Error for InventoryPageError{}
#[derive(Debug,serde::Deserialize,serde::Serialize)]
#[allow(nonstandard_style,dead_code)]
pub struct RobloxOperation{
pub path:Option<std::path::PathBuf>,
pub metadata:Option<String>,
pub done:Option<bool>,
pub error:Option<String>,
pub response:Option<String>,
}
//idk how to do this better
enum ReaderType<R:std::io::Read>{
GZip(flate2::read::GzDecoder<std::io::BufReader<R>>),
@ -251,7 +247,7 @@ impl CloudContext{
.multipart(form)
.send().await
}
pub async fn create_asset(&self,config:CreateAssetRequest,body:impl Into<std::borrow::Cow<'static,[u8]>>)->Result<AssetResponse,CreateError>{
pub async fn create_asset(&self,config:CreateAssetRequest,body:impl Into<std::borrow::Cow<'static,[u8]>>)->Result<RobloxOperation,CreateError>{
let url=reqwest::Url::parse("https://apis.roblox.com/assets/v1/assets").map_err(CreateError::ParseError)?;
let request_config=serde_json::to_string(&config).map_err(CreateError::SerializeError)?;
@ -260,11 +256,12 @@ impl CloudContext{
.text("request",request_config)
.part("fileContent",reqwest::multipart::Part::bytes(body));
let resp=self.post_form(url,form).await.map_err(CreateError::Reqwest)?;
let resp=self.post_form(url,form).await.map_err(CreateError::Reqwest)?
.error_for_status().map_err(CreateError::Reqwest)?;
Ok(resp.json::<AssetResponse>().await.map_err(CreateError::Reqwest)?)
Ok(resp.json::<RobloxOperation>().await.map_err(CreateError::Reqwest)?)
}
pub async fn update_asset(&self,config:UpdateAssetRequest,body:impl Into<std::borrow::Cow<'static,[u8]>>)->Result<AssetResponse,UpdateError>{
pub async fn update_asset(&self,config:UpdateAssetRequest,body:impl Into<std::borrow::Cow<'static,[u8]>>)->Result<RobloxOperation,UpdateError>{
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}",config.assetId);
let url=reqwest::Url::parse(raw_url.as_str()).map_err(UpdateError::ParseError)?;
@ -274,9 +271,12 @@ impl CloudContext{
.text("request",request_config)
.part("fileContent",reqwest::multipart::Part::bytes(body));
let resp=self.patch_form(url,form).await.map_err(UpdateError::Reqwest)?;
let resp=self.patch_form(url,form).await
.map_err(UpdateError::Reqwest)?
//roblox api documentation is very poor, just give the status code and drop the json
.error_for_status().map_err(UpdateError::Reqwest)?;
Ok(resp.json::<AssetResponse>().await.map_err(UpdateError::Reqwest)?)
Ok(resp.json::<RobloxOperation>().await.map_err(UpdateError::Reqwest)?)
}
pub async fn get_asset(&self,config:GetAssetRequest)->Result<Vec<u8>,GetError>{
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/").map_err(GetError::ParseError)?;
@ -320,9 +320,15 @@ impl CloudContext{
}
pub async fn update_place(&self,config:UpdatePlaceRequest,body:impl Into<reqwest::Body>+Clone)->Result<UpdatePlaceResponse,UpdateError>{
let raw_url=format!("https://apis.roblox.com/universes/v1/{}/places/{}/versions",config.universeId,config.placeId);
let url=reqwest::Url::parse(raw_url.as_str()).map_err(UpdateError::ParseError)?;
let mut url=reqwest::Url::parse(raw_url.as_str()).map_err(UpdateError::ParseError)?;
//url borrow scope
{
let mut query=url.query_pairs_mut();//borrow here
query.append_pair("versionType","Published");
}
let resp=self.post(url,body).await.map_err(UpdateError::Reqwest)?;
let resp=self.post(url,body).await.map_err(UpdateError::Reqwest)?
.error_for_status().map_err(UpdateError::Reqwest)?;
Ok(resp.json::<UpdatePlaceResponse>().await.map_err(UpdateError::Reqwest)?)
}

@ -62,22 +62,22 @@ pub struct UploadResponse{
}
#[allow(nonstandard_style,dead_code)]
pub struct DownloadRequest{
pub struct GetAssetRequest{
pub asset_id:u64,
pub version:Option<u64>,
}
#[derive(Debug)]
pub enum DownloadError{
pub enum GetError{
ParseError(url::ParseError),
Reqwest(reqwest::Error),
IO(std::io::Error)
}
impl std::fmt::Display for DownloadError{
impl std::fmt::Display for GetError{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f,"{self:?}")
}
}
impl std::error::Error for DownloadError{}
impl std::error::Error for GetError{}
pub struct AssetVersionsPageRequest{
pub asset_id:u64,
@ -269,8 +269,8 @@ impl CookieContext{
Ok(resp.json::<UploadResponse>().await.map_err(UploadError::Reqwest)?)
}
pub async fn download(&self,config:DownloadRequest)->Result<Vec<u8>,DownloadError>{
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/").map_err(DownloadError::ParseError)?;
pub async fn get_asset(&self,config:GetAssetRequest)->Result<Vec<u8>,GetError>{
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/").map_err(GetError::ParseError)?;
//url borrow scope
{
let mut query=url.query_pairs_mut();//borrow here
@ -279,15 +279,15 @@ impl CookieContext{
query.append_pair("version",version.to_string().as_str());
}
}
let resp=self.get(url).await.map_err(DownloadError::Reqwest)?;
let resp=self.get(url).await.map_err(GetError::Reqwest)?;
let body=resp.bytes().await.map_err(DownloadError::Reqwest)?;
let body=resp.bytes().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(DownloadError::IO)
}.map_err(GetError::IO)
}
pub async fn get_asset_versions_page(&self,config:AssetVersionsPageRequest)->Result<AssetVersionsPageResponse,AssetVersionsPageError>{
let mut url=reqwest::Url::parse(format!("https://develop.roblox.com/v1/assets/{}/saved-versions",config.asset_id).as_str()).map_err(AssetVersionsPageError::ParseError)?;
@ -305,7 +305,7 @@ impl CookieContext{
Ok(self.get(url).await.map_err(AssetVersionsPageError::Reqwest)?
.json::<AssetVersionsPageResponse>().await.map_err(AssetVersionsPageError::Reqwest)?)
}
pub async fn inventory_page(&self,config:InventoryPageRequest)->Result<InventoryPageResponse,InventoryPageError>{
pub async fn get_inventory_page(&self,config:InventoryPageRequest)->Result<InventoryPageResponse,InventoryPageError>{
let mut url=reqwest::Url::parse(format!("https://apis.roblox.com/toolbox-service/v1/creations/group/{}/10?limit=50",config.group).as_str()).map_err(InventoryPageError::ParseError)?;
//url borrow scope
{

@ -19,15 +19,15 @@ impl PropertiesOverride{
impl std::fmt::Display for PropertiesOverride{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
if let Some(name)=self.name.as_deref(){
writeln!(f,"--!Properties.Name = \"{}\"",name)?;
writeln!(f,"-- Properties.Name = \"{}\"",name)?;
}
if let Some(class)=self.class.as_deref(){
writeln!(f,"--!Properties.ClassName = \"{}\"",class)?;
writeln!(f,"-- Properties.ClassName = \"{}\"",class)?;
}
Ok(())
}
}
pub(crate) fn sanitize<'a>(s:&'a str)->std::borrow::Cow<'a,str>{
lazy_regex::regex!(r"[^A-z0-9.-]").replace_all(s,"_")
lazy_regex::regex!(r"[^A-Za-z0-9.-]").replace_all(s,"_")
}

@ -203,7 +203,7 @@ impl ScriptWithOverrides{
let mut count=0;
for line in source.lines(){
//only string type properties are supported atm
if let Some(captures)=lazy_regex::regex!(r#"^\-\-\!\s*Properties\.([A-z]\w*)\s*\=\s*"(\w+)"$"#)
if let Some(captures)=lazy_regex::regex!(r#"^\-\-\s*Properties\.([A-Za-z]\w*)\s*\=\s*"(\w+)"$"#)
.captures(line){
count+=line.len();
match &captures[1]{
@ -248,7 +248,7 @@ pub enum CompileNodeError{
extension:String,
style:Option<Style>,
},
NoExtension,
UnknownExtension,
}
impl std::fmt::Display for CompileNodeError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
@ -343,7 +343,7 @@ impl CompileNode{
_=>false,
};
let (ext_len,file_discernment)={
if let Some(captures)=lazy_regex::regex!(r"^.*(.module.lua|.client.lua|.server.lua|.rbxmx|.lua)$")
if let Some(captures)=lazy_regex::regex!(r"^.*(\.module\.lua|\.client\.lua|\.server\.lua)$")
.captures(file_name.as_str()){
let ext=&captures[1];
(ext.len(),match ext{
@ -355,6 +355,12 @@ impl CompileNode{
},
".client.lua"=>FileDiscernment::Script(ScriptHint::LocalScript),
".server.lua"=>FileDiscernment::Script(ScriptHint::Script),
_=>panic!("Regex failed"),
})
}else if let Some(captures)=lazy_regex::regex!(r"^.*(\.rbxmx|\.lua)$")
.captures(file_name.as_str()){
let ext=&captures[1];
(ext.len(),match ext{
".rbxmx"=>{
if is_goober{
Err(CompileNodeError::ExtensionNotSupportedInStyle{extension:ext.to_owned(),style})?;
@ -365,7 +371,7 @@ impl CompileNode{
_=>panic!("Regex failed"),
})
}else{
return Err(CompileNodeError::NoExtension);
return Err(CompileNodeError::UnknownExtension);
}
};
file_name.truncate(file_name.len()-ext_len);
@ -500,10 +506,19 @@ pub async fn compile(config:CompileConfig,mut dom:&mut rbx_dom_weak::WeakDom)->R
Ok(Some(entry))=>tokio::spawn(async move{
let met=entry.metadata().await.map_err(CompileError::IO)?;
//discern that bad boy
let compile_class=match met.is_dir(){
true=>CompileNode::from_folder(&entry,style).await,
false=>CompileNode::from_file(&entry,style).await,
}.map_err(CompileError::CompileNode)?;
let compile_class={
let result=match met.is_dir(){
true=>CompileNode::from_folder(&entry,style).await,
false=>CompileNode::from_file(&entry,style).await,
};
match result{
Ok(compile_class)=>compile_class,
Err(e)=>{
println!("Ignoring file {entry:?} due to error {e}");
return Ok(None);
},
}
};
//prepare data structure
Ok(Some((compile_class.blacklist,match compile_class.class{
CompileClass::Folder=>PreparedData::Builder(rbx_dom_weak::InstanceBuilder::new("Folder").with_name(compile_class.name.as_str())),

@ -2,8 +2,8 @@ use std::{io::Read,path::PathBuf};
use clap::{Args,Parser,Subcommand};
use anyhow::Result as AResult;
use futures::StreamExt;
use rbx_asset::cloud::{ApiKey,CloudContext,InventoryItem};
use rbx_asset::cookie::{Cookie,CookieContext,AssetVersion};
use rbx_asset::cloud::{ApiKey,CloudContext};
use rbx_asset::cookie::{Cookie,CookieContext,AssetVersion,InventoryItem};
type AssetID=u64;
type AssetIDFileMap=Vec<(AssetID,PathBuf)>;
@ -25,7 +25,9 @@ enum Commands{
DownloadDecompile(DownloadDecompileSubcommand),
DownloadGroupInventoryJson(DownloadGroupInventoryJsonSubcommand),
CreateAsset(CreateAssetSubcommand),
CreateAssetMedia(CreateAssetMediaSubcommand),
UploadAsset(UpdateAssetSubcommand),
UploadAssetMedia(UpdateAssetMediaSubcommand),
UploadPlace(UpdatePlaceSubcommand),
Compile(CompileSubcommand),
CompileUploadAsset(CompileUploadAssetSubcommand),
@ -82,6 +84,27 @@ struct DownloadGroupInventoryJsonSubcommand{
}
#[derive(Args)]
struct CreateAssetSubcommand{
#[arg(long,group="cookie",required=true)]
cookie_literal:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_envvar:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_file:Option<PathBuf>,
#[arg(long)]
group_id:Option<u64>,
#[arg(long)]
input_file:PathBuf,
#[arg(long)]
model_name:String,
#[arg(long)]
description:Option<String>,
#[arg(long)]
free_model:Option<bool>,
#[arg(long)]
allow_comments:Option<bool>,
}
#[derive(Args)]
struct CreateAssetMediaSubcommand{
#[arg(long,group="api_key",required=true)]
api_key_literal:Option<String>,
#[arg(long,group="api_key",required=true)]
@ -95,12 +118,40 @@ struct CreateAssetSubcommand{
#[arg(long)]
input_file:PathBuf,
#[arg(long)]
asset_type:AssetType,
#[arg(long)]
creator_user_id:u64,
#[arg(long)]
creator_group_id:Option<u64>,
/// Expected price limits how much robux can be spent to create the asset (defaults to 0)
#[arg(long)]
expected_price:Option<u64>,
}
#[derive(Args)]
struct UpdateAssetSubcommand{
#[arg(long)]
asset_id:AssetID,
#[arg(long,group="cookie",required=true)]
cookie_literal:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_envvar:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_file:Option<PathBuf>,
#[arg(long)]
group_id:Option<u64>,
#[arg(long)]
input_file:PathBuf,
#[arg(long)]
change_name:Option<String>,
#[arg(long)]
change_description:Option<String>,
#[arg(long)]
change_free_model:Option<bool>,
#[arg(long)]
change_allow_comments:Option<bool>,
}
#[derive(Args)]
struct UpdateAssetMediaSubcommand{
#[arg(long)]
asset_id:AssetID,
#[arg(long,group="api_key",required=true)]
@ -142,14 +193,14 @@ struct CompileSubcommand{
struct CompileUploadAssetSubcommand{
#[arg(long)]
asset_id:AssetID,
#[arg(long,group="api_key",required=true)]
api_key_literal:Option<String>,
#[arg(long,group="api_key",required=true)]
api_key_envvar:Option<String>,
#[arg(long,group="api_key",required=true)]
api_key_file:Option<PathBuf>,
#[arg(long,group="cookie",required=true)]
cookie_literal:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_envvar:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_file:Option<PathBuf>,
#[arg(long)]
input_file:PathBuf,
group_id:Option<u64>,
#[arg(long)]
input_folder:Option<PathBuf>,
#[arg(long)]
@ -170,8 +221,6 @@ struct CompileUploadPlaceSubcommand{
#[arg(long,group="api_key",required=true)]
api_key_file:Option<PathBuf>,
#[arg(long)]
input_file:PathBuf,
#[arg(long)]
input_folder:Option<PathBuf>,
#[arg(long)]
style:Option<Style>,
@ -195,12 +244,12 @@ struct DecompileSubcommand{
}
#[derive(Args)]
struct DownloadDecompileSubcommand{
#[arg(long,group="api_key",required=true)]
api_key_literal:Option<String>,
#[arg(long,group="api_key",required=true)]
api_key_envvar:Option<String>,
#[arg(long,group="api_key",required=true)]
api_key_file:Option<PathBuf>,
#[arg(long,group="cookie",required=true)]
cookie_literal:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_envvar:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_file:Option<PathBuf>,
#[arg(long)]
output_folder:Option<PathBuf>,
#[arg(long)]
@ -237,12 +286,12 @@ struct DecompileHistoryIntoGitSubcommand{
struct DownloadAndDecompileHistoryIntoGitSubcommand{
#[arg(long)]
asset_id:AssetID,
#[arg(long,group="api_key",required=true)]
api_key_literal:Option<String>,
#[arg(long,group="api_key",required=true)]
api_key_envvar:Option<String>,
#[arg(long,group="api_key",required=true)]
api_key_file:Option<PathBuf>,
#[arg(long,group="cookie",required=true)]
cookie_literal:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_envvar:Option<String>,
#[arg(long,group="cookie",required=true)]
cookie_file:Option<PathBuf>,
//currently output folder must be the current folder due to git2 limitations
//output_folder:cli.output.unwrap(),
#[arg(long)]
@ -274,6 +323,21 @@ impl Style{
}
}
}
#[derive(Clone,Copy,Debug,clap::ValueEnum)]
enum AssetType{
Audio,
Decal,
Model,
}
impl AssetType{
fn cloud(&self)->rbx_asset::cloud::AssetType{
match self{
AssetType::Audio=>rbx_asset::cloud::AssetType::Audio,
AssetType::Decal=>rbx_asset::cloud::AssetType::Decal,
AssetType::Model=>rbx_asset::cloud::AssetType::Model,
}
}
}
#[tokio::main]
async fn main()->AResult<()>{
@ -308,10 +372,10 @@ async fn main()->AResult<()>{
},
Commands::DownloadDecompile(subcommand)=>{
download_decompile(DownloadDecompileConfig{
api_key:api_key_from_args(
subcommand.api_key_literal,
subcommand.api_key_envvar,
subcommand.api_key_file,
cookie:cookie_from_args(
subcommand.cookie_literal,
subcommand.cookie_envvar,
subcommand.cookie_file,
).await?,
asset_id:subcommand.asset_id,
output_folder:subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
@ -330,7 +394,20 @@ async fn main()->AResult<()>{
subcommand.group,
subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
).await,
Commands::CreateAsset(subcommand)=>create(CreateConfig{
Commands::CreateAsset(subcommand)=>create_asset(CreateAssetConfig{
cookie:cookie_from_args(
subcommand.cookie_literal,
subcommand.cookie_envvar,
subcommand.cookie_file,
).await?,
group:subcommand.group_id,
input_file:subcommand.input_file,
model_name:subcommand.model_name,
description:subcommand.description.unwrap_or_else(||String::with_capacity(0)),
free_model:subcommand.free_model.unwrap_or(false),
allow_comments:subcommand.allow_comments.unwrap_or(false),
}).await,
Commands::CreateAssetMedia(subcommand)=>create_asset_media(CreateAssetMediaConfig{
api_key:api_key_from_args(
subcommand.api_key_literal,
subcommand.api_key_envvar,
@ -339,10 +416,26 @@ async fn main()->AResult<()>{
creator_user_id:subcommand.creator_user_id,
creator_group_id:subcommand.creator_group_id,
input_file:subcommand.input_file,
asset_type:subcommand.asset_type.cloud(),
model_name:subcommand.model_name,
description:subcommand.description.unwrap_or_else(||String::with_capacity(0)),
expected_price:subcommand.expected_price,
}).await,
Commands::UploadAsset(subcommand)=>upload_asset(UploadAssetConfig{
cookie:cookie_from_args(
subcommand.cookie_literal,
subcommand.cookie_envvar,
subcommand.cookie_file,
).await?,
asset_id:subcommand.asset_id,
group_id:subcommand.group_id,
input_file:subcommand.input_file,
change_name:subcommand.change_name,
change_description:subcommand.change_description,
change_free_model:subcommand.change_free_model,
change_allow_comments:subcommand.change_allow_comments,
}).await,
Commands::UploadAssetMedia(subcommand)=>upload_asset_media(UploadAssetMediaConfig{
api_key:api_key_from_args(
subcommand.api_key_literal,
subcommand.api_key_envvar,
@ -371,12 +464,13 @@ async fn main()->AResult<()>{
input_folder:subcommand.input_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
template:subcommand.template,
style:subcommand.style.map(|s|s.rox()),
api_key:api_key_from_args(
subcommand.api_key_literal,
subcommand.api_key_envvar,
subcommand.api_key_file,
cookie:cookie_from_args(
subcommand.cookie_literal,
subcommand.cookie_envvar,
subcommand.cookie_file,
).await?,
asset_id:subcommand.asset_id,
group_id:subcommand.group_id,
}).await,
Commands::CompileUploadPlace(subcommand)=>compile_upload_place(CompileUploadPlaceConfig{
input_folder:subcommand.input_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
@ -411,10 +505,10 @@ async fn main()->AResult<()>{
Commands::DownloadAndDecompileHistoryIntoGit(subcommand)=>download_and_decompile_history_into_git(DownloadAndDecompileHistoryConfig{
git_committer_name:subcommand.git_committer_name,
git_committer_email:subcommand.git_committer_email,
api_key:api_key_from_args(
subcommand.api_key_literal,
subcommand.api_key_envvar,
subcommand.api_key_file,
cookie:cookie_from_args(
subcommand.cookie_literal,
subcommand.cookie_envvar,
subcommand.cookie_file,
).await?,
asset_id:subcommand.asset_id,
output_folder:std::env::current_dir()?,
@ -431,9 +525,9 @@ async fn cookie_from_args(literal:Option<String>,environment:Option<String>,file
(Some(cookie_literal),None,None)=>cookie_literal,
(None,Some(cookie_environment),None)=>std::env::var(cookie_environment)?,
(None,None,Some(cookie_file))=>tokio::fs::read_to_string(cookie_file).await?,
_=>Err(anyhow::Error::msg("Illegal api key argument triple"))?,
_=>Err(anyhow::Error::msg("Illegal cookie argument triple"))?,
};
Ok(Cookie::new(cookie))
Ok(Cookie::new(format!(".ROBLOSECURITY={cookie}")))
}
async fn api_key_from_args(literal:Option<String>,environment:Option<String>,file:Option<PathBuf>)->AResult<ApiKey>{
let api_key=match (literal,environment,file){
@ -445,20 +539,44 @@ async fn api_key_from_args(literal:Option<String>,environment:Option<String>,fil
Ok(ApiKey::new(api_key))
}
struct CreateConfig{
struct CreateAssetConfig{
cookie:Cookie,
model_name:String,
description:String,
input_file:PathBuf,
group:Option<u64>,
free_model:bool,
allow_comments:bool,
}
async fn create_asset(config:CreateAssetConfig)->AResult<()>{
let resp=CookieContext::new(config.cookie)
.create(rbx_asset::cookie::CreateRequest{
name:config.model_name,
description:config.description,
ispublic:config.free_model,
allowComments:config.allow_comments,
groupId:config.group,
},tokio::fs::read(config.input_file).await?).await?;
println!("UploadResponse={:?}",resp);
Ok(())
}
struct CreateAssetMediaConfig{
api_key:ApiKey,
asset_type:rbx_asset::cloud::AssetType,
model_name:String,
description:String,
input_file:PathBuf,
creator_user_id:u64,
creator_group_id:Option<u64>,
expected_price:Option<u64>,
}
///This is hardcoded to create models atm
async fn create(config:CreateConfig)->AResult<()>{
async fn create_asset_media(config:CreateAssetMediaConfig)->AResult<()>{
let resp=CloudContext::new(config.api_key)
.create_asset(rbx_asset::cloud::CreateAssetRequest{
assetType:rbx_asset::cloud::AssetType::Model,
assetType:config.asset_type,
displayName:config.model_name,
description:config.description,
creationContext:rbx_asset::cloud::CreationContext{
@ -466,25 +584,50 @@ async fn create(config:CreateConfig)->AResult<()>{
userId:config.creator_user_id,
groupId:config.creator_group_id.unwrap_or(0),
},
expectedPrice:0,
expectedPrice:config.expected_price.unwrap_or(0),
}
},tokio::fs::read(config.input_file).await?).await?;
println!("CreateResponse={:?}",resp);
Ok(())
}
struct UploadAssetConfig{
cookie:Cookie,
asset_id:AssetID,
change_name:Option<String>,
change_description:Option<String>,
change_free_model:Option<bool>,
change_allow_comments:Option<bool>,
group_id:Option<u64>,
input_file:PathBuf,
}
async fn upload_asset(config:UploadAssetConfig)->AResult<()>{
let context=CookieContext::new(config.cookie);
let resp=context.upload(rbx_asset::cookie::UploadRequest{
assetid:config.asset_id,
name:config.change_name,
description:config.change_description,
ispublic:config.change_free_model,
allowComments:config.change_allow_comments,
groupId:config.group_id,
},tokio::fs::read(config.input_file).await?).await?;
println!("UploadResponse={:?}",resp);
Ok(())
}
struct UploadAssetConfig{
struct UploadAssetMediaConfig{
api_key:ApiKey,
asset_id:u64,
input_file:PathBuf,
}
async fn upload_asset(config:UploadAssetConfig)->AResult<()>{
async fn upload_asset_media(config:UploadAssetMediaConfig)->AResult<()>{
let context=CloudContext::new(config.api_key);
context.update_asset(rbx_asset::cloud::UpdateAssetRequest{
let resp=context.update_asset(rbx_asset::cloud::UpdateAssetRequest{
assetId:config.asset_id,
displayName:None,
description:None,
},tokio::fs::read(config.input_file).await?).await?;
println!("UploadResponse={:?}",resp);
Ok(())
}
@ -531,7 +674,7 @@ async fn get_inventory_pages(context:&CookieContext,group:u64)->AResult<Vec<Inve
let mut cursor:Option<String>=None;
let mut asset_list=Vec::new();
loop{
let mut page=context.inventory_page(rbx_asset::cookie::InventoryPageRequest{group,cursor}).await?;
let mut page=context.get_inventory_page(rbx_asset::cookie::InventoryPageRequest{group,cursor}).await?;
asset_list.append(&mut page.data);
if page.nextPageCursor.is_none(){
break;
@ -552,11 +695,11 @@ async fn download_group_inventory_json(cookie:Cookie,group:u64,output_folder:Pat
Ok(())
}
async fn get_version_history(context:&CloudContext,asset_id:AssetID)->AResult<Vec<AssetVersion>>{
async fn get_version_history(context:&CookieContext,asset_id:AssetID)->AResult<Vec<AssetVersion>>{
let mut cursor:Option<String>=None;
let mut asset_list=Vec::new();
loop{
let mut page=context.get_asset_versions(rbx_asset::cloud::AssetVersionsRequest{asset_id,cursor}).await?;
let mut page=context.get_asset_versions_page(rbx_asset::cookie::AssetVersionsPageRequest{asset_id,cursor}).await?;
asset_list.append(&mut page.data);
if page.nextPageCursor.is_none(){
break;
@ -651,7 +794,7 @@ 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::cloud::GetAssetRequest{asset_id:config.asset_id,version:Some(version_number)}).await?;
let file=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id:config.asset_id,version:Some(version_number)}).await?;
tokio::fs::write(path,file).await?;
@ -746,7 +889,7 @@ async fn decompile(config:DecompileConfig)->AResult<()>{
}
struct DownloadDecompileConfig{
api_key:ApiKey,
cookie:Cookie,
asset_id:AssetID,
style:rox_compiler::Style,
output_folder:PathBuf,
@ -756,8 +899,8 @@ struct DownloadDecompileConfig{
}
async fn download_decompile(config:DownloadDecompileConfig)->AResult<()>{
let context=CloudContext::new(config.api_key);
let file=context.get_asset(rbx_asset::cloud::GetAssetRequest{asset_id:config.asset_id,version:None}).await?;
let context=CookieContext::new(config.cookie);
let file=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 context=rox_compiler::DecompiledContext::from_dom(dom);
@ -914,7 +1057,7 @@ async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{
}
struct DownloadAndDecompileHistoryConfig{
api_key:ApiKey,
cookie:Cookie,
asset_id:AssetID,
git_committer_name:String,
git_committer_email:String,
@ -926,7 +1069,7 @@ struct DownloadAndDecompileHistoryConfig{
}
async fn download_and_decompile_history_into_git(config:DownloadAndDecompileHistoryConfig)->AResult<()>{
let context=CloudContext::new(config.api_key);
let context=CookieContext::new(config.cookie);
//poll paged list of all asset versions
let asset_list=get_version_history(&context,config.asset_id).await?;
@ -939,7 +1082,7 @@ 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::cloud::GetAssetRequest{asset_id,version:Some(asset_version.assetVersionNumber)}).await?;
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))?;
Ok::<_,anyhow::Error>((asset_version,rox_compiler::DecompiledContext::from_dom(dom)))
})
@ -997,7 +1140,8 @@ struct CompileUploadAssetConfig{
input_folder:PathBuf,
template:Option<PathBuf>,
style:Option<rox_compiler::Style>,
api_key:ApiKey,
cookie:Cookie,
group_id:Option<u64>,
asset_id:AssetID,
}
async fn compile_upload_asset(config:CompileUploadAssetConfig)->AResult<()>{
@ -1017,12 +1161,16 @@ async fn compile_upload_asset(config:CompileUploadAssetConfig)->AResult<()>{
rbx_binary::to_writer(std::io::Cursor::new(&mut data),&dom,dom.root().children())?;
//upload it
let context=CloudContext::new(config.api_key);
context.update_asset(rbx_asset::cloud::UpdateAssetRequest{
assetId:config.asset_id,
displayName:None,
let context=CookieContext::new(config.cookie);
let resp=context.upload(rbx_asset::cookie::UploadRequest{
groupId:config.group_id,
assetid:config.asset_id,
name:None,
description:None,
ispublic:None,
allowComments:None,
},data).await?;
println!("UploadResponse={:?}",resp);
Ok(())
}