web/saving-handler: destructure params, reuse request if passed

This commit is contained in:
wukko 2025-03-06 17:02:06 +06:00
parent d98cb4c2d7
commit 158ba6f28f
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
3 changed files with 13 additions and 7 deletions

View File

@ -79,7 +79,7 @@
if (!isBotCheckOngoing) { if (!isBotCheckOngoing) {
await tick(); // wait for button to render await tick(); // wait for button to render
savingHandler($link); savingHandler({ url: $link });
} }
} }
}; };
@ -98,7 +98,7 @@
} }
if (e.key === "Enter" && validLink($link) && isFocused) { if (e.key === "Enter" && validLink($link) && isFocused) {
savingHandler($link); savingHandler({ url: $link });
} }
if (["Escape", "Clear"].includes(e.key) && isFocused) { if (["Escape", "Clear"].includes(e.key) && isFocused) {

View File

@ -58,7 +58,7 @@
{disabled} {disabled}
on:click={() => { on:click={() => {
hapticSwitch(); hapticSwitch();
savingHandler(url); savingHandler({ url });
}} }}
aria-label={buttonAltText} aria-label={buttonAltText}
> >

View File

@ -10,6 +10,7 @@ import { downloadButtonState } from "$lib/state/omnibox";
import { createSavePipeline } from "$lib/queen-bee/queue"; import { createSavePipeline } from "$lib/queen-bee/queue";
import type { DialogInfo } from "$lib/types/dialog"; import type { DialogInfo } from "$lib/types/dialog";
import type { CobaltSaveRequestBody } from "$lib/types/api";
const defaultErrorPopup: DialogInfo = { const defaultErrorPopup: DialogInfo = {
id: "save-error", id: "save-error",
@ -17,7 +18,7 @@ const defaultErrorPopup: DialogInfo = {
meowbalt: "error", meowbalt: "error",
}; };
export const savingHandler = async (link: string) => { export const savingHandler = async ({ url, request }: { url?: string, request?: CobaltSaveRequestBody }) => {
downloadButtonState.set("think"); downloadButtonState.set("think");
const errorButtons = [ const errorButtons = [
@ -30,8 +31,13 @@ export const savingHandler = async (link: string) => {
const getSetting = lazySettingGetter(get(settings)); const getSetting = lazySettingGetter(get(settings));
const request = { if (!request && !url) return;
url: link,
const selectedRequest = request || {
// pointing typescript to the fact that
// url is either present or not used at all,
// aka in cases when request is present
url: url!,
alwaysProxy: getSetting("save", "alwaysProxy"), alwaysProxy: getSetting("save", "alwaysProxy"),
localProcessing: getSetting("save", "localProcessing"), localProcessing: getSetting("save", "localProcessing"),
@ -53,7 +59,7 @@ export const savingHandler = async (link: string) => {
allowH265: getSetting("save", "allowH265"), allowH265: getSetting("save", "allowH265"),
} }
const response = await API.request(request); const response = await API.request(selectedRequest);
if (!response) { if (!response) {
downloadButtonState.set("error"); downloadButtonState.set("error");