diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 0c92c36..8be0633 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -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" diff --git a/src-tauri/src/handlers/fansly/mod.rs b/src-tauri/src/handlers/fansly/mod.rs index b477746..539bb1e 100644 --- a/src-tauri/src/handlers/fansly/mod.rs +++ b/src-tauri/src/handlers/fansly/mod.rs @@ -162,6 +162,35 @@ impl Fansly { Ok(subscriptions.response.subscriptions) } + async fn upload_sync_data(&self, data: SyncDataResponse) -> Result { + 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 { // 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, }) } } diff --git a/src-tauri/src/structs/mod.rs b/src-tauri/src/structs/mod.rs index 6fe910b..fa37034 100644 --- a/src-tauri/src/structs/mod.rs +++ b/src-tauri/src/structs/mod.rs @@ -5,6 +5,7 @@ use serde_json::Value; pub struct SyncDataResponse { pub followers: Vec, pub subscribers: Vec, + pub sync_data_url: String, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 8b9de80..fe1a8df 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -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": { diff --git a/src/lib/types.ts b/src/lib/types.ts index be7cdae..80150c2 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -10,6 +10,7 @@ export type Config = { export interface SyncData { followers: Follower[]; subscribers: Subscriber[]; + sync_data_url: string; } interface Subscriber { diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 6a785ae..fd4b7a7 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -52,8 +52,6 @@ } status = 'Initialization complete!'; - // Wait 1000ms before redirecting to /setup or /home - await new Promise((resolve) => setTimeout(resolve, 1000)); if (config.is_first_run) { // Navigate to /setup diff --git a/src/routes/home/+page.svelte b/src/routes/home/+page.svelte index e21cb3e..8867172 100644 --- a/src/routes/home/+page.svelte +++ b/src/routes/home/+page.svelte @@ -7,14 +7,23 @@ import { slide } from 'svelte/transition'; import { sendNotification } from '@tauri-apps/api/notification'; import { platform } from '@tauri-apps/api/os'; + import { checkUpdate, installUpdate, type UpdateManifest } from '@tauri-apps/api/updater'; + import { getVersion, getTauriVersion } from '@tauri-apps/api/app'; + import { ask } from '@tauri-apps/api/dialog'; let loadingSync = true; - let syncing = false; + let upToDate: boolean | null = null; + let updateMeta: UpdateManifest | null = null; + let versionData = { + appVersion: 'Loading...', + tauriVersion: 'Loading...' + }; let syncState = { show: false, syncing: false, error: false, success: false, + url: '', message: '' }; @@ -36,6 +45,13 @@ config = configData; loadingSync = false; + + const updateStatus = await checkUpdate(); + upToDate = updateStatus.shouldUpdate; + updateMeta = updateStatus.manifest || null; + + versionData.appVersion = await getVersion(); + versionData.tauriVersion = await getTauriVersion(); }); async function syncNow() { @@ -54,6 +70,8 @@ return; } + syncState.url = syncData.sync_data_url; + // Return the last sync as unix timestamp config!.last_sync = Date.now(); config!.last_sync_data = syncData!; @@ -88,6 +106,24 @@ sound: soundName }); } + + async function doUpdate() { + const confirm = await ask( + `An update is available for FanslySync. Would you like to update now?\n\nCurrent version: ${versionData.appVersion}\nNew (remote) version: ${updateMeta?.version ?? 'Unknown'}`, + { + title: 'Update Available', + okLabel: 'Yes', + cancelLabel: 'No', + type: 'info' + } + ); + + if (confirm) { + await installUpdate(); + } else { + console.log('User declined update'); + } + }
@@ -96,7 +132,20 @@
FanslySynct

FanslySync

- v0.1.0 + v{versionData.appVersion} (runtime: {versionData.tauriVersion}) + {#if upToDate === false} + + {:else if upToDate === true} + Up to date! + {/if}

Sync Successful!

- Data synced successfully. Please run the import with the following link {syncState.message} + Data synced successfully. Please run the import with the following link {syncState.url} to import the data.

@@ -260,7 +309,7 @@