From ef5c8b0d8e794d0634cade975c5c70ac73aa8e21 Mon Sep 17 00:00:00 2001 From: Joep Date: Sat, 9 Sep 2023 13:06:04 +0200 Subject: [PATCH] Converted view/Share.vue to composition api --- frontend/.eslintrc.json | 6 +- frontend/src/api/pub.ts | 46 +-- frontend/src/api/utils.ts | 8 +- frontend/src/main.ts | 2 + frontend/src/stores/file.ts | 12 +- frontend/src/stores/layout.ts | 2 +- frontend/src/types/api.d.ts | 11 +- frontend/src/types/file.d.ts | 41 ++- frontend/src/types/global.d.ts | 3 + frontend/src/types/layout.d.ts | 6 +- frontend/src/views/Files.vue | 5 +- frontend/src/views/Share.vue | 413 ++++++++++------------- frontend/src/views/files/FileListing.vue | 2 +- 13 files changed, 251 insertions(+), 306 deletions(-) diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index 607f9b61..ba4fcdfd 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -3,10 +3,14 @@ "env": { "node": true }, + "parser": "@typescript-eslint/parser", "extends": [ - "plugin:vue/vue3-essential", "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:vue/vue3-essential", "@vue/eslint-config-prettier" + ], "rules": { "vue/multi-word-component-names": "off", diff --git a/frontend/src/api/pub.ts b/frontend/src/api/pub.ts index 526e2b0d..6cae6bf1 100644 --- a/frontend/src/api/pub.ts +++ b/frontend/src/api/pub.ts @@ -1,7 +1,7 @@ import { fetchURL, removePrefix, createURL } from "./utils"; import { baseURL } from "@/utils/constants"; -export async function fetch(url: apiUrl, password: string = "") { +export async function fetch(url: ApiUrl, password: string = "") { url = removePrefix(url); const res = await fetchURL( @@ -33,35 +33,35 @@ export async function fetch(url: apiUrl, password: string = "") { } // Is this redundant code? -// export function download(format, hash, token, ...files) { -// let url = `${baseURL}/api/public/dl/${hash}`; +export function download(format: any, hash: string, token: string, ...files: any) { + let url = `${baseURL}/api/public/dl/${hash}`; -// if (files.length === 1) { -// url += encodeURIComponent(files[0]) + "?"; -// } else { -// let arg = ""; + if (files.length === 1) { + url += encodeURIComponent(files[0]) + "?"; + } else { + let arg = ""; -// for (let file of files) { -// arg += encodeURIComponent(file) + ","; -// } + for (let file of files) { + arg += encodeURIComponent(file) + ","; + } -// arg = arg.substring(0, arg.length - 1); -// arg = encodeURIComponent(arg); -// url += `/?files=${arg}&`; -// } + arg = arg.substring(0, arg.length - 1); + arg = encodeURIComponent(arg); + url += `/?files=${arg}&`; + } -// if (format) { -// url += `algo=${format}&`; -// } + if (format) { + url += `algo=${format}&`; + } -// if (token) { -// url += `token=${token}&`; -// } + if (token) { + url += `token=${token}&`; + } -// window.open(url); -// } + window.open(url); +} -export function getDownloadURL(share: share, inline = false) { +export function getDownloadURL(share: IFile, inline = false) { const params = { ...(inline && { inline: "true" }), ...(share.token && { token: share.token }), diff --git a/frontend/src/api/utils.ts b/frontend/src/api/utils.ts index 5e7467ab..5fa7609c 100644 --- a/frontend/src/api/utils.ts +++ b/frontend/src/api/utils.ts @@ -3,7 +3,7 @@ import { renew, logout } from "@/utils/auth"; import { baseURL } from "@/utils/constants"; import { encodePath } from "@/utils/url"; -export async function fetchURL(url: apiUrl, opts: apiOpts, auth = true) { +export async function fetchURL(url: ApiUrl, opts: ApiOpts, auth = true) { const authStore = useAuthStore(); opts = opts || {}; @@ -46,7 +46,7 @@ export async function fetchURL(url: apiUrl, opts: apiOpts, auth = true) { return res; } -export async function fetchJSON(url: apiUrl, opts?: any) { +export async function fetchJSON(url: ApiUrl, opts?: any) { const res = await fetchURL(url, opts); if (res.status === 200) { @@ -56,7 +56,7 @@ export async function fetchJSON(url: apiUrl, opts?: any) { } } -export function removePrefix(url: apiUrl) { +export function removePrefix(url: ApiUrl) { url = url.split("/").splice(2).join("/"); if (url === "") url = "/"; @@ -64,7 +64,7 @@ export function removePrefix(url: apiUrl) { return url; } -export function createURL(endpoint: apiUrl, params = {}, auth = true) { +export function createURL(endpoint: ApiUrl, params = {}, auth = true) { const authStore = useAuthStore(); let prefix = baseURL; diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 5e6c699a..923f1dde 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -13,6 +13,8 @@ import dayjs from "dayjs"; import localizedFormat from "dayjs/plugin/localizedFormat"; import relativeTime from "dayjs/plugin/relativeTime"; import duration from "dayjs/plugin/duration"; +import "./css/styles.css"; + // register dayjs plugins globally dayjs.extend(localizedFormat); dayjs.extend(relativeTime); diff --git a/frontend/src/stores/file.ts b/frontend/src/stores/file.ts index 045f6e2c..616a7f44 100644 --- a/frontend/src/stores/file.ts +++ b/frontend/src/stores/file.ts @@ -3,15 +3,15 @@ import { defineStore } from "pinia"; export const useFileStore = defineStore("file", { // convert to a function state: (): { - req: req, - oldReq: req, + req: IFile | null, + oldReq: IFile | null, reload: boolean, selected: any[], multiple: boolean, isFiles: boolean } => ({ - req: {}, - oldReq: {}, + req: null, + oldReq: null, reload: false, selected: [], multiple: false, @@ -28,7 +28,7 @@ export const useFileStore = defineStore("file", { // return !layoutStore.loading && state.route._value.name === "Files"; // }, isListing: (state) => { - return state.isFiles && state.req.isDir; + return state.isFiles && state?.req?.isDir; }, }, actions: { @@ -36,7 +36,7 @@ export const useFileStore = defineStore("file", { toggleMultiple() { this.multiple = !this.multiple; }, - updateRequest(value: req) { + updateRequest(value: IFile) { this.oldReq = this.req; this.req = value; }, diff --git a/frontend/src/stores/layout.ts b/frontend/src/stores/layout.ts index 1ca27243..aa2afc87 100644 --- a/frontend/src/stores/layout.ts +++ b/frontend/src/stores/layout.ts @@ -7,7 +7,7 @@ export const useLayoutStore = defineStore("layout", { state: (): { loading: boolean, show: string | null | boolean, - showConfirm: boolean | null, + showConfirm: Function | null, showAction: boolean | null, showShell: boolean | null } => ({ diff --git a/frontend/src/types/api.d.ts b/frontend/src/types/api.d.ts index 79b6a23a..fe56a5bd 100644 --- a/frontend/src/types/api.d.ts +++ b/frontend/src/types/api.d.ts @@ -1,14 +1,13 @@ -type apiUrl = string // Can also be set as a path eg: "path1" | "path2" +type ApiUrl = string // Can also be set as a path eg: "path1" | "path2" type resourcePath = string -type apiMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" +type ApiMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" -// type apiContent = string | Blob | File -type apiContent = Blob | File | Pick, "read"> | "" +type ApiContent = Blob | File | Pick, "read"> | "" -interface apiOpts { - method?: apiMethod, +interface ApiOpts { + method?: ApiMethod, headers?: object, body?: any } diff --git a/frontend/src/types/file.d.ts b/frontend/src/types/file.d.ts index 69709c28..b025210e 100644 --- a/frontend/src/types/file.d.ts +++ b/frontend/src/types/file.d.ts @@ -1,5 +1,5 @@ - -interface file { +interface IFile { + index?: number name: string, modified: string, path: string, @@ -7,27 +7,32 @@ interface file { isDir: boolean, size: number, fullPath: string, - type: uploadType + type: uploadType, + items: IFile[] + token?: string, + hash: string, + url?: string } -interface item { - id: number, - path: string, - file: file, - url?: string, - dir?: boolean, - from?: string, - to?: string, - name?: string, - type?: uploadType - overwrite: boolean -} + type uploadType = "video" | "audio" | "image" | "pdf" | "text" | "blob" -interface req { - isDir?: boolean -} +type req = { + path: string + name: string + size: number + extension: string + modified: string + mode: number + isDir: boolean + isSymlink: boolean + type: string + url: string + hash: string + } + + interface uploads { [key: string]: upload diff --git a/frontend/src/types/global.d.ts b/frontend/src/types/global.d.ts index 8f8d3240..5366524c 100644 --- a/frontend/src/types/global.d.ts +++ b/frontend/src/types/global.d.ts @@ -5,4 +5,7 @@ declare global { FileBrowser: any; grecaptcha: any } + interface HTMLAttributes extends HTMLAttributes { + title: any + } } \ No newline at end of file diff --git a/frontend/src/types/layout.d.ts b/frontend/src/types/layout.d.ts index 0f741a49..1d4efe7f 100644 --- a/frontend/src/types/layout.d.ts +++ b/frontend/src/types/layout.d.ts @@ -1,5 +1,5 @@ interface LayoutValue { - prompt: boolean, - confirm: boolean, - action: boolean, + prompt: string, + confirm: Function, + action?: boolean, } \ No newline at end of file diff --git a/frontend/src/views/Files.vue b/frontend/src/views/Files.vue index 51744265..ef50c51a 100644 --- a/frontend/src/views/Files.vue +++ b/frontend/src/views/Files.vue @@ -1,6 +1,6 @@