Small ts improvs
This commit is contained in:
parent
1ad7f4be5f
commit
aed1e416a5
@ -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];
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
} => ({
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
/**
|
||||
* Dummy store for exposing router to be used in other stores
|
||||
* @example
|
||||
* // route: () => {
|
||||
* // const routerStore = useRouterStore();
|
||||
|
||||
4
frontend/src/types/api.d.ts
vendored
4
frontend/src/types/api.d.ts
vendored
@ -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;
|
||||
|
||||
5
frontend/src/types/file.d.ts
vendored
5
frontend/src/types/file.d.ts
vendored
@ -43,3 +43,8 @@ type DownloadFormat =
|
||||
| "tarlz4"
|
||||
| "tarsz"
|
||||
| null;
|
||||
|
||||
interface ClipItem {
|
||||
from: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
1
frontend/src/types/utils.d.ts
vendored
1
frontend/src/types/utils.d.ts
vendored
@ -1 +0,0 @@
|
||||
type settings = any;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -535,9 +535,9 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
this.clipboardStore.updateClipboard({
|
||||
key: key,
|
||||
items: items,
|
||||
this.clipboardStore.$patch({
|
||||
key,
|
||||
items,
|
||||
path: this.$route.path,
|
||||
});
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user