web: prevent openURL action on ios devices if url is redirect
This commit is contained in:
@@ -4,16 +4,31 @@ import settings from "$lib/state/settings";
|
||||
|
||||
import { device } from "$lib/device";
|
||||
import { t } from "$lib/i18n/translations";
|
||||
|
||||
import { createDialog } from "$lib/dialogs";
|
||||
import type { DialogInfo } from "$lib/types/dialog";
|
||||
|
||||
const openSavingDialog = ({ url, file, body }: { url?: string, file?: File, body?: string }) => {
|
||||
import type { DialogInfo } from "$lib/types/dialog";
|
||||
import type { CobaltFileUrlType } from "$lib/types/api";
|
||||
|
||||
type DownloadFileParams = {
|
||||
url?: string,
|
||||
file?: File,
|
||||
urlType?: CobaltFileUrlType,
|
||||
}
|
||||
|
||||
type SavingDialogParams = {
|
||||
url?: string,
|
||||
file?: File,
|
||||
body?: string,
|
||||
urlType?: CobaltFileUrlType,
|
||||
}
|
||||
|
||||
const openSavingDialog = ({ url, file, body, urlType }: SavingDialogParams) => {
|
||||
const dialogData: DialogInfo = {
|
||||
type: "saving",
|
||||
id: "saving",
|
||||
file,
|
||||
url,
|
||||
urlType,
|
||||
}
|
||||
if (body) dialogData.bodyText = body;
|
||||
|
||||
@@ -60,13 +75,13 @@ export const copyURL = async (url: string) => {
|
||||
return await navigator?.clipboard?.writeText(url);
|
||||
}
|
||||
|
||||
export const downloadFile = ({ url, file }: { url?: string, file?: File }) => {
|
||||
export const downloadFile = ({ url, file, urlType }: DownloadFileParams) => {
|
||||
if (!url && !file) throw new Error("attempted to download void");
|
||||
|
||||
const pref = get(settings).save.savingMethod;
|
||||
|
||||
if (pref === "ask") {
|
||||
return openSavingDialog({ url, file });
|
||||
return openSavingDialog({ url, file, urlType });
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -85,6 +100,7 @@ export const downloadFile = ({ url, file }: { url?: string, file?: File }) => {
|
||||
url,
|
||||
file,
|
||||
body: get(t)("dialog.saving.timeout"),
|
||||
urlType
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,7 +116,8 @@ export const downloadFile = ({ url, file }: { url?: string, file?: File }) => {
|
||||
if (url) {
|
||||
if (pref === "share" && device.supports.share) {
|
||||
return shareURL(url);
|
||||
} else if (pref === "download" && device.supports.directDownload) {
|
||||
} else if (pref === "download" && device.supports.directDownload
|
||||
&& !(device.is.iOS && urlType === "redirect")) {
|
||||
return openURL(url);
|
||||
} else if (pref === "copy" && !file) {
|
||||
return copyURL(url);
|
||||
@@ -108,5 +125,5 @@ export const downloadFile = ({ url, file }: { url?: string, file?: File }) => {
|
||||
}
|
||||
} catch { /* catch & ignore */ }
|
||||
|
||||
return openSavingDialog({ url, file });
|
||||
return openSavingDialog({ url, file, urlType });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user