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);
}
export async function checksum(url: string, algo: ChecksumAlgs) {
export async function checksum(url: string, algo: ChecksumAlg) {
const data = await resourceAction(`${url}?checksum=${algo}`, "GET");
return (await data.json()).checksums[algo];
}

View File

@ -2,7 +2,11 @@ import { defineStore } from "pinia";
export const useClipboardStore = defineStore("clipboard", {
// convert to a function
state: () => ({
state: (): {
key: string;
items: ClipItem[];
path?: string;
} => ({
key: "",
items: [],
path: undefined,
@ -12,11 +16,6 @@ export const useClipboardStore = defineStore("clipboard", {
},
actions: {
// 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`
resetClipboard() {
this.$reset();

View File

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

View File

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

View File

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

View File

@ -43,3 +43,8 @@ type DownloadFormat =
| "tarlz4"
| "tarsz"
| 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 router from "@/router";
import jwt_decode from "jwt-decode";
import jwt_decode, { JwtPayload } from "jwt-decode";
import { baseURL } from "./constants";
import { StatusError } from "@/api/utils";
export function parseToken(token: string) {
// 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;`;
@ -48,7 +48,7 @@ export async function login(
if (res.status === 200) {
parseToken(body);
} 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) {
parseToken(body);
} 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++) {
rules[i] = rules[i].toLowerCase();
}

View File

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