Add cookie header support for Roblox API requests in CloneCommand and StudioCommand

- Introduced a cookie header to the API requests in both `fetch_experience_name` and `get_universe_id` functions, allowing for authenticated requests to the Roblox API.
- Updated the request handling to conditionally include the cookie if available, enhancing the functionality of the commands when interacting with the API.
This commit is contained in:
Joe 2026-02-06 23:00:39 -06:00
parent 8dc050895a
commit 2892d989f8
2 changed files with 22 additions and 5 deletions

View file

@ -4,6 +4,7 @@ use std::process::{Command, Stdio};
use anyhow::{bail, Context};
use clap::Parser;
use reqwest::blocking::Client;
use reqwest::header::COOKIE;
use serde::Deserialize;
use super::init::{InitCommand, InitKind};
@ -131,12 +132,17 @@ struct GameData {
/// Resolves a place ID to its experience name via the Roblox API.
fn fetch_experience_name(place_id: u64) -> anyhow::Result<String> {
let cookie_header = rbx_cookie::get_value().map(|c| format!(".ROBLOSECURITY={}", c));
let client = Client::new();
// Place ID -> Universe ID
let universe_url = format!("https://apis.roblox.com/universes/v1/places/{place_id}/universe");
let universe: UniverseResponse = client
.get(&universe_url)
let mut req = client.get(&universe_url);
if let Some(cookie) = &cookie_header {
req = req.header(COOKIE, cookie);
}
let universe: UniverseResponse = req
.send()
.context("Failed to reach Roblox universe API")?
.json()
@ -147,8 +153,11 @@ fn fetch_experience_name(place_id: u64) -> anyhow::Result<String> {
"https://games.roblox.com/v1/games?universeIds={}",
universe.universe_id
);
let games: GamesResponse = client
.get(&games_url)
let mut req = client.get(&games_url);
if let Some(cookie) = &cookie_header {
req = req.header(COOKIE, cookie);
}
let games: GamesResponse = req
.send()
.context("Failed to reach Roblox games API")?
.json()

View file

@ -5,6 +5,7 @@ use std::process::Command;
use anyhow::Context;
use clap::Parser;
use memofs::Vfs;
use reqwest::header::COOKIE;
use serde::Deserialize;
use crate::project::Project;
@ -66,12 +67,19 @@ impl StudioCommand {
}
fn get_universe_id(place_id: u64) -> anyhow::Result<u64> {
let cookie_header = rbx_cookie::get_value().map(|c| format!(".ROBLOSECURITY={}", c));
let url = format!(
"https://apis.roblox.com/universes/v1/places/{}/universe",
place_id
);
let response: UniverseResponse = reqwest::blocking::get(&url)
let mut req = reqwest::blocking::Client::new().get(&url);
if let Some(cookie) = &cookie_header {
req = req.header(COOKIE, cookie);
}
let response: UniverseResponse = req
.send()
.context("Failed to fetch universe ID from Roblox API")?
.json()
.context("Failed to parse universe ID response")?;