diff --git a/frontend/src/api/pub.ts b/frontend/src/api/pub.ts index e97b876b..d8c99feb 100644 --- a/frontend/src/api/pub.ts +++ b/frontend/src/api/pub.ts @@ -1,4 +1,4 @@ -import type { IFile } from "@/types"; +import type { IShare } from "@/types"; import { fetchURL, removePrefix, createURL } from "./utils"; import { baseURL } from "@/utils/constants"; @@ -67,7 +67,7 @@ export function download( window.open(url); } -export function getDownloadURL(share: IFile, inline = false) { +export function getDownloadURL(share: IShare, inline = false) { const params = { ...(inline && { inline: "true" }), ...(share.token && { token: share.token }), diff --git a/frontend/src/types/api.d.ts b/frontend/src/types/api.d.ts index 01c2de6a..adb60a3e 100644 --- a/frontend/src/types/api.d.ts +++ b/frontend/src/types/api.d.ts @@ -24,11 +24,11 @@ export type ChecksumAlgs = "md5" | "sha1" | "sha256" | "sha512"; type inline = any; export interface IShare { - expire: any; hash: string; path: string; - userID: number; - token: string; + expire?: any; + userID?: number; + token?: string; } interface settings { diff --git a/frontend/src/views/Login.vue b/frontend/src/views/Login.vue index 4c5ba068..4786b218 100644 --- a/frontend/src/views/Login.vue +++ b/frontend/src/views/Login.vue @@ -71,10 +71,7 @@ const submit = async (event: Event) => { event.preventDefault(); event.stopPropagation(); - let redirect = route.query.redirect; - if (redirect === "" || redirect === undefined || redirect === null) { - redirect = "/files/"; - } + const redirect = (route.query.redirect || "/files/") as string; let captcha = ""; if (recaptcha) { @@ -99,7 +96,6 @@ const submit = async (event: Event) => { } await auth.login(username.value, password.value, captcha); - // @ts-ignore router.push({ path: redirect }); } catch (e: any) { console.error(e); diff --git a/frontend/src/views/Share.vue b/frontend/src/views/Share.vue index d021be66..db85722c 100644 --- a/frontend/src/views/Share.vue +++ b/frontend/src/views/Share.vue @@ -194,9 +194,10 @@ import Item from "@/components/files/ListingItem.vue"; import Clipboard from "clipboard"; import { useFileStore } from "@/stores/file"; import { useLayoutStore } from "@/stores/layout"; -import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue"; +import { computed, inject, onBeforeUnmount, onMounted, ref, watch } from "vue"; import { useRoute } from "vue-router"; import { useI18n } from "vue-i18n"; +import type { IToastSuccess } from "@/types"; const error = ref(null); const showLimit = ref(100); @@ -206,6 +207,8 @@ const hash = ref(null); const token = ref(null); const clip = ref(null); +const $showSuccess = inject("$showError")!; + const { t } = useI18n({}); const route = useRoute(); @@ -256,7 +259,7 @@ const fetchData = async () => { fileStore.reload = false; fileStore.selected = []; fileStore.multiple = false; - // fileStore.closeHovers(); + layoutStore.closeHovers(); // Set loading to true and reset the error. layoutStore.loading = true; @@ -324,7 +327,6 @@ const download = () => { files.push(req.value.items[i].path); } - // @ts-ignore api.download(format, hash.value, token.value, ...files); }, }); @@ -332,8 +334,7 @@ const download = () => { const linkSelected = () => { return isSingleFile() && req.value - ? // @ts-ignore - api.getDownloadURL({ + ? api.getDownloadURL({ hash: hash.value, path: req.value.items[fileStore.selected[0]].path, }) @@ -348,7 +349,7 @@ onMounted(async () => { window.addEventListener("keydown", keyEvent); clip.value = new Clipboard(".copy-clipboard"); clip.value.on("success", () => { - // $showSuccess(this.t("success.linkCopied")); + $showSuccess(t("success.linkCopied")); }); }); diff --git a/frontend/src/views/settings/Global.vue b/frontend/src/views/settings/Global.vue index 92d6f6b5..b3da1696 100644 --- a/frontend/src/views/settings/Global.vue +++ b/frontend/src/views/settings/Global.vue @@ -254,7 +254,7 @@ const settings = ref(null); const debounceTimeout = ref(null); const commandObject = ref<{ - [key in keyof SettingsCommand]: string; + [key in keyof SettingsCommand]: string[] | string; }>({}); const shellValue = ref(""); @@ -312,19 +312,20 @@ const save = async () => { commands: {}, }; - // @ts-ignore - for (const name of Object.keys(settings.value.commands)) { - // @ts-ignore - const newValue = commandObject.value[name]; - // @ts-ignore - if (name in commandObject.value && !Array.isArray(newValue)) { - // @ts-ignore - newSettings.commands[name] = newValue + const keys = Object.keys(settings.value.commands) as Array< + keyof SettingsCommand + >; + for (const key of keys) { + // not sure if we can safely assert non-null + const newValue = commandObject.value[key]; + if (!newValue) continue; + + if (Array.isArray(newValue)) { + newSettings.commands[key] = newValue; + } else if (key in commandObject.value) { + newSettings.commands[key] = newValue .split("\n") .filter((cmd: string) => cmd !== ""); - } else { - // @ts-ignore - newSettings.commands[name] = newValue; } } newSettings.shell = shellValue.value.split("\n"); @@ -379,16 +380,16 @@ onMounted(async () => { const original: ISettings = await api.get(); let newSettings: ISettings = { ...original, commands: {} }; - for (const key in original.commands) { - // @ts-ignore + const keys = Object.keys(original.commands) as Array; + for (const key in keys) { + //@ts-ignore newSettings.commands[key] = original.commands[key]; - // @ts-ignore + //@ts-ignore commandObject.value[key] = original.commands[key].join("\n"); } originalSettings.value = original; settings.value = newSettings; - // @ts-ignore shellValue.value = newSettings.shell.join("\n"); } catch (e) { error.value = e;