mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 09:28:29 +00:00
web/saving-handler: destructure params, reuse request if passed
This commit is contained in:
parent
d98cb4c2d7
commit
158ba6f28f
@ -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) {
|
||||
|
@ -58,7 +58,7 @@
|
||||
{disabled}
|
||||
on:click={() => {
|
||||
hapticSwitch();
|
||||
savingHandler(url);
|
||||
savingHandler({ url });
|
||||
}}
|
||||
aria-label={buttonAltText}
|
||||
>
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user