From 6e47f69141c21b54683506ab1db3cef3534bf457 Mon Sep 17 00:00:00 2001 From: Alvin-Zilverstand <524715@vistacollege.nl> Date: Wed, 9 Sep 2026 15:25:48 +0200 Subject: [PATCH] Add upload provider selection --- src-tauri/src/main.rs | 44 ++++++++++++++++++++++++++----------- ui/src/main.ts | 50 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 18 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index aaebbc5..c42fb1d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -17,7 +17,9 @@ use clipforge::models::{Clip, ClipSource, GameEvent, RecordingStatus}; use clipforge::recorder::{RecorderAction, RecorderService}; use clipforge::settings::{load_or_create_settings, save_settings}; use clipforge::storage::{clip_path, is_inside_root, LibraryPaths}; -use clipforge::upload::{CatboxUploader, UploadMetadata, Uploader}; +use clipforge::upload::{ + CatboxUploader, CustomHttpUploader, LitterboxUploader, UploadMetadata, Uploader, +}; use serde::Serialize; use std::env; use std::fs; @@ -537,7 +539,13 @@ fn trim_clip( } #[tauri::command] -fn upload_clip(clip_id: String, runtime: State<'_, AppRuntime>) -> Result { +fn upload_clip( + clip_id: String, + provider: Option, + custom_endpoint: Option, + custom_response_url_path: Option, + runtime: State<'_, AppRuntime>, +) -> Result { let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?; let clip = recorder .library @@ -549,17 +557,27 @@ fn upload_clip(clip_id: String, runtime: State<'_, AppRuntime>) -> Result CatboxUploader::default().upload(&clip.path, &metadata), + "litterbox" => LitterboxUploader::default().upload(&clip.path, &metadata), + "custom_http" => CustomHttpUploader { + endpoint: custom_endpoint.unwrap_or_default(), + method: "POST".to_string(), + multipart_field: "file".to_string(), + response_url_path: custom_response_url_path.unwrap_or_else(|| "url".to_string()), + headers: Vec::new(), + } + .upload(&clip.path, &metadata), + unknown => { + return Err(format!("Unsupported upload provider: {unknown}")); + } + } + .map_err(|error| error.to_string())?; if !recorder .library .update_upload(&clip_id, result.provider, result.url) diff --git a/ui/src/main.ts b/ui/src/main.ts index ba361f2..03e42f0 100644 --- a/ui/src/main.ts +++ b/ui/src/main.ts @@ -77,6 +77,9 @@ type AppState = { ffmpegPath: string | null; micEnabled: boolean; autoUpload: boolean; + uploadProvider: "catbox" | "litterbox" | "custom_http" | "lustful"; + customUploadEndpoint: string; + customUploadResponsePath: string; selectedClipId: string; clips: Clip[]; autoEvents: AutoEvent[]; @@ -109,6 +112,9 @@ const state: AppState = { ffmpegPath: null, micEnabled: false, autoUpload: false, + uploadProvider: "catbox", + customUploadEndpoint: "", + customUploadResponsePath: "url", selectedClipId: "clip-1", clips: [ { @@ -398,16 +404,30 @@ function renderAutoClipView() { } function renderUploadsView() { + const providers: Array<{ id: AppState["uploadProvider"]; title: string; body: string }> = [ + { id: "catbox", title: "Catbox", body: "Anonymous or userhash-backed permanent uploads." }, + { id: "litterbox", title: "Litterbox", body: "Temporary uploads with a 24 hour default expiry." }, + { id: "custom_http", title: "Custom HTTP", body: "POST multipart clip files to your own endpoint." }, + { id: "lustful", title: "Lustful", body: "Blocked until API details are confirmed." }, + ]; return `
- ${["Catbox", "Litterbox", "Custom HTTP", "Lustful"].map((provider) => ` + ${providers.map((provider) => `

Provider

-

${provider}

-

${provider === "Lustful" ? "Stubbed until API details are confirmed." : "Optional; local clips remain available if upload fails."}

- +

${provider.title}

+

${provider.body}

+
`).join("")} +
+

Custom HTTP

+

Endpoint

+ + +
`; } @@ -492,6 +512,21 @@ function bindEvents() { render(); }); + appRoot.querySelectorAll("[data-upload-provider]").forEach((button) => { + button.addEventListener("click", () => { + state.uploadProvider = button.dataset.uploadProvider as AppState["uploadProvider"]; + render(); + }); + }); + + appRoot.querySelector("[data-action='custom-upload-endpoint']")?.addEventListener("input", (event) => { + state.customUploadEndpoint = (event.target as HTMLInputElement).value; + }); + + appRoot.querySelector("[data-action='custom-upload-response-path']")?.addEventListener("input", (event) => { + state.customUploadResponsePath = (event.target as HTMLInputElement).value; + }); + appRoot.querySelectorAll("[data-event-id]").forEach((input) => { input.addEventListener("change", () => { const eventRule = state.autoEvents.find((event) => event.id === input.dataset.eventId); @@ -623,7 +658,12 @@ async function uploadSelectedClip() { } try { - const dto = await tauriInvoke("upload_clip", { clipId: state.selectedClipId }); + const dto = await tauriInvoke("upload_clip", { + clipId: state.selectedClipId, + provider: state.uploadProvider, + customEndpoint: state.customUploadEndpoint, + customResponseUrlPath: state.customUploadResponsePath, + }); const updated = clipFromDto(dto); state.clips = state.clips.map((clip) => (clip.id === updated.id ? updated : clip)); render();