use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Region {
#[default]
Global,
Cn,
Test,
}
impl Region {
pub fn openapi_base(self) -> &'static str {
match self {
Region::Global => "https://openapi-g.insta360.com",
Region::Cn => "https://openapi.insta360.com",
Region::Test => "https://openapi-test.insta360.com",
}
}
pub fn cloud_base(self) -> &'static str {
match self {
Region::Global => "https://service-fra.insta360.com",
Region::Cn => "https://service.insta360.com",
Region::Test => "https://service-test.insta360.com",
}
}
pub fn mainland_flag(self) -> &'static str {
match self {
Region::Cn => "1",
_ => "0",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Platform {
Windows,
Android,
}
impl Platform {
pub fn header_value(self) -> &'static str {
match self {
Platform::Windows => "pc/windows",
Platform::Android => "android",
}
}
}
impl fmt::Display for Platform {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.header_value())
}
}
#[derive(Debug, Clone)]
pub struct ClientConfig {
pub region: Region,
pub platform: Platform,
pub app_version: String,
pub app_id: String,
pub app_traffic: String,
pub client_id: String,
pub app_key: String,
pub equipment_code: String,
pub language: String,
pub sign_key: String,
pub user_agent: String,
}
impl ClientConfig {
pub fn windows(region: Region) -> Self {
ClientConfig {
region,
platform: Platform::Windows,
app_version: "6.0.2".to_string(),
app_id: "studio_win".to_string(),
app_traffic: "release".to_string(),
client_id: String::new(),
app_key: String::new(),
equipment_code: String::new(),
language: "en".to_string(),
sign_key: String::new(),
user_agent: "insta360/studio".to_string(),
}
}
pub fn can_sign(&self) -> bool {
!self.app_key.is_empty() && !self.sign_key.is_empty()
}
}