Skip to content

Commit

Permalink
Formatting, fix rust issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorlias committed Mar 9, 2022
1 parent 4755357 commit e1a6aba
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ fn main() {

fn run(options: Options) -> Result<(), anyhow::Error> {
let auth_cookie = options.auth_cookie.or_else(get_auth_cookie);
let api_key = options.api_key;

match options.subcommand {
Subcommand::Run { script, args } => {
Expand All @@ -97,7 +98,7 @@ fn run(options: Options) -> Result<(), anyhow::Error> {
.map(|value| value.to_lua(context))
.collect::<Result<Vec<_>, _>>()?;

RemodelContext::new(auth_cookie, options.api_key).inject(context)?;
RemodelContext::new(auth_cookie, api_key).inject(context)?;

RemodelApi::inject(context)?;
RobloxApi::inject(context)?;
Expand Down
42 changes: 30 additions & 12 deletions src/remodel_api/remodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ fn xml_decode_options() -> rbx_xml::DecodeOptions {

pub enum UploadPlaceAsset {
Legacy(u64),
CloudAPI {
place_id: u64,
universe_id: u64,
}
CloudAPI { place_id: u64, universe_id: u64 },
}

pub struct Remodel;
Expand Down Expand Up @@ -342,13 +339,24 @@ impl Remodel {

match asset {
UploadPlaceAsset::Legacy(asset_id) => Remodel::upload_asset(context, buffer, asset_id),
UploadPlaceAsset::CloudAPI {place_id, universe_id} => Remodel::cloud_upload_place_asset(context, buffer, universe_id, place_id),
UploadPlaceAsset::CloudAPI {
place_id,
universe_id,
} => Remodel::cloud_upload_place_asset(context, buffer, universe_id, place_id),
}
}

fn cloud_upload_place_asset(context: Context<'_>, buffer: Vec<u8>, universe_id: u64, asset_id: u64) -> rlua::Result<()> {
fn cloud_upload_place_asset(
context: Context<'_>,
buffer: Vec<u8>,
universe_id: u64,
asset_id: u64,
) -> rlua::Result<()> {
let re_context = RemodelContext::get(context)?;
let url = format!("https://apis.roblox.com/universes/v1/{}/places/{}/versions?versionType=Published", universe_id, asset_id);
let url = format!(
"https://apis.roblox.com/universes/v1/{}/places/{}/versions?versionType=Published",
universe_id, asset_id
);

let api_key = re_context.api_key().ok_or_else(|| {
rlua::Error::external(
Expand All @@ -365,13 +373,12 @@ impl Remodel {
client
.post(&url)
.header("x-api-key", api_key)
.header(USER_AGENT, "Roblox/WinInet")
.header(CONTENT_TYPE, "application/xml")
.header(ACCEPT, "application/json")
.body(buffer.clone())
};

log::debug!("Uploading to Roblox...");
log::debug!("Uploading to Roblox Cloud...");
let response = build_request().send().map_err(rlua::Error::external)?;

if response.status().is_success() {
Expand Down Expand Up @@ -545,15 +552,26 @@ impl UserData for Remodel {
|context, (instance, asset_id): (LuaInstance, String)| {
let asset_id = asset_id.parse().map_err(rlua::Error::external)?;

Remodel::write_existing_place_asset(context, instance, UploadPlaceAsset::Legacy(asset_id))
Remodel::write_existing_place_asset(
context,
instance,
UploadPlaceAsset::Legacy(asset_id),
)
},
);

methods.add_function(
"publishPlaceToCloud",
|context, (instance, universe_id, place_id): (LuaInstance, u64, u64)| {
Remodel::write_existing_place_asset(context, instance, UploadPlaceAsset::CloudAPI {universe_id, place_id})
}
Remodel::write_existing_place_asset(
context,
instance,
UploadPlaceAsset::CloudAPI {
universe_id,
place_id,
},
)
},
);

methods.add_function(
Expand Down

0 comments on commit e1a6aba

Please sign in to comment.