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

View File

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

View File

@ -10,6 +10,7 @@ import { downloadButtonState } from "$lib/state/omnibox";
import { createSavePipeline } from "$lib/queen-bee/queue";
import type { DialogInfo } from "$lib/types/dialog";
import type { CobaltSaveRequestBody } from "$lib/types/api";
const defaultErrorPopup: DialogInfo = {
id: "save-error",
@ -17,7 +18,7 @@ const defaultErrorPopup: DialogInfo = {
meowbalt: "error",
};
export const savingHandler = async (link: string) => {
export const savingHandler = async ({ url, request }: { url?: string, request?: CobaltSaveRequestBody }) => {
downloadButtonState.set("think");
const errorButtons = [
@ -30,8 +31,13 @@ export const savingHandler = async (link: string) => {
const getSetting = lazySettingGetter(get(settings));
const request = {
url: link,
if (!request && !url) return;
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"),
localProcessing: getSetting("save", "localProcessing"),
@ -53,7 +59,7 @@ export const savingHandler = async (link: string) => {
allowH265: getSetting("save", "allowH265"),
}
const response = await API.request(request);
const response = await API.request(selectedRequest);
if (!response) {
downloadButtonState.set("error");