Add upload provider selection
This commit is contained in:
1 parent
885e3d9665
commit
6e47f69141
2 files changed
+76
-18
No files matched your search
+31
-13
@@ -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<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 clip = recorder
|
||||
.library
|
||||
@@ -549,17 +557,27 @@ fn upload_clip(clip_id: String, runtime: State<'_, AppRuntime>) -> Result<ClipDt
|
||||
if !clip.path.exists() {
|
||||
return Err(format!("Clip file does not exist: {}", clip.path.display()));
|
||||
}
|
||||
let uploader = CatboxUploader::default();
|
||||
let result = uploader
|
||||
.upload(
|
||||
&clip.path,
|
||||
&UploadMetadata {
|
||||
clip_id: clip.id.clone(),
|
||||
game_id: clip.game_id.clone(),
|
||||
title: clip.id.clone(),
|
||||
},
|
||||
)
|
||||
.map_err(|error| error.to_string())?;
|
||||
let metadata = UploadMetadata {
|
||||
clip_id: clip.id.clone(),
|
||||
game_id: clip.game_id.clone(),
|
||||
title: clip.id.clone(),
|
||||
};
|
||||
let result = match provider.as_deref().unwrap_or("catbox") {
|
||||
"catbox" => 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)
|
||||
|
||||
+45
-5
@@ -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 `
|
||||
<section class="settings-grid">
|
||||
${["Catbox", "Litterbox", "Custom HTTP", "Lustful"].map((provider) => `
|
||||
${providers.map((provider) => `
|
||||
<article class="settings-panel">
|
||||
<p class="eyebrow">Provider</p>
|
||||
<h2>${provider}</h2>
|
||||
<p class="muted">${provider === "Lustful" ? "Stubbed until API details are confirmed." : "Optional; local clips remain available if upload fails."}</p>
|
||||
<button>${provider === "Custom HTTP" ? "Configure" : "Enable"}</button>
|
||||
<h2>${provider.title}</h2>
|
||||
<p class="muted">${provider.body}</p>
|
||||
<button class="${state.uploadProvider === provider.id ? "selected" : ""}" data-upload-provider="${provider.id}">
|
||||
${state.uploadProvider === provider.id ? "Selected" : "Select"}
|
||||
</button>
|
||||
</article>
|
||||
`).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>
|
||||
`;
|
||||
}
|
||||
@@ -492,6 +512,21 @@ function bindEvents() {
|
||||
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) => {
|
||||
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<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);
|
||||
state.clips = state.clips.map((clip) => (clip.id === updated.id ? updated : clip));
|
||||
render();
|
||||
|
||||
Reference in new issue
Block a user