feat: use paste.hep.gg:
All checks were successful
FanslySync Build & Test / FanslySync Test Runner (push) Successful in 13m13s
All checks were successful
FanslySync Build & Test / FanslySync Test Runner (push) Successful in 13m13s
This commit is contained in:
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
@ -109,6 +109,7 @@ dependencies = [
|
||||
"tauri-plugin-notification",
|
||||
"tauri-plugin-os",
|
||||
"tauri-plugin-updater",
|
||||
"thiserror 2.0.12",
|
||||
"tokio",
|
||||
"tokio-macros",
|
||||
]
|
||||
|
@ -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.
|
||||
|
@ -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<String>,
|
||||
payload: PasteData,
|
||||
}
|
||||
|
||||
pub struct Fansly {
|
||||
client: reqwest::Client,
|
||||
token: Option<String>,
|
||||
}
|
||||
|
||||
#[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<String>) -> 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<String, reqwest::Error> {
|
||||
let url = "https://paste.fanslycreatorbot.com";
|
||||
async fn upload_sync_data(&self, data: SyncDataResponse) -> Result<String, UploadError> {
|
||||
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(
|
||||
|
@ -59,7 +59,7 @@
|
||||
"height": 650,
|
||||
"resizable": false,
|
||||
"title": "FanslySync",
|
||||
"width": 600
|
||||
"width": 630
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
|
Reference in New Issue
Block a user