Small ts improvs

This commit is contained in:
Kloon ImKloon 2023-09-14 16:11:22 +02:00
parent 1ad7f4be5f
commit aed1e416a5
No known key found for this signature in database
GPG Key ID: CCF1C86A995C5B6A
10 changed files with 22 additions and 20 deletions

View File

@ -178,7 +178,7 @@ export function copy(items: any[], overwrite = false, rename = false) {
return moveCopy(items, true, overwrite, rename); return moveCopy(items, true, overwrite, rename);
} }
export async function checksum(url: string, algo: ChecksumAlgs) { export async function checksum(url: string, algo: ChecksumAlg) {
const data = await resourceAction(`${url}?checksum=${algo}`, "GET"); const data = await resourceAction(`${url}?checksum=${algo}`, "GET");
return (await data.json()).checksums[algo]; return (await data.json()).checksums[algo];
} }

View File

@ -2,7 +2,11 @@ import { defineStore } from "pinia";
export const useClipboardStore = defineStore("clipboard", { export const useClipboardStore = defineStore("clipboard", {
// convert to a function // convert to a function
state: () => ({ state: (): {
key: string;
items: ClipItem[];
path?: string;
} => ({
key: "", key: "",
items: [], items: [],
path: undefined, path: undefined,
@ -12,11 +16,6 @@ export const useClipboardStore = defineStore("clipboard", {
}, },
actions: { actions: {
// no context as first argument, use `this` instead // no context as first argument, use `this` instead
updateClipboard(value: any) {
this.key = value.key;
this.items = value.items;
this.path = value.path;
},
// easily reset state using `$reset` // easily reset state using `$reset`
resetClipboard() { resetClipboard() {
this.$reset(); this.$reset();

View File

@ -6,7 +6,7 @@ export const useFileStore = defineStore("file", {
req: Resource | null; req: Resource | null;
oldReq: Resource | null; oldReq: Resource | null;
reload: boolean; reload: boolean;
selected: any[]; selected: number[];
multiple: boolean; multiple: boolean;
isFiles: boolean; isFiles: boolean;
} => ({ } => ({

View File

@ -1,6 +1,7 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
/** /**
* Dummy store for exposing router to be used in other stores
* @example * @example
* // route: () => { * // route: () => {
* // const routerStore = useRouterStore(); * // const routerStore = useRouterStore();

View File

@ -17,9 +17,7 @@ interface TusSettings {
chunkSize: number; chunkSize: number;
} }
type ChecksumAlgs = "md5" | "sha1" | "sha256" | "sha512"; type ChecksumAlg = "md5" | "sha1" | "sha256" | "sha512";
type inline = any;
interface Share { interface Share {
hash: string; hash: string;

View File

@ -43,3 +43,8 @@ type DownloadFormat =
| "tarlz4" | "tarlz4"
| "tarsz" | "tarsz"
| null; | null;
interface ClipItem {
from: string;
name: string;
}

View File

@ -1 +0,0 @@
type settings = any;

View File

@ -1,12 +1,12 @@
import { useAuthStore } from "@/stores/auth"; import { useAuthStore } from "@/stores/auth";
import router from "@/router"; import router from "@/router";
import jwt_decode from "jwt-decode"; import jwt_decode, { JwtPayload } from "jwt-decode";
import { baseURL } from "./constants"; import { baseURL } from "./constants";
import { StatusError } from "@/api/utils"; import { StatusError } from "@/api/utils";
export function parseToken(token: string) { export function parseToken(token: string) {
// falsy or malformed jwt will throw InvalidTokenError // falsy or malformed jwt will throw InvalidTokenError
const data = jwt_decode<{ [key: string]: any; user: IUser }>(token); const data = jwt_decode<JwtPayload & { user: IUser }>(token);
document.cookie = `auth=${token}; Path=/; SameSite=Strict;`; document.cookie = `auth=${token}; Path=/; SameSite=Strict;`;
@ -48,7 +48,7 @@ export async function login(
if (res.status === 200) { if (res.status === 200) {
parseToken(body); parseToken(body);
} else { } else {
throw new Error(body); throw new StatusError(body, res.status);
} }
} }
@ -65,7 +65,7 @@ export async function renew(jwt: string) {
if (res.status === 200) { if (res.status === 200) {
parseToken(body); parseToken(body);
} else { } else {
throw new Error(body); throw new StatusError(body, res.status);
} }
} }

View File

@ -1,4 +1,4 @@
export default function getRule(rules: any) { export default function getRule(rules: string[]) {
for (let i = 0; i < rules.length; i++) { for (let i = 0; i < rules.length; i++) {
rules[i] = rules[i].toLowerCase(); rules[i] = rules[i].toLowerCase();
} }

View File

@ -535,9 +535,9 @@ export default {
return; return;
} }
this.clipboardStore.updateClipboard({ this.clipboardStore.$patch({
key: key, key,
items: items, items,
path: this.$route.path, path: this.$route.path,
}); });
}, },