diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 58ec48af..087fdcbc 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -8,15 +8,12 @@ import { onMounted } from "vue"; onMounted(() => { - const loading = document.getElementById("loading"); - if (loading !== null) { - loading.classList.add("done"); + // we can safely assume non-nullity here + const loading = document.getElementById("loading")!; + loading.classList.add("done"); - setTimeout(function () { - if (loading.parentNode !== null) { - loading.parentNode.removeChild(loading); - } - }, 200); - } + setTimeout(function () { + loading.parentNode!.removeChild(loading); + }, 200); }); diff --git a/frontend/src/api/settings.ts b/frontend/src/api/settings.ts index d17c9146..6f806279 100644 --- a/frontend/src/api/settings.ts +++ b/frontend/src/api/settings.ts @@ -1,7 +1,7 @@ import { fetchURL, fetchJSON } from "./utils"; export function get() { - return fetchJSON(`/api/settings`, {}); + return fetchJSON(`/api/settings`, {}); } export async function update(settings: ISettings) { diff --git a/frontend/src/api/share.ts b/frontend/src/api/share.ts index 23ae5bda..3748da4e 100644 --- a/frontend/src/api/share.ts +++ b/frontend/src/api/share.ts @@ -1,12 +1,12 @@ import { fetchURL, fetchJSON, removePrefix, createURL } from "./utils"; export async function list() { - return fetchJSON("/api/shares"); + return fetchJSON("/api/shares"); } export async function get(url: string) { url = removePrefix(url); - return fetchJSON(`/api/share${url}`); + return fetchJSON(`/api/share${url}`); } export async function remove(hash: string) { diff --git a/frontend/src/api/users.ts b/frontend/src/api/users.ts index 35827f4c..a44254fb 100644 --- a/frontend/src/api/users.ts +++ b/frontend/src/api/users.ts @@ -1,11 +1,11 @@ -import { fetchURL, fetchJSON } from "./utils"; +import { fetchURL, fetchJSON, StatusError } from "./utils"; export async function getAll() { - return fetchJSON(`/api/users`, {}); + return fetchJSON(`/api/users`, {}); } export async function get(id: number) { - return fetchJSON(`/api/users/${id}`, {}); + return fetchJSON(`/api/users/${id}`, {}); } export async function create(user: IUser) { @@ -21,6 +21,8 @@ export async function create(user: IUser) { if (res.status === 201) { return res.headers.get("Location"); } + + throw new StatusError(await res.text(), res.status); } export async function update(user: IUser, which = ["all"]) { diff --git a/frontend/src/api/utils.ts b/frontend/src/api/utils.ts index b413f786..9d116132 100644 --- a/frontend/src/api/utils.ts +++ b/frontend/src/api/utils.ts @@ -13,7 +13,11 @@ export class StatusError extends Error { } } -export async function fetchURL(url: string, opts: ApiOpts, auth = true) { +export async function fetchURL( + url: string, + opts: ApiOpts, + auth = true +): Promise { const authStore = useAuthStore(); opts = opts || {}; @@ -50,17 +54,17 @@ export async function fetchURL(url: string, opts: ApiOpts, auth = true) { return res; } -export async function fetchJSON(url: string, opts?: any) { +export async function fetchJSON(url: string, opts?: any): Promise { const res = await fetchURL(url, opts); if (res.status === 200) { - return res.json(); - } else { - throw new Error(res.status.toString()); + return res.json() as Promise; } + + throw new StatusError(`${res.status} ${res.statusText}`, res.status); } -export function removePrefix(url: string) { +export function removePrefix(url: string): string { url = url.split("/").splice(2).join("/"); if (url === "") url = "/"; @@ -68,7 +72,7 @@ export function removePrefix(url: string) { return url; } -export function createURL(endpoint: string, params = {}, auth = true) { +export function createURL(endpoint: string, params = {}, auth = true): string { const authStore = useAuthStore(); let prefix = baseURL; diff --git a/frontend/src/types/api.d.ts b/frontend/src/types/api.d.ts index a027e712..6412ae0d 100644 --- a/frontend/src/types/api.d.ts +++ b/frontend/src/types/api.d.ts @@ -27,10 +27,7 @@ interface Share { expire?: any; userID?: number; token?: string; -} - -interface settings { - any; + username?: string; } interface SearchParams { diff --git a/frontend/src/views/Errors.vue b/frontend/src/views/Errors.vue index 5ddd9ebe..9cf000e1 100644 --- a/frontend/src/views/Errors.vue +++ b/frontend/src/views/Errors.vue @@ -17,7 +17,7 @@ import { useI18n } from "vue-i18n"; const { t } = useI18n({}); const errors: { - [key: string]: { + [key: number]: { icon: string; message: string; }; @@ -40,7 +40,10 @@ const errors: { }, }; -const props = defineProps(["errorCode", "showHeader"]); +const props = defineProps<{ + errorCode: number; + showHeader?: boolean; +}>(); const info = computed(() => { return errors[props.errorCode] ? errors[props.errorCode] : errors[500]; diff --git a/frontend/src/views/Share.vue b/frontend/src/views/Share.vue index 2258167b..6befb971 100644 --- a/frontend/src/views/Share.vue +++ b/frontend/src/views/Share.vue @@ -297,7 +297,7 @@ const keyEvent = (event: KeyboardEvent) => { }; const toggleMultipleSelection = () => { - // toggle + fileStore.toggleMultiple(); }; const isSingleFile = () => diff --git a/frontend/src/views/settings/Global.vue b/frontend/src/views/settings/Global.vue index 8e52386c..6462bbeb 100644 --- a/frontend/src/views/settings/Global.vue +++ b/frontend/src/views/settings/Global.vue @@ -309,7 +309,7 @@ const save = async () => { keyof SettingsCommand >; for (const key of keys) { - // not sure if we can safely assert non-null + // not sure if we can safely assume non-null const newValue = commandObject.value[key]; if (!newValue) continue; @@ -374,10 +374,8 @@ onMounted(async () => { const keys = Object.keys(original.commands) as Array; for (const key of keys) { - //@ts-ignore newSettings.commands[key] = original.commands[key]; - //@ts-ignore - commandObject.value[key] = original.commands[key].join("\n"); + commandObject.value[key] = original.commands[key]!.join("\n"); } originalSettings.value = original; diff --git a/frontend/src/views/settings/Profile.vue b/frontend/src/views/settings/Profile.vue index ec397d5d..a94f6c77 100644 --- a/frontend/src/views/settings/Profile.vue +++ b/frontend/src/views/settings/Profile.vue @@ -80,9 +80,9 @@ import { useAuthStore } from "@/stores/auth"; import { useLayoutStore } from "@/stores/layout"; import { users as api } from "@/api"; import Languages from "@/components/settings/Languages.vue"; -// import i18n, { rtlLanguages } from "@/i18n"; import { inject, onMounted, ref } from "vue"; import { useI18n } from "vue-i18n"; +import i18n, { rtlLanguages } from "@/i18n"; const layoutStore = useLayoutStore(); const authStore = useAuthStore(); @@ -98,10 +98,6 @@ const singleClick = ref(false); const dateFormat = ref(false); const locale = ref(""); -// ...mapState(useAuthStore, ["user"]), -// ...mapWritableState(useLayoutStore, ["loading"]), -//...mapActions(useAuthStore, ["updateUser"]), - const passwordClass = () => { const baseClass = "input input--block"; @@ -164,10 +160,9 @@ const updateSettings = async (event: Event) => { singleClick: singleClick.value, dateFormat: dateFormat.value, }; - // TODO don't know what this is doing - const shouldReload = false; - // rtlLanguages.includes(data.locale) !== - // rtlLanguages.includes(i18n.locale); + const shouldReload = + rtlLanguages.includes(data.locale) !== + rtlLanguages.includes(i18n.global.locale); await api.update(data, [ "locale", "hideDotfiles", @@ -179,8 +174,10 @@ const updateSettings = async (event: Event) => { location.reload(); } $showSuccess(t("settings.settingsUpdated")); - } catch (e: any) { - $showError(e); + } catch (err) { + if (err instanceof Error) { + $showError(err); + } } }; diff --git a/frontend/src/views/settings/Shares.vue b/frontend/src/views/settings/Shares.vue index 36831fd1..d8be2743 100644 --- a/frontend/src/views/settings/Shares.vue +++ b/frontend/src/views/settings/Shares.vue @@ -1,5 +1,5 @@