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 { 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 }),

View File

@ -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 {

View File

@ -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);

View File

@ -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 | any>(null);
const showLimit = ref<number>(100);
@ -206,6 +207,8 @@ const hash = ref<any>(null);
const token = ref<any>(null);
const clip = ref<any>(null);
const $showSuccess = inject<IToastSuccess>("$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"));
});
});

View File

@ -254,7 +254,7 @@ const settings = ref<ISettings | null>(null);
const debounceTimeout = ref<number | null>(null);
const commandObject = ref<{
[key in keyof SettingsCommand]: string;
[key in keyof SettingsCommand]: string[] | string;
}>({});
const shellValue = ref<string>("");
@ -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<keyof SettingsCommand>;
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;