tosho_mplus/constants.rs
1//! Provides constants used in the library.
2//!
3//! All the following structs are a lazy static.
4//!
5//! ```rust
6//! use tosho_mplus::constants::get_constants;
7//!
8//! let _ = get_constants(1); // Android
9//! ```
10
11use std::sync::LazyLock;
12
13use tosho_macros::comptime_b64;
14
15/// A struct containing constants used in the library.
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct Constants {
18 /// The user agent string used for image requests.
19 pub(crate) image_ua: String,
20 /// The user agent string used for API requests.
21 pub(crate) api_ua: String,
22 /// The OS version string used for API requests.
23 pub(crate) os_ver: &'static str,
24 /// The app version string used for API requests.
25 pub(crate) app_ver: &'static str,
26 /// The OS name string used for API requests.
27 pub(crate) os_name: &'static str,
28}
29
30/// The constants used for Android devices.
31pub static ANDROID_CONSTANTS: LazyLock<Constants> = LazyLock::new(|| {
32 Constants {
33 image_ua: "Dalvik/2.1.0 (Linux; U; Android 14; SM-A156E Build/UP1A.231005.007)".to_string(),
34 api_ua: "okhttp/4.9.0".to_string(),
35 os_ver: "34", // Android SDK 14
36 app_ver: "1024",
37 os_name: "android",
38 }
39});
40
41/// The base API used for overall requests.
42pub const BASE_API: &str = comptime_b64!("aHR0cHM6Ly9qdW1wZy1hcGkudG9reW8tY2RuLmNvbS9hcGk=");
43/// The base image URL used for image requests.
44pub const BASE_IMG: &str = comptime_b64!("aHR0cHM6Ly9qdW1wZy1hc3NldHMudG9reW8tY2RuLmNvbQ==");
45
46/// The base host used for overall requests.
47pub const BASE_HOST: &str = comptime_b64!("bWFuZ2FwbHVzLnNodWVpc2hhLmNvLmpw");
48/// The API host used for API requests.
49pub const API_HOST: &str = comptime_b64!("anVtcGctYXBpLnRva3lvLWNkbi5jb20=");
50/// The image host used for image requests.
51pub const IMAGE_HOST: &str = comptime_b64!("anVtcGctYXNzZXRzLnRva3lvLWNkbi5jb20=");
52
53/// Returns the constants for the given device type.
54///
55/// # Arguments
56/// * `device_type` - The device type to get the constants for.
57///
58/// # Available device types
59/// * `1` - Android
60///
61/// # Panics
62/// Panics if the device type is invalid.
63///
64/// # Examples
65/// ```rust
66/// # use tosho_mplus::constants::get_constants;
67/// #
68/// let _ = get_constants(1); // Android
69/// ```
70pub fn get_constants(device_type: u8) -> &'static Constants {
71 match device_type {
72 1 => &ANDROID_CONSTANTS,
73 _ => panic!("Invalid device type"),
74 }
75}