From d7907558df3689faec7c014f8d53e684d11521c7 Mon Sep 17 00:00:00 2001 From: Sticks Date: Tue, 22 Apr 2025 21:01:05 -0400 Subject: [PATCH] feat: use paste.hep.gg: --- src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 1 + src-tauri/src/handlers/fansly/mod.rs | 55 +++++++++++++++++++++------- src-tauri/tauri.conf.json | 2 +- src/routes/home/+page.svelte | 26 ++++++++----- 5 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 19c10ce..61f6b4d 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -109,6 +109,7 @@ dependencies = [ "tauri-plugin-notification", "tauri-plugin-os", "tauri-plugin-updater", + "thiserror 2.0.12", "tokio", "tokio-macros", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index fb4f812..851ac6b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -30,6 +30,7 @@ tauri-plugin-notification = { version = "2.2.1" } tauri-plugin-updater = { version = "2.2.1" } tauri-plugin-log = { version = "2.2.1" } log = "0.4.27" +thiserror = "2.0.12" [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. diff --git a/src-tauri/src/handlers/fansly/mod.rs b/src-tauri/src/handlers/fansly/mod.rs index 1cbedb2..760106c 100644 --- a/src-tauri/src/handlers/fansly/mod.rs +++ b/src-tauri/src/handlers/fansly/mod.rs @@ -10,6 +10,7 @@ use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT}; use serde::{Deserialize, Serialize}; use serde_json::Value; use tokio::sync::Mutex; +use thiserror::Error; // Create a PROGRESS mutex to hold the current sync progress, lazy initialized lazy_static! { @@ -26,11 +27,32 @@ pub struct SyncProgress { pub complete: bool, } +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct PasteData { + id: String, + content: String, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct PasteResponse { + error: Option, + payload: PasteData, +} + pub struct Fansly { client: reqwest::Client, token: Option, } +#[derive(Debug, Error)] +pub enum UploadError { + #[error("HTTP error: {0}")] + Http(#[from] reqwest::Error), + + #[error("Failed to get UUID from paste.hep.gg URL")] + MissingUuid, +} + impl Fansly { pub fn new(token: Option) -> Self { let mut headers = HeaderMap::new(); @@ -38,7 +60,7 @@ impl Fansly { // Set the user agent to the FanslySync/0.1.0 tanner@fanslycreatorbot.com headers.insert( USER_AGENT, - HeaderValue::from_static("FanslySync/0.1.0 tanner@fanslycreatorbot.com"), + HeaderValue::from_static("FanslySync/0.1.0 tanner@fanslycreatorbot.com"), // this sucks, oh well ); // If we have a token, add it to the headers\ @@ -209,20 +231,14 @@ impl Fansly { } - async fn upload_sync_data(&self, data: SyncDataResponse) -> Result { - let url = "https://paste.fanslycreatorbot.com"; + async fn upload_sync_data(&self, data: SyncDataResponse) -> Result { + let url = "https://paste.hep.gg/"; // 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")?, - ); + .text("content", json_string); // Create a new client and POST let response = self @@ -235,12 +251,23 @@ impl Fansly { if !response.status().is_success() { log::error!("Failed to upload sync data..."); log::info!("Response: {:?}", response); - return Err(response.error_for_status().unwrap_err()); + return Err(UploadError::from(response.error_for_status().unwrap_err())); } - let reply = response.text().await?; - log::info!("Uploaded sync data successfully. Response: {}", reply); - Ok(reply) + log::info!("Uploaded sync data successfully."); + + // Get the response URL from the response + let url = response.url(); + + // Grab the UUID from the URL + let uuid = url.path_segments() + .and_then(|segments| segments.last()) + .ok_or(UploadError::MissingUuid)?; + + log::info!("Sync data uploaded to paste.hep.gg with UUID: {}", uuid); + + // Return the URL of the uploaded data + Ok(format!("https://paste.hep.gg/api/{}/raw", uuid)) } pub async fn upload_auto_sync_data( diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 113f90a..504fbb0 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -59,7 +59,7 @@ "height": 650, "resizable": false, "title": "FanslySync", - "width": 600 + "width": 630 } ], "security": { diff --git a/src/routes/home/+page.svelte b/src/routes/home/+page.svelte index 6bb8b83..3d9c3cf 100644 --- a/src/routes/home/+page.svelte +++ b/src/routes/home/+page.svelte @@ -837,13 +837,22 @@ {#if syncState.show}
-
+
+ +
+ +
{#if !syncState.success && !syncState.error} {:else if syncState.success} -
+

Sync Successful!

- Data synced successfully. Please run the import with the following link {syncState.url} - to import the data. + Data synced successfully. Use the copy button to copy the sync URL to your clipboard.

@@ -900,7 +908,7 @@
{:else} -
+

Sync Failed!

An error occurred while syncing your data. Details: {syncState.message}