add uploading

This commit is contained in:
2024-07-25 21:27:07 -05:00
parent c6ef195be7
commit a3ae877972
7 changed files with 102 additions and 9 deletions

View File

@ -17,7 +17,7 @@ tauri-build = { version = "1.5.3", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.7.0", features = [ "updater", "os-all", "notification-all", "dialog-confirm", "clipboard-all", "dialog-message", "dialog-ask"] }
tauri = { version = "1.7.0", features = [ "app-all", "updater", "os-all", "notification-all", "dialog-confirm", "clipboard-all", "dialog-message", "dialog-ask"] }
dirs = "5.0.1"
reqwest = { version = "0.11.18", features = ["json"] }
lazy_static = "1.5.0"

View File

@ -162,6 +162,35 @@ impl Fansly {
Ok(subscriptions.response.subscriptions)
}
async fn upload_sync_data(&self, data: SyncDataResponse) -> Result<String, reqwest::Error> {
let url = "https://paste.hep.gg/documents";
// Set our content type to application/json
let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
reqwest::header::CONTENT_TYPE,
"application/json".parse().unwrap(),
);
let response = self
.client
.post(url)
.headers(headers)
.json(&data)
.send()
.await?;
if !response.status().is_success() {
eprintln!("[sync::process::upload_sync_data] Failed to upload sync data.");
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))
}
pub async fn sync(&self) -> Result<SyncDataResponse, String> {
// Fetch profile
println!("[sync::process] Fetching profile...");
@ -244,11 +273,23 @@ impl Fansly {
);
println!("[sync::process] Sync complete.");
println!("[sync::process] Uploading sync data to paste.hep.gg for processing...");
// Upload sync data to paste.hep.gg
let paste_url = self
.upload_sync_data(SyncDataResponse {
followers: followers.clone(),
subscribers: subscribers.clone(),
sync_data_url: "".to_string(),
})
.await
.map_err(|e| e.to_string())?;
// Return JSON of what we fetched
Ok(SyncDataResponse {
followers,
subscribers,
sync_data_url: paste_url,
})
}
}

View File

@ -5,6 +5,7 @@ use serde_json::Value;
pub struct SyncDataResponse {
pub followers: Vec<FanslyFollowersResponse>,
pub subscribers: Vec<Subscription>,
pub sync_data_url: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]

View File

@ -7,8 +7,8 @@
"distDir": "../build"
},
"package": {
"productName": "fanslysync-desktop",
"version": "0.1.0"
"productName": "FanslySync",
"version": "0.1.1"
},
"tauri": {
"allowlist": {
@ -30,6 +30,9 @@
},
"os": {
"all": true
},
"app": {
"all": true
}
},
"bundle": {