Skip to content

Commit 5b8fe3b

Browse files
migrate to open cloud
1 parent ea0d23d commit 5b8fe3b

10 files changed

+1692
-1009
lines changed

Cargo.lock

+1,302-863
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "tarmac"
33
description = "Resource compiler and asset manager for Roblox projects"
4-
version = "0.7.0"
4+
version = "0.8.0"
55
authors = ["Lucien Greathouse <[email protected]>"]
66
edition = "2018"
77
license = "MIT"
@@ -19,15 +19,9 @@ panic = "abort"
1919
panic = "abort"
2020

2121
[workspace]
22-
members = [
23-
".",
24-
"packos",
25-
]
26-
27-
default-members = [
28-
".",
29-
"packos",
30-
]
22+
members = [".", "packos"]
23+
24+
default-members = [".", "packos"]
3125

3226
[dependencies]
3327
packos = { path = "packos", version = "0.1.0" }

src/commands/create_cache_map.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ use fs_err as fs;
77
use crate::asset_name::AssetName;
88
use crate::data::Manifest;
99
use crate::options::{CreateCacheMapOptions, GlobalOptions};
10-
use crate::roblox_web_api::RobloxApiClient;
10+
use crate::roblox_web_api::{RobloxApiClient, RobloxOpenCloudCredentials};
1111

1212
pub fn create_cache_map(
1313
global: GlobalOptions,
1414
options: CreateCacheMapOptions,
1515
) -> anyhow::Result<()> {
16-
let mut api_client = RobloxApiClient::new(global.auth);
16+
let credentials = RobloxOpenCloudCredentials::get_credentials(global.auth, global.api_key)?;
17+
let mut api_client = RobloxApiClient::new(credentials);
1718

1819
let project_path = match options.project_path {
1920
Some(path) => path.clone(),

src/commands/sync.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ use walkdir::WalkDir;
1414
use crate::{
1515
alpha_bleed::alpha_bleed,
1616
asset_name::AssetName,
17-
auth_cookie::get_auth_cookie,
1817
codegen::perform_codegen,
1918
data::{Config, ConfigError, ImageSlice, InputManifest, Manifest, ManifestError, SyncInput},
2019
dpi_scale,
2120
image::Image,
2221
options::{GlobalOptions, SyncOptions, SyncTarget},
23-
roblox_web_api::{RobloxApiClient, RobloxApiError},
22+
roblox_web_api::{RobloxApiClient, RobloxApiError, RobloxOpenCloudCredentials},
23+
roblox_web_api_types::RobloxAuthenticationError,
2424
sync_backend::{
2525
DebugSyncBackend, Error as SyncBackendError, NoneSyncBackend, RetryBackend,
2626
RobloxSyncBackend, SyncBackend, UploadInfo,
@@ -43,7 +43,8 @@ pub fn sync(global: GlobalOptions, options: SyncOptions) -> Result<(), SyncError
4343
None => env::current_dir()?,
4444
};
4545

46-
let mut api_client = RobloxApiClient::new(global.auth.or_else(get_auth_cookie));
46+
let credentials = RobloxOpenCloudCredentials::get_credentials(global.auth, global.api_key)?;
47+
let mut api_client = RobloxApiClient::new(credentials);
4748

4849
let mut session = SyncSession::new(&fuzzy_config_path)?;
4950

@@ -753,6 +754,12 @@ pub enum SyncError {
753754
#[from]
754755
source: RobloxApiError,
755756
},
757+
758+
#[error(transparent)]
759+
RobloxAuthenticationError {
760+
#[from]
761+
source: RobloxAuthenticationError,
762+
},
756763
}
757764

758765
impl SyncError {

src/commands/upload_image.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
use std::borrow::Cow;
2-
1+
use anyhow::Ok;
32
use fs_err as fs;
43

54
use crate::{
6-
auth_cookie::get_auth_cookie,
75
options::{GlobalOptions, UploadImageOptions},
8-
roblox_web_api::{ImageUploadData, RobloxApiClient},
6+
roblox_web_api::{RobloxApiClient, RobloxOpenCloudCredentials, DECAL},
7+
roblox_web_api_types::{ImageUploadData, ImageUploadMetadata},
98
};
109

11-
pub fn upload_image(global: GlobalOptions, options: UploadImageOptions) {
12-
let auth = global
13-
.auth
14-
.clone()
15-
.or_else(get_auth_cookie)
16-
.expect("no auth cookie found");
17-
10+
pub fn upload_image(
11+
global: GlobalOptions,
12+
options: UploadImageOptions,
13+
) -> Result<(), anyhow::Error> {
1814
let image_data = fs::read(options.path).expect("couldn't read input file");
15+
let credentials = RobloxOpenCloudCredentials::get_credentials(global.auth, global.api_key)?;
1916

20-
let mut client = RobloxApiClient::new(Some(auth));
17+
let mut client = RobloxApiClient::new(credentials);
2118

2219
let upload_data = ImageUploadData {
23-
image_data: Cow::Owned(image_data),
24-
name: &options.name,
25-
description: &options.description,
26-
group_id: None,
20+
image_data: image_data.into(),
21+
image_metadata: ImageUploadMetadata::new(
22+
DECAL.to_string(),
23+
options.name.to_string(),
24+
options.description.to_string(),
25+
options.user_id,
26+
options.group_id,
27+
)?,
2728
};
2829

29-
let response = client
30-
.upload_image(upload_data)
31-
.expect("Roblox API request failed");
30+
let response = client.upload_image(upload_data)?;
3231

3332
eprintln!("Image uploaded successfully!");
34-
println!("{}", response.backing_asset_id);
33+
println!("{}", response.asset_id);
34+
Ok(())
3535
}

src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ mod image;
1010
mod lua_ast;
1111
mod options;
1212
mod roblox_web_api;
13+
mod roblox_web_api_types;
1314
mod sync_backend;
14-
1515
use std::{env, panic, process};
1616

1717
use backtrace::Backtrace;
@@ -22,7 +22,7 @@ use crate::options::{Options, Subcommand};
2222
fn run(options: Options) -> Result<(), anyhow::Error> {
2323
match options.command {
2424
Subcommand::UploadImage(upload_options) => {
25-
commands::upload_image(options.global, upload_options)
25+
commands::upload_image(options.global, upload_options)?
2626
}
2727
Subcommand::Sync(sync_options) => commands::sync(options.global, sync_options)?,
2828
Subcommand::CreateCacheMap(sub_options) => {

src/options.rs

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub struct GlobalOptions {
2020
#[structopt(long, global(true))]
2121
pub auth: Option<String>,
2222

23+
/// The Open Cloud API key tarmac will use to upload assets.
24+
#[structopt(long, global(true))]
25+
pub api_key: Option<String>,
26+
2327
/// Sets verbosity level. Can be specified multiple times.
2428
#[structopt(long = "verbose", short, global(true), parse(from_occurrences))]
2529
pub verbosity: u8,
@@ -54,6 +58,14 @@ pub struct UploadImageOptions {
5458
/// The description to give to the resulting Decal asset.
5559
#[structopt(long, default_value = "Uploaded by Tarmac.")]
5660
pub description: String,
61+
62+
/// The ID of the user to upload to. Not compatible with `group_id`.
63+
#[structopt(long)]
64+
pub group_id: Option<u64>,
65+
66+
/// The ID of the group to upload to. Not compatible with `user_id`.
67+
#[structopt(long)]
68+
pub user_id: Option<u64>,
5769
}
5870

5971
#[derive(Debug, StructOpt)]

0 commit comments

Comments
 (0)