Fix some ts-ignores in Login and Share

This commit is contained in:
Kloon ImKloon 2023-09-11 21:03:42 +02:00
parent 443ceb53d1
commit d4439c9ae9
No known key found for this signature in database
GPG Key ID: CCF1C86A995C5B6A
5 changed files with 30 additions and 32 deletions

View File

@ -1,4 +1,4 @@
import type { IFile } from "@/types"; import type { IShare } from "@/types";
import { fetchURL, removePrefix, createURL } from "./utils"; import { fetchURL, removePrefix, createURL } from "./utils";
import { baseURL } from "@/utils/constants"; import { baseURL } from "@/utils/constants";
@ -67,7 +67,7 @@ export function download(
window.open(url); window.open(url);
} }
export function getDownloadURL(share: IFile, inline = false) { export function getDownloadURL(share: IShare, inline = false) {
const params = { const params = {
...(inline && { inline: "true" }), ...(inline && { inline: "true" }),
...(share.token && { token: share.token }), ...(share.token && { token: share.token }),

View File

@ -24,11 +24,11 @@ export type ChecksumAlgs = "md5" | "sha1" | "sha256" | "sha512";
type inline = any; type inline = any;
export interface IShare { export interface IShare {
expire: any;
hash: string; hash: string;
path: string; path: string;
userID: number; expire?: any;
token: string; userID?: number;
token?: string;
} }
interface settings { interface settings {

View File

@ -71,10 +71,7 @@ const submit = async (event: Event) => {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
let redirect = route.query.redirect; const redirect = (route.query.redirect || "/files/") as string;
if (redirect === "" || redirect === undefined || redirect === null) {
redirect = "/files/";
}
let captcha = ""; let captcha = "";
if (recaptcha) { if (recaptcha) {
@ -99,7 +96,6 @@ const submit = async (event: Event) => {
} }
await auth.login(username.value, password.value, captcha); await auth.login(username.value, password.value, captcha);
// @ts-ignore
router.push({ path: redirect }); router.push({ path: redirect });
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);

View File

@ -194,9 +194,10 @@ import Item from "@/components/files/ListingItem.vue";
import Clipboard from "clipboard"; import Clipboard from "clipboard";
import { useFileStore } from "@/stores/file"; import { useFileStore } from "@/stores/file";
import { useLayoutStore } from "@/stores/layout"; 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 { useRoute } from "vue-router";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import type { IToastSuccess } from "@/types";
const error = ref<null | any>(null); const error = ref<null | any>(null);
const showLimit = ref<number>(100); const showLimit = ref<number>(100);
@ -206,6 +207,8 @@ const hash = ref<any>(null);
const token = ref<any>(null); const token = ref<any>(null);
const clip = ref<any>(null); const clip = ref<any>(null);
const $showSuccess = inject<IToastSuccess>("$showError")!;
const { t } = useI18n({}); const { t } = useI18n({});
const route = useRoute(); const route = useRoute();
@ -256,7 +259,7 @@ const fetchData = async () => {
fileStore.reload = false; fileStore.reload = false;
fileStore.selected = []; fileStore.selected = [];
fileStore.multiple = false; fileStore.multiple = false;
// fileStore.closeHovers(); layoutStore.closeHovers();
// Set loading to true and reset the error. // Set loading to true and reset the error.
layoutStore.loading = true; layoutStore.loading = true;
@ -324,7 +327,6 @@ const download = () => {
files.push(req.value.items[i].path); files.push(req.value.items[i].path);
} }
// @ts-ignore
api.download(format, hash.value, token.value, ...files); api.download(format, hash.value, token.value, ...files);
}, },
}); });
@ -332,8 +334,7 @@ const download = () => {
const linkSelected = () => { const linkSelected = () => {
return isSingleFile() && req.value return isSingleFile() && req.value
? // @ts-ignore ? api.getDownloadURL({
api.getDownloadURL({
hash: hash.value, hash: hash.value,
path: req.value.items[fileStore.selected[0]].path, path: req.value.items[fileStore.selected[0]].path,
}) })
@ -348,7 +349,7 @@ onMounted(async () => {
window.addEventListener("keydown", keyEvent); window.addEventListener("keydown", keyEvent);
clip.value = new Clipboard(".copy-clipboard"); clip.value = new Clipboard(".copy-clipboard");
clip.value.on("success", () => { clip.value.on("success", () => {
// $showSuccess(this.t("success.linkCopied")); $showSuccess(t("success.linkCopied"));
}); });
}); });

View File

@ -254,7 +254,7 @@ const settings = ref<ISettings | null>(null);
const debounceTimeout = ref<number | null>(null); const debounceTimeout = ref<number | null>(null);
const commandObject = ref<{ const commandObject = ref<{
[key in keyof SettingsCommand]: string; [key in keyof SettingsCommand]: string[] | string;
}>({}); }>({});
const shellValue = ref<string>(""); const shellValue = ref<string>("");
@ -312,19 +312,20 @@ const save = async () => {
commands: {}, commands: {},
}; };
// @ts-ignore const keys = Object.keys(settings.value.commands) as Array<
for (const name of Object.keys(settings.value.commands)) { keyof SettingsCommand
// @ts-ignore >;
const newValue = commandObject.value[name]; for (const key of keys) {
// @ts-ignore // not sure if we can safely assert non-null
if (name in commandObject.value && !Array.isArray(newValue)) { const newValue = commandObject.value[key];
// @ts-ignore if (!newValue) continue;
newSettings.commands[name] = newValue
if (Array.isArray(newValue)) {
newSettings.commands[key] = newValue;
} else if (key in commandObject.value) {
newSettings.commands[key] = newValue
.split("\n") .split("\n")
.filter((cmd: string) => cmd !== ""); .filter((cmd: string) => cmd !== "");
} else {
// @ts-ignore
newSettings.commands[name] = newValue;
} }
} }
newSettings.shell = shellValue.value.split("\n"); newSettings.shell = shellValue.value.split("\n");
@ -379,16 +380,16 @@ onMounted(async () => {
const original: ISettings = await api.get(); const original: ISettings = await api.get();
let newSettings: ISettings = { ...original, commands: {} }; let newSettings: ISettings = { ...original, commands: {} };
for (const key in original.commands) { const keys = Object.keys(original.commands) as Array<keyof SettingsCommand>;
// @ts-ignore for (const key in keys) {
//@ts-ignore
newSettings.commands[key] = original.commands[key]; newSettings.commands[key] = original.commands[key];
// @ts-ignore //@ts-ignore
commandObject.value[key] = original.commands[key].join("\n"); commandObject.value[key] = original.commands[key].join("\n");
} }
originalSettings.value = original; originalSettings.value = original;
settings.value = newSettings; settings.value = newSettings;
// @ts-ignore
shellValue.value = newSettings.shell.join("\n"); shellValue.value = newSettings.shell.join("\n");
} catch (e) { } catch (e) {
error.value = e; error.value = e;