Fix stuff in converted views
This commit is contained in:
parent
242226e7fc
commit
b6616ddeed
@ -8,15 +8,12 @@
|
|||||||
import { onMounted } from "vue";
|
import { onMounted } from "vue";
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const loading = document.getElementById("loading");
|
// we can safely assume non-nullity here
|
||||||
if (loading !== null) {
|
const loading = document.getElementById("loading")!;
|
||||||
loading.classList.add("done");
|
loading.classList.add("done");
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
if (loading.parentNode !== null) {
|
loading.parentNode!.removeChild(loading);
|
||||||
loading.parentNode.removeChild(loading);
|
}, 200);
|
||||||
}
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { fetchURL, fetchJSON } from "./utils";
|
import { fetchURL, fetchJSON } from "./utils";
|
||||||
|
|
||||||
export function get() {
|
export function get() {
|
||||||
return fetchJSON(`/api/settings`, {});
|
return fetchJSON<ISettings>(`/api/settings`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function update(settings: ISettings) {
|
export async function update(settings: ISettings) {
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
import { fetchURL, fetchJSON, removePrefix, createURL } from "./utils";
|
import { fetchURL, fetchJSON, removePrefix, createURL } from "./utils";
|
||||||
|
|
||||||
export async function list() {
|
export async function list() {
|
||||||
return fetchJSON("/api/shares");
|
return fetchJSON<Share[]>("/api/shares");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get(url: string) {
|
export async function get(url: string) {
|
||||||
url = removePrefix(url);
|
url = removePrefix(url);
|
||||||
return fetchJSON(`/api/share${url}`);
|
return fetchJSON<Share>(`/api/share${url}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function remove(hash: string) {
|
export async function remove(hash: string) {
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { fetchURL, fetchJSON } from "./utils";
|
import { fetchURL, fetchJSON, StatusError } from "./utils";
|
||||||
|
|
||||||
export async function getAll() {
|
export async function getAll() {
|
||||||
return fetchJSON(`/api/users`, {});
|
return fetchJSON<IUser[]>(`/api/users`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get(id: number) {
|
export async function get(id: number) {
|
||||||
return fetchJSON(`/api/users/${id}`, {});
|
return fetchJSON<IUser>(`/api/users/${id}`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function create(user: IUser) {
|
export async function create(user: IUser) {
|
||||||
@ -21,6 +21,8 @@ export async function create(user: IUser) {
|
|||||||
if (res.status === 201) {
|
if (res.status === 201) {
|
||||||
return res.headers.get("Location");
|
return res.headers.get("Location");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new StatusError(await res.text(), res.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function update(user: IUser, which = ["all"]) {
|
export async function update(user: IUser, which = ["all"]) {
|
||||||
|
|||||||
@ -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<Response> {
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
@ -50,17 +54,17 @@ export async function fetchURL(url: string, opts: ApiOpts, auth = true) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchJSON(url: string, opts?: any) {
|
export async function fetchJSON<T>(url: string, opts?: any): Promise<T> {
|
||||||
const res = await fetchURL(url, opts);
|
const res = await fetchURL(url, opts);
|
||||||
|
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
return res.json();
|
return res.json() as Promise<T>;
|
||||||
} else {
|
|
||||||
throw new Error(res.status.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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("/");
|
url = url.split("/").splice(2).join("/");
|
||||||
|
|
||||||
if (url === "") url = "/";
|
if (url === "") url = "/";
|
||||||
@ -68,7 +72,7 @@ export function removePrefix(url: string) {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createURL(endpoint: string, params = {}, auth = true) {
|
export function createURL(endpoint: string, params = {}, auth = true): string {
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
let prefix = baseURL;
|
let prefix = baseURL;
|
||||||
|
|||||||
5
frontend/src/types/api.d.ts
vendored
5
frontend/src/types/api.d.ts
vendored
@ -27,10 +27,7 @@ interface Share {
|
|||||||
expire?: any;
|
expire?: any;
|
||||||
userID?: number;
|
userID?: number;
|
||||||
token?: string;
|
token?: string;
|
||||||
}
|
username?: string;
|
||||||
|
|
||||||
interface settings {
|
|
||||||
any;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SearchParams {
|
interface SearchParams {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import { useI18n } from "vue-i18n";
|
|||||||
const { t } = useI18n({});
|
const { t } = useI18n({});
|
||||||
|
|
||||||
const errors: {
|
const errors: {
|
||||||
[key: string]: {
|
[key: number]: {
|
||||||
icon: string;
|
icon: string;
|
||||||
message: string;
|
message: string;
|
||||||
};
|
};
|
||||||
@ -40,7 +40,10 @@ const errors: {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const props = defineProps(["errorCode", "showHeader"]);
|
const props = defineProps<{
|
||||||
|
errorCode: number;
|
||||||
|
showHeader?: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
const info = computed(() => {
|
const info = computed(() => {
|
||||||
return errors[props.errorCode] ? errors[props.errorCode] : errors[500];
|
return errors[props.errorCode] ? errors[props.errorCode] : errors[500];
|
||||||
|
|||||||
@ -297,7 +297,7 @@ const keyEvent = (event: KeyboardEvent) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const toggleMultipleSelection = () => {
|
const toggleMultipleSelection = () => {
|
||||||
// toggle
|
fileStore.toggleMultiple();
|
||||||
};
|
};
|
||||||
|
|
||||||
const isSingleFile = () =>
|
const isSingleFile = () =>
|
||||||
|
|||||||
@ -309,7 +309,7 @@ const save = async () => {
|
|||||||
keyof SettingsCommand
|
keyof SettingsCommand
|
||||||
>;
|
>;
|
||||||
for (const key of keys) {
|
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];
|
const newValue = commandObject.value[key];
|
||||||
if (!newValue) continue;
|
if (!newValue) continue;
|
||||||
|
|
||||||
@ -374,10 +374,8 @@ onMounted(async () => {
|
|||||||
|
|
||||||
const keys = Object.keys(original.commands) as Array<keyof SettingsCommand>;
|
const keys = Object.keys(original.commands) as Array<keyof SettingsCommand>;
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
//@ts-ignore
|
|
||||||
newSettings.commands[key] = original.commands[key];
|
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;
|
originalSettings.value = original;
|
||||||
|
|||||||
@ -80,9 +80,9 @@ import { useAuthStore } from "@/stores/auth";
|
|||||||
import { useLayoutStore } from "@/stores/layout";
|
import { useLayoutStore } from "@/stores/layout";
|
||||||
import { users as api } from "@/api";
|
import { users as api } from "@/api";
|
||||||
import Languages from "@/components/settings/Languages.vue";
|
import Languages from "@/components/settings/Languages.vue";
|
||||||
// import i18n, { rtlLanguages } from "@/i18n";
|
|
||||||
import { inject, onMounted, ref } from "vue";
|
import { inject, onMounted, ref } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import i18n, { rtlLanguages } from "@/i18n";
|
||||||
|
|
||||||
const layoutStore = useLayoutStore();
|
const layoutStore = useLayoutStore();
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
@ -98,10 +98,6 @@ const singleClick = ref<boolean>(false);
|
|||||||
const dateFormat = ref<boolean>(false);
|
const dateFormat = ref<boolean>(false);
|
||||||
const locale = ref<string>("");
|
const locale = ref<string>("");
|
||||||
|
|
||||||
// ...mapState(useAuthStore, ["user"]),
|
|
||||||
// ...mapWritableState(useLayoutStore, ["loading"]),
|
|
||||||
//...mapActions(useAuthStore, ["updateUser"]),
|
|
||||||
|
|
||||||
const passwordClass = () => {
|
const passwordClass = () => {
|
||||||
const baseClass = "input input--block";
|
const baseClass = "input input--block";
|
||||||
|
|
||||||
@ -164,10 +160,9 @@ const updateSettings = async (event: Event) => {
|
|||||||
singleClick: singleClick.value,
|
singleClick: singleClick.value,
|
||||||
dateFormat: dateFormat.value,
|
dateFormat: dateFormat.value,
|
||||||
};
|
};
|
||||||
// TODO don't know what this is doing
|
const shouldReload =
|
||||||
const shouldReload = false;
|
rtlLanguages.includes(data.locale) !==
|
||||||
// rtlLanguages.includes(data.locale) !==
|
rtlLanguages.includes(i18n.global.locale);
|
||||||
// rtlLanguages.includes(i18n.locale);
|
|
||||||
await api.update(data, [
|
await api.update(data, [
|
||||||
"locale",
|
"locale",
|
||||||
"hideDotfiles",
|
"hideDotfiles",
|
||||||
@ -179,8 +174,10 @@ const updateSettings = async (event: Event) => {
|
|||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
$showSuccess(t("settings.settingsUpdated"));
|
$showSuccess(t("settings.settingsUpdated"));
|
||||||
} catch (e: any) {
|
} catch (err) {
|
||||||
$showError(e);
|
if (err instanceof Error) {
|
||||||
|
$showError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<errors v-if="error" :errorCode="error.status" />
|
<errors v-if="error" :errorCode="error.status ?? 400" />
|
||||||
<div class="row" v-else-if="!layoutStore.loading">
|
<div class="row" v-else-if="!layoutStore.loading">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@ -71,6 +71,7 @@ import Clipboard from "clipboard";
|
|||||||
import Errors from "@/views/Errors.vue";
|
import Errors from "@/views/Errors.vue";
|
||||||
import { inject, onBeforeUnmount, ref, onMounted } from "vue";
|
import { inject, onBeforeUnmount, ref, onMounted } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import { StatusError } from "@/api/utils";
|
||||||
|
|
||||||
const $showError = inject("$showError") as IToastSuccess;
|
const $showError = inject("$showError") as IToastSuccess;
|
||||||
const $showSuccess = inject("$showSuccess") as IToastError;
|
const $showSuccess = inject("$showSuccess") as IToastError;
|
||||||
@ -79,10 +80,8 @@ const { t } = useI18n();
|
|||||||
const layoutStore = useLayoutStore();
|
const layoutStore = useLayoutStore();
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
// ...mapState(useAuthStore, ["user"]),
|
const error = ref<StatusError | null>(null);
|
||||||
// ...mapWritableState(useLayoutStore, ["loading"]),
|
const links = ref<Share[]>([]);
|
||||||
const error = ref<any>(null);
|
|
||||||
const links = ref<any[]>([]);
|
|
||||||
const clip = ref<Clipboard | null>(null);
|
const clip = ref<Clipboard | null>(null);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@ -100,8 +99,10 @@ onMounted(async () => {
|
|||||||
: "";
|
: "";
|
||||||
}
|
}
|
||||||
links.value = newLinks;
|
links.value = newLinks;
|
||||||
} catch (e: any) {
|
} catch (err) {
|
||||||
error.value = e;
|
if (err instanceof StatusError || err instanceof Error) {
|
||||||
|
error.value = err;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
layoutStore.loading = false;
|
layoutStore.loading = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,11 +75,10 @@ import { useLayoutStore } from "@/stores/layout";
|
|||||||
import { users as api, settings } from "@/api";
|
import { users as api, settings } from "@/api";
|
||||||
import UserForm from "@/components/settings/UserForm.vue";
|
import UserForm from "@/components/settings/UserForm.vue";
|
||||||
import Errors from "@/views/Errors.vue";
|
import Errors from "@/views/Errors.vue";
|
||||||
// @ts-ignore
|
|
||||||
import { cloneDeep } from "lodash-es";
|
|
||||||
import { computed, inject, onMounted, ref, watch } from "vue";
|
import { computed, inject, onMounted, ref, watch } from "vue";
|
||||||
import { useRoute, useRouter } from "vue-router";
|
import { useRoute, useRouter } from "vue-router";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import { StatusError } from "@/api/utils";
|
||||||
|
|
||||||
const error = ref<any | null>(null);
|
const error = ref<any | null>(null);
|
||||||
const originalUser = ref<IUser | null>(null);
|
const originalUser = ref<IUser | null>(null);
|
||||||
@ -112,12 +111,12 @@ const fetchData = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (isNew.value) {
|
if (isNew.value) {
|
||||||
let { defaults, _createUserDir } = await settings.get();
|
let { defaults, createUserDir: _createUserDir } = await settings.get();
|
||||||
createUserDir.value = _createUserDir;
|
createUserDir.value = _createUserDir;
|
||||||
user.value = {
|
user.value = {
|
||||||
...defaults,
|
...defaults,
|
||||||
username: "",
|
username: "",
|
||||||
passsword: "",
|
password: "",
|
||||||
rules: [],
|
rules: [],
|
||||||
lockPassword: false,
|
lockPassword: false,
|
||||||
id: 0,
|
id: 0,
|
||||||
@ -146,8 +145,12 @@ const deleteUser = async (e: Event) => {
|
|||||||
await api.remove(user.value.id);
|
await api.remove(user.value.id);
|
||||||
router.push({ path: "/settings/users" });
|
router.push({ path: "/settings/users" });
|
||||||
$showSuccess(t("settings.userDeleted"));
|
$showSuccess(t("settings.userDeleted"));
|
||||||
} catch (e: any) {
|
} catch (err) {
|
||||||
e.message === "403" ? $showError(t("errors.forbidden")) : $showError(e);
|
if (err instanceof StatusError) {
|
||||||
|
err.status === 403 ? $showError(t("errors.forbidden")) : $showError(err);
|
||||||
|
} else if (err instanceof Error) {
|
||||||
|
$showError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const save = async (event: Event) => {
|
const save = async (event: Event) => {
|
||||||
@ -163,7 +166,7 @@ const save = async (event: Event) => {
|
|||||||
...user.value,
|
...user.value,
|
||||||
};
|
};
|
||||||
|
|
||||||
const loc = (await api.create(newUser)) as string;
|
const loc = (await api.create(newUser)) || "/settings/users";
|
||||||
router.push({ path: loc });
|
router.push({ path: loc });
|
||||||
$showSuccess(t("settings.userCreated"));
|
$showSuccess(t("settings.userCreated"));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<errors v-if="error" :errorCode="error.status" />
|
<errors v-if="error" :errorCode="error.status ?? 400" />
|
||||||
<div class="row" v-else-if="!layoutStore.loading">
|
<div class="row" v-else-if="!layoutStore.loading">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@ -47,8 +47,9 @@ import { users as api } from "@/api";
|
|||||||
import Errors from "@/views/Errors.vue";
|
import Errors from "@/views/Errors.vue";
|
||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import { StatusError } from "@/api/utils";
|
||||||
|
|
||||||
const error = ref<any>(null);
|
const error = ref<StatusError | null>(null);
|
||||||
const users = ref<IUser[]>([]);
|
const users = ref<IUser[]>([]);
|
||||||
|
|
||||||
const layoutStore = useLayoutStore();
|
const layoutStore = useLayoutStore();
|
||||||
@ -59,8 +60,10 @@ onMounted(async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
users.value = await api.getAll();
|
users.value = await api.getAll();
|
||||||
} catch (e: any) {
|
} catch (err) {
|
||||||
error.value = e;
|
if (err instanceof StatusError || err instanceof Error) {
|
||||||
|
error.value = err;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
layoutStore.loading = false;
|
layoutStore.loading = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user