mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
Support the new Open Cloud API (#504)
* Add support for the new Open Cloud API * Cleanup Open Cloud variables * Avoid cloning buffer for do_upload_open_cloud * Satisfy cargo fmt * Actually correct cargo fmt Apparently my earlier fix did not fix everything. * Update CHANGELOG.md * Update CHANGELOG.md Forgot to add the link to issue #486 in the previous commit :/ * Cleanup & improve code for open cloud api * Commit to force GH Actions to run (?) Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
# Rojo Changelog
|
# Rojo Changelog
|
||||||
|
|
||||||
## Unreleased Changes
|
## Unreleased Changes
|
||||||
|
* Added support for the new Open Cloud API when uploading. ([#486])
|
||||||
|
|
||||||
## [7.0.0] - December 10, 2021
|
## [7.0.0] - December 10, 2021
|
||||||
* Fixed Rojo's interactions with properties enabled by FFlags that are not yet enabled. ([#493])
|
* Fixed Rojo's interactions with properties enabled by FFlags that are not yet enabled. ([#493])
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
* Connection settings are now remembered when reconnecting in Roblox Studio. ([#500])
|
* Connection settings are now remembered when reconnecting in Roblox Studio. ([#500])
|
||||||
* Updated reflection database to Roblox v503.
|
* Updated reflection database to Roblox v503.
|
||||||
|
|
||||||
|
[#486]: https://github.com/rojo-rbx/rojo/issues/486
|
||||||
[#430]: https://github.com/rojo-rbx/rojo/issues/430
|
[#430]: https://github.com/rojo-rbx/rojo/issues/430
|
||||||
[#493]: https://github.com/rojo-rbx/rojo/pull/493
|
[#493]: https://github.com/rojo-rbx/rojo/pull/493
|
||||||
[#500]: https://github.com/rojo-rbx/rojo/pull/500
|
[#500]: https://github.com/rojo-rbx/rojo/pull/500
|
||||||
@@ -475,4 +477,4 @@ This is a general maintenance release for the Rojo 0.5.x release series.
|
|||||||
* More robust syncing with a new reconciler
|
* More robust syncing with a new reconciler
|
||||||
|
|
||||||
## [0.1.0](https://github.com/rojo-rbx/rojo/releases/tag/v0.1.0) (November 29, 2017)
|
## [0.1.0](https://github.com/rojo-rbx/rojo/releases/tag/v0.1.0) (November 29, 2017)
|
||||||
* Initial release, functionally very similar to [rbxfs](https://github.com/LPGhatguy/rbxfs)
|
* Initial release, functionally very similar to [rbxfs](https://github.com/LPGhatguy/rbxfs)
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ pub struct UploadCommand {
|
|||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
pub cookie: Option<String>,
|
pub cookie: Option<String>,
|
||||||
|
|
||||||
|
/// API key obtained from create.roblox.com/credentials. Rojo will use the Open Cloud API when this is provided. Only supports uploading to a place.
|
||||||
|
#[structopt(long = "api_key")]
|
||||||
|
pub api_key: Option<String>,
|
||||||
|
|
||||||
|
/// The Universe ID of the given place. Required when using the Open Cloud API.
|
||||||
|
#[structopt(long = "universe_id")]
|
||||||
|
pub universe_id: Option<u64>,
|
||||||
|
|
||||||
/// Asset ID to upload to.
|
/// Asset ID to upload to.
|
||||||
#[structopt(long = "asset_id")]
|
#[structopt(long = "asset_id")]
|
||||||
pub asset_id: u64,
|
pub asset_id: u64,
|
||||||
@@ -33,10 +41,6 @@ impl UploadCommand {
|
|||||||
pub fn run(self) -> Result<(), anyhow::Error> {
|
pub fn run(self) -> Result<(), anyhow::Error> {
|
||||||
let project_path = resolve_path(&self.project);
|
let project_path = resolve_path(&self.project);
|
||||||
|
|
||||||
let cookie = self.cookie.or_else(get_auth_cookie).context(
|
|
||||||
"Rojo could not find your Roblox auth cookie. Please pass one via --cookie.",
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let vfs = Vfs::new_default();
|
let vfs = Vfs::new_default();
|
||||||
|
|
||||||
let session = ServeSession::new(vfs, project_path)?;
|
let session = ServeSession::new(vfs, project_path)?;
|
||||||
@@ -54,7 +58,36 @@ impl UploadCommand {
|
|||||||
|
|
||||||
log::trace!("Encoding binary model");
|
log::trace!("Encoding binary model");
|
||||||
rbx_binary::to_writer(&mut buffer, tree.inner(), &encode_ids)?;
|
rbx_binary::to_writer(&mut buffer, tree.inner(), &encode_ids)?;
|
||||||
do_upload(buffer, self.asset_id, &cookie)
|
|
||||||
|
match (self.cookie, self.api_key, self.universe_id) {
|
||||||
|
(cookie, None, universe) => {
|
||||||
|
// using legacy. notify if universe is provided.
|
||||||
|
if universe.is_some() {
|
||||||
|
log::warn!(
|
||||||
|
"--universe_id was provided but is ignored when using legacy upload"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let cookie = cookie.or_else(get_auth_cookie).context(
|
||||||
|
"Rojo could not find your Roblox auth cookie. Please pass one via --cookie.",
|
||||||
|
)?;
|
||||||
|
do_upload(buffer, self.asset_id, &cookie)
|
||||||
|
}
|
||||||
|
|
||||||
|
(cookie, Some(api_key), Some(universe_id)) => {
|
||||||
|
// using open cloud. notify if cookie is provided.
|
||||||
|
if cookie.is_some() {
|
||||||
|
log::warn!("--cookie was provided but is ignored when using Open Cloud API");
|
||||||
|
}
|
||||||
|
|
||||||
|
do_upload_open_cloud(buffer, universe_id, self.asset_id, &api_key)
|
||||||
|
}
|
||||||
|
|
||||||
|
(_, Some(_), None) => {
|
||||||
|
// API key is provided, universe id is not.
|
||||||
|
bail!("--universe_id must be provided to use the Open Cloud API");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,3 +158,38 @@ fn do_upload(buffer: Vec<u8>, asset_id: u64, cookie: &str) -> anyhow::Result<()>
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implementation of do_upload that supports the new open cloud api.
|
||||||
|
/// see https://developer.roblox.com/en-us/articles/open-cloud
|
||||||
|
fn do_upload_open_cloud(
|
||||||
|
buffer: Vec<u8>,
|
||||||
|
universe_id: u64,
|
||||||
|
asset_id: u64,
|
||||||
|
api_key: &str,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
let url = format!(
|
||||||
|
"https://apis.roblox.com/universes/v1/{}/places/{}/versions?versionType=Published",
|
||||||
|
universe_id, asset_id
|
||||||
|
);
|
||||||
|
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
|
log::debug!("Uploading to Roblox...");
|
||||||
|
let mut response = client
|
||||||
|
.post(&url)
|
||||||
|
.header("x-api-key", api_key)
|
||||||
|
.header(CONTENT_TYPE, "application/xml")
|
||||||
|
.header(ACCEPT, "application/json")
|
||||||
|
.body(buffer)
|
||||||
|
.send()?;
|
||||||
|
|
||||||
|
let status = response.status();
|
||||||
|
if !status.is_success() {
|
||||||
|
bail!(
|
||||||
|
"The Roblox API returned an unexpected error: {}",
|
||||||
|
response.text()?
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user