Add upload provider selection

This commit is contained in:
Alvin-Zilverstand committed 2026-09-09 15:25:48 +02:00
1 parent 885e3d9665
commit 6e47f69141
2 files changed
+76 -18

No files matched your search

+31 -13
View File
@@ -17,7 +17,9 @@ use clipforge::models::{Clip, ClipSource, GameEvent, RecordingStatus};
use clipforge::recorder::{RecorderAction, RecorderService}; use clipforge::recorder::{RecorderAction, RecorderService};
use clipforge::settings::{load_or_create_settings, save_settings}; use clipforge::settings::{load_or_create_settings, save_settings};
use clipforge::storage::{clip_path, is_inside_root, LibraryPaths}; 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 serde::Serialize;
use std::env; use std::env;
use std::fs; use std::fs;
@@ -537,7 +539,13 @@ fn trim_clip(
} }
#[tauri::command] #[tauri::command]
fn upload_clip(clip_id: String, runtime: State<'_, AppRuntime>) -> Result<ClipDto, String> { fn upload_clip(
clip_id: String,
provider: Option<String>,
custom_endpoint: Option<String>,
custom_response_url_path: Option<String>,
runtime: State<'_, AppRuntime>,
) -> Result<ClipDto, String> {
let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?; let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
let clip = recorder let clip = recorder
.library .library
@@ -549,17 +557,27 @@ fn upload_clip(clip_id: String, runtime: State<'_, AppRuntime>) -> Result<ClipDt
if !clip.path.exists() { if !clip.path.exists() {
return Err(format!("Clip file does not exist: {}", clip.path.display())); return Err(format!("Clip file does not exist: {}", clip.path.display()));
} }
let uploader = CatboxUploader::default(); let metadata = UploadMetadata {
let result = uploader clip_id: clip.id.clone(),
.upload( game_id: clip.game_id.clone(),
&clip.path, title: clip.id.clone(),
&UploadMetadata { };
clip_id: clip.id.clone(), let result = match provider.as_deref().unwrap_or("catbox") {
game_id: clip.game_id.clone(), "catbox" => CatboxUploader::default().upload(&clip.path, &metadata),
title: clip.id.clone(), "litterbox" => LitterboxUploader::default().upload(&clip.path, &metadata),
}, "custom_http" => CustomHttpUploader {
) endpoint: custom_endpoint.unwrap_or_default(),
.map_err(|error| error.to_string())?; 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 if !recorder
.library .library
.update_upload(&clip_id, result.provider, result.url) .update_upload(&clip_id, result.provider, result.url)
+45 -5
View File
@@ -77,6 +77,9 @@ type AppState = {
ffmpegPath: string | null; ffmpegPath: string | null;
micEnabled: boolean; micEnabled: boolean;
autoUpload: boolean; autoUpload: boolean;
uploadProvider: "catbox" | "litterbox" | "custom_http" | "lustful";
customUploadEndpoint: string;
customUploadResponsePath: string;
selectedClipId: string; selectedClipId: string;
clips: Clip[]; clips: Clip[];
autoEvents: AutoEvent[]; autoEvents: AutoEvent[];
@@ -109,6 +112,9 @@ const state: AppState = {
ffmpegPath: null, ffmpegPath: null,
micEnabled: false, micEnabled: false,
autoUpload: false, autoUpload: false,
uploadProvider: "catbox",
customUploadEndpoint: "",
customUploadResponsePath: "url",
selectedClipId: "clip-1", selectedClipId: "clip-1",
clips: [ clips: [
{ {
@@ -398,16 +404,30 @@ function renderAutoClipView() {
} }
function renderUploadsView() { 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 ` return `
<section class="settings-grid"> <section class="settings-grid">
${["Catbox", "Litterbox", "Custom HTTP", "Lustful"].map((provider) => ` ${providers.map((provider) => `
<article class="settings-panel"> <article class="settings-panel">
<p class="eyebrow">Provider</p> <p class="eyebrow">Provider</p>
<h2>${provider}</h2> <h2>${provider.title}</h2>
<p class="muted">${provider === "Lustful" ? "Stubbed until API details are confirmed." : "Optional; local clips remain available if upload fails."}</p> <p class="muted">${provider.body}</p>
<button>${provider === "Custom HTTP" ? "Configure" : "Enable"}</button> <button class="${state.uploadProvider === provider.id ? "selected" : ""}" data-upload-provider="${provider.id}">
${state.uploadProvider === provider.id ? "Selected" : "Select"}
</button>
</article> </article>
`).join("")} `).join("")}
<article class="settings-panel">
<p class="eyebrow">Custom HTTP</p>
<h2>Endpoint</h2>
<label>URL <input value="${state.customUploadEndpoint}" data-action="custom-upload-endpoint" /></label>
<label>Response path <input value="${state.customUploadResponsePath}" data-action="custom-upload-response-path" /></label>
</article>
</section> </section>
`; `;
} }
@@ -492,6 +512,21 @@ function bindEvents() {
render(); render();
}); });
appRoot.querySelectorAll<HTMLButtonElement>("[data-upload-provider]").forEach((button) => {
button.addEventListener("click", () => {
state.uploadProvider = button.dataset.uploadProvider as AppState["uploadProvider"];
render();
});
});
appRoot.querySelector<HTMLInputElement>("[data-action='custom-upload-endpoint']")?.addEventListener("input", (event) => {
state.customUploadEndpoint = (event.target as HTMLInputElement).value;
});
appRoot.querySelector<HTMLInputElement>("[data-action='custom-upload-response-path']")?.addEventListener("input", (event) => {
state.customUploadResponsePath = (event.target as HTMLInputElement).value;
});
appRoot.querySelectorAll<HTMLInputElement>("[data-event-id]").forEach((input) => { appRoot.querySelectorAll<HTMLInputElement>("[data-event-id]").forEach((input) => {
input.addEventListener("change", () => { input.addEventListener("change", () => {
const eventRule = state.autoEvents.find((event) => event.id === input.dataset.eventId); const eventRule = state.autoEvents.find((event) => event.id === input.dataset.eventId);
@@ -623,7 +658,12 @@ async function uploadSelectedClip() {
} }
try { try {
const dto = await tauriInvoke<ClipDto>("upload_clip", { clipId: state.selectedClipId }); const dto = await tauriInvoke<ClipDto>("upload_clip", {
clipId: state.selectedClipId,
provider: state.uploadProvider,
customEndpoint: state.customUploadEndpoint,
customResponseUrlPath: state.customUploadResponsePath,
});
const updated = clipFromDto(dto); const updated = clipFromDto(dto);
state.clips = state.clips.map((clip) => (clip.id === updated.id ? updated : clip)); state.clips = state.clips.map((clip) => (clip.id === updated.id ? updated : clip));
render(); render();