format, use logging properly, restrict runtime.log to 5mb, bump versions, update framework
This commit is contained in:
@ -2,16 +2,16 @@ use crate::handlers::config::{get_config_path, Config};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn init_config() -> Result<(), String> {
|
||||
println!("[commands::config::init_config] Initializing config...");
|
||||
log::info!("[commands::config::init_config] Initializing config...");
|
||||
let config_path = get_config_path().map_err(|e| e.to_string())?;
|
||||
|
||||
println!(
|
||||
log::info!(
|
||||
"[commands::config::init_config] Config path: {}",
|
||||
config_path.display()
|
||||
);
|
||||
|
||||
Config::load_or_create(&config_path).map_err(|e| e.to_string())?;
|
||||
println!("[commands::config::init_config] Config initialized successfully");
|
||||
log::info!("[commands::config::init_config] Config initialized successfully");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ pub fn get_config() -> Result<Config, String> {
|
||||
let config_path = get_config_path().map_err(|e| e.to_string())?;
|
||||
let config = Config::load_or_create(&config_path).map_err(|e| e.to_string())?;
|
||||
|
||||
println!(
|
||||
log::info!(
|
||||
"[commands::config::get_config] Config loaded successfully: {:?} from path: {}",
|
||||
config,
|
||||
config_path.display()
|
||||
@ -32,7 +32,7 @@ pub fn get_config() -> Result<Config, String> {
|
||||
#[tauri::command]
|
||||
pub fn save_config(config: Config) -> Result<(), String> {
|
||||
let config_path = get_config_path().map_err(|e| e.to_string())?;
|
||||
println!(
|
||||
log::info!(
|
||||
"[commands::config::save_config] Saving config: {:?} to path: {}",
|
||||
config,
|
||||
config_path.display()
|
||||
|
@ -55,15 +55,15 @@ impl Config {
|
||||
let config_raw = std::fs::read_to_string(path)?;
|
||||
let config_json: serde_json::Value = serde_json::from_str(&config_raw)?;
|
||||
|
||||
println!("[config::migrate] Migrating config file to latest version...");
|
||||
println!(
|
||||
log::info!("[config::migrate] Migrating config file to latest version...");
|
||||
log::debug!(
|
||||
"[config::migrate] [DEBUG] config is_object: {}",
|
||||
config_json.is_object()
|
||||
);
|
||||
|
||||
// Check if the JSON object is valid, if not, return an error
|
||||
if !config_json.is_object() {
|
||||
println!(
|
||||
log::error!(
|
||||
"[config::migrate] [ERROR] Found invalid JSON object in config file"
|
||||
);
|
||||
return Err(io::Error::new(
|
||||
@ -77,7 +77,7 @@ impl Config {
|
||||
|
||||
// Check if the version field is a valid integer, if not, return an error
|
||||
if version == 0 {
|
||||
println!(
|
||||
log::error!(
|
||||
"[config::migrate] [ERROR] Found invalid version field in config JSON"
|
||||
);
|
||||
return Err(io::Error::new(
|
||||
@ -86,7 +86,7 @@ impl Config {
|
||||
));
|
||||
}
|
||||
|
||||
println!(
|
||||
log::info!(
|
||||
"[config::migrate] Found version field in config JSON: {}",
|
||||
version
|
||||
);
|
||||
@ -110,7 +110,7 @@ impl Config {
|
||||
config = config.migrate()?;
|
||||
config.save(path)?;
|
||||
|
||||
println!(
|
||||
log::info!(
|
||||
"[config::migrate] Successfully migrated config file to latest version"
|
||||
);
|
||||
// Recursively call load_or_create to load the migrated config
|
||||
|
@ -154,15 +154,16 @@ impl Fansly {
|
||||
let response = self.client.get(url).headers(headers).send().await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
eprintln!("[fanslySyncExt] No successful response from API. Setting error state.");
|
||||
log::error!("[sync::process::fetch_subscribers] No successful response from API. Setting error state.");
|
||||
let error = response.error_for_status().unwrap_err();
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
let subscriptions: FanslyBaseResponse<FanslySubscriptionsResponse> =
|
||||
response.json().await?;
|
||||
println!(
|
||||
"[fanslySyncExt] Got {} subscriptions from API.",
|
||||
|
||||
log::info!(
|
||||
"[sync::process::fetch_subscribers] Got {} subscribers from API.",
|
||||
subscriptions.response.subscriptions.len()
|
||||
);
|
||||
|
||||
@ -170,32 +171,37 @@ impl Fansly {
|
||||
}
|
||||
|
||||
async fn upload_sync_data(&self, data: SyncDataResponse) -> Result<String, reqwest::Error> {
|
||||
let url = "https://paste.hep.gg/documents";
|
||||
let url = "https://paste.fanslycreatorbot.com";
|
||||
|
||||
// Set our content type to application/json
|
||||
let mut headers = reqwest::header::HeaderMap::new();
|
||||
headers.insert(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/json".parse().unwrap(),
|
||||
);
|
||||
// Convert passed data to bytes
|
||||
let json_string = serde_json::to_string(&data).unwrap();
|
||||
let data_as_bytes = json_string.as_bytes();
|
||||
|
||||
let form = reqwest::multipart::Form::new()
|
||||
.part(
|
||||
"file",
|
||||
reqwest::multipart::Part::bytes(data_as_bytes.to_vec())
|
||||
.file_name("sync_data.json")
|
||||
.mime_str("application/json")?,
|
||||
);
|
||||
|
||||
// Create a new client and POST
|
||||
let response = self
|
||||
.client
|
||||
.post(url)
|
||||
.headers(headers)
|
||||
.json(&data)
|
||||
.multipart(form)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
eprintln!("[sync::process::upload_sync_data] Failed to upload sync data.");
|
||||
log::error!("Failed to upload sync data...");
|
||||
log::info!("Response: {:?}", response);
|
||||
return Err(response.error_for_status().unwrap_err());
|
||||
}
|
||||
|
||||
let json: serde_json::Value = response.json().await?;
|
||||
let key = json["key"].as_str().unwrap();
|
||||
|
||||
Ok(format!("https://paste.hep.gg/{}", key))
|
||||
let reply = response.text().await?;
|
||||
log::info!("Uploaded sync data successfully. Response: {}", reply);
|
||||
Ok(reply)
|
||||
}
|
||||
|
||||
pub async fn upload_auto_sync_data(
|
||||
@ -224,10 +230,12 @@ impl Fansly {
|
||||
.await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
eprintln!("[sync::process::upload_auto_sync_data] Failed to upload sync data.");
|
||||
log::error!("Failed to upload sync data...");
|
||||
log::info!("Response: {:?}", response);
|
||||
return Err(response.error_for_status().unwrap_err());
|
||||
}
|
||||
|
||||
log::info!("Uploaded sync data successfully.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -253,7 +261,8 @@ impl Fansly {
|
||||
match response {
|
||||
Ok(response) => {
|
||||
if !response.status().is_success() {
|
||||
eprintln!("[sync::process::check_sync_token] Failed to check sync token.");
|
||||
log::error!("Failed to check sync token...");
|
||||
log::info!("Response: {:?}", response);
|
||||
return Err(response.error_for_status().unwrap_err());
|
||||
}
|
||||
|
||||
@ -266,34 +275,32 @@ impl Fansly {
|
||||
|
||||
pub async fn sync(&self, auto: bool) -> Result<SyncDataResponse, String> {
|
||||
// Fetch profile
|
||||
println!("[sync::process] Fetching profile...");
|
||||
log::info!("[sync::process] Fetching profile...");
|
||||
let profile = self.get_profile().await.map_err(|e| e.to_string())?;
|
||||
|
||||
if !profile.success {
|
||||
return Err("Failed to fetch profile".to_string());
|
||||
}
|
||||
|
||||
println!("[sync::process] Profile retrieved successfully.");
|
||||
log::info!("[sync::process] Syncing profile...");
|
||||
|
||||
let account = profile.response.account;
|
||||
let total_followers = account.follow_count;
|
||||
let total_subscribers = account.subscriber_count;
|
||||
|
||||
println!(
|
||||
"[sync::process] Account {} has {} followers and {} subscribers. Starting sync...",
|
||||
account.id, total_followers, total_subscribers
|
||||
);
|
||||
log::info!("[sync::process] Account ID: {}, Followers: {}, Subscribers: {}",
|
||||
account.id, total_followers, total_subscribers);
|
||||
|
||||
let mut followers: Vec<FanslyFollowersResponse> = Vec::new();
|
||||
let mut subscribers: Vec<Subscription> = Vec::new();
|
||||
|
||||
println!("[sync::process] Fetching followers and subscribers...");
|
||||
log::info!("[sync::process] Fetching followers...");
|
||||
|
||||
// Fetch followers until we have all of them
|
||||
let mut offset = 0;
|
||||
let mut total_requests = 0;
|
||||
while followers.len() < total_followers as usize {
|
||||
println!(
|
||||
log::info!(
|
||||
"[sync::process] Fetching followers for account {} with offset {} (total: {})",
|
||||
account.id, offset, total_followers
|
||||
);
|
||||
@ -302,7 +309,7 @@ impl Fansly {
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
println!(
|
||||
log::info!(
|
||||
"[sync::process] Got {} followers from API.",
|
||||
response.response.len()
|
||||
);
|
||||
@ -319,7 +326,7 @@ impl Fansly {
|
||||
// Fetch subscribers until we have all of them
|
||||
offset = 0;
|
||||
while subscribers.len() < total_subscribers as usize {
|
||||
println!(
|
||||
log::info!(
|
||||
"[sync::process] Fetching subscribers with offset {} for account {} (total: {})",
|
||||
offset, account.id, total_subscribers
|
||||
);
|
||||
@ -339,14 +346,14 @@ impl Fansly {
|
||||
}
|
||||
}
|
||||
|
||||
println!(
|
||||
log::info!(
|
||||
"[sync::process] Got {} followers and {} subscribers from API.",
|
||||
followers.len(),
|
||||
subscribers.len()
|
||||
);
|
||||
|
||||
println!("[sync::process] Sync complete.");
|
||||
println!("[sync::process] Uploading sync data to paste.hep.gg for processing...");
|
||||
log::info!("[sync::process] Sync complete.");
|
||||
log::info!("[sync::process] Uploading sync data to paste.hep.gg for processing...");
|
||||
|
||||
// Upload sync data to paste.hep.gg
|
||||
if !auto {
|
||||
|
@ -39,7 +39,6 @@ async fn main() {
|
||||
MacosLauncher::LaunchAgent,
|
||||
None,
|
||||
))
|
||||
.plugin(tauri_plugin_log::Builder::new().build())
|
||||
.plugin(tauri_plugin_notification::init())
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
@ -54,6 +53,8 @@ async fn main() {
|
||||
}),
|
||||
Target::new(TargetKind::Webview),
|
||||
])
|
||||
.rotation_strategy(tauri_plugin_log::RotationStrategy::KeepOne)
|
||||
.max_file_size(1024 * 1024 * 5)
|
||||
.build(),
|
||||
)
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
|
@ -107,7 +107,6 @@ pub struct Account {
|
||||
pub post_likes: i64,
|
||||
pub streaming: Streaming,
|
||||
pub account_media_likes: i64,
|
||||
pub earnings_wallet: EarningsWallet,
|
||||
pub subscription_tiers: Vec<SubscriptionTier>,
|
||||
pub profile_access: bool,
|
||||
}
|
||||
@ -156,18 +155,6 @@ pub struct Streaming {
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EarningsWallet {
|
||||
pub id: String,
|
||||
pub account_id: String,
|
||||
pub balance: i64,
|
||||
#[serde(rename = "type")]
|
||||
pub type_field: i64,
|
||||
pub wallet_version: i64,
|
||||
pub flags: i64,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SubscriptionTier {
|
||||
|
Reference in New Issue
Block a user