From fccb8238019c8bd1be91b6b6f90b00aefbbe216a Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 5 Oct 2022 21:34:08 +0200 Subject: [PATCH] Fixed a few things Closes #39, #40 --- frontend/package.json | 2 + frontend/src/api/base.ts | 10 +++- frontend/src/api/util.ts | 15 ++++-- .../components/DirViewer/DirViewerTable.vue | 9 +++- .../src/components/DirViewer/PreviewImage.vue | 51 +++++++++++-------- .../UploadDialog/UploadFileDialog.vue | 4 +- frontend/src/views/FSView.vue | 8 +-- frontend/vite.config.ts | 1 + frontend/yarn.lock | 10 ++++ 9 files changed, 77 insertions(+), 33 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index cdce3ff..08a4445 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -17,6 +17,7 @@ "filesize": "^9.0.11", "jwt-decode": "^3.1.2", "naive-ui": "^2.32.1", + "semaphore": "^1.1.0", "stream-browserify": "^3.0.0", "util": "^0.12.4", "vue": "^3.2.37", @@ -25,6 +26,7 @@ "devDependencies": { "@rushstack/eslint-patch": "^1.1.4", "@types/node": "^18.7.14", + "@types/semaphore": "^1.1.1", "@vitejs/plugin-vue": "^3.0.1", "@vitejs/plugin-vue-jsx": "^2.0.0", "@vue/eslint-config-prettier": "^7.0.0", diff --git a/frontend/src/api/base.ts b/frontend/src/api/base.ts index d90f2df..06b32b9 100644 --- a/frontend/src/api/base.ts +++ b/frontend/src/api/base.ts @@ -40,8 +40,14 @@ export const post_token_form = ( }, onUploadProgress: onProgress }) - .then((res) => res.data) - .catch((err) => err.response.data); + .then((res) => { + console.log(res); + return res.data; + }) + .catch((err) => { + console.log(err); + return err.response.data; + }); // eslint-disable-next-line @typescript-eslint/no-unused-vars export const get = (url: string) => diff --git a/frontend/src/api/util.ts b/frontend/src/api/util.ts index 7e15900..f798baa 100644 --- a/frontend/src/api/util.ts +++ b/frontend/src/api/util.ts @@ -4,6 +4,16 @@ import jwtDecode from 'jwt-decode'; import { isErrorResponse } from './base'; import { refresh_token } from './auth'; +export async function update_token( + token: TokenInjectType +): Promise { + if (!token.jwt.value) return token.logout(); + const new_token = await refresh_token(token.jwt.value); + if (isErrorResponse(new_token)) return token.logout(); + token.setToken(new_token.jwt); + return new_token.jwt; +} + export async function check_token( token: TokenInjectType ): Promise { @@ -13,10 +23,7 @@ export async function check_token( // Expires in more than 60 Minute if (payload.exp && payload.exp > Math.floor(Date.now() / 1000 + 60 * 60)) return token.jwt.value; - const new_token = await refresh_token(token.jwt.value); - if (isErrorResponse(new_token)) return token.logout(); - token.setToken(new_token.jwt); - return new_token.jwt; + return update_token(token); } export type TokenInjectType = { diff --git a/frontend/src/components/DirViewer/DirViewerTable.vue b/frontend/src/components/DirViewer/DirViewerTable.vue index afdb759..de1edc4 100644 --- a/frontend/src/components/DirViewer/DirViewerTable.vue +++ b/frontend/src/components/DirViewer/DirViewerTable.vue @@ -33,6 +33,7 @@ import { Delete, Download } from '@vicons/carbon'; +import semaphore from 'semaphore'; import NLink from '@/components/NLink.vue'; import PreviewImage from '@/components/DirViewer/PreviewImage.vue'; import createZipDialog from '@/components/DirViewer/CreateZipDialog'; @@ -59,6 +60,7 @@ const props = defineProps<{ showPreview: boolean; }>(); +const previewDownloadSem = semaphore(40); const checkedRows = ref([]); const deleteNodes = ref([]); const deleteDialog = ref(); @@ -222,7 +224,12 @@ const previewColumns: DataTableColumn[] = [ return node.isFile ? ( {{ - default: () => , + default: () => ( + + ), fallback: () => }} diff --git a/frontend/src/components/DirViewer/PreviewImage.vue b/frontend/src/components/DirViewer/PreviewImage.vue index a33e0a5..bf77dfa 100644 --- a/frontend/src/components/DirViewer/PreviewImage.vue +++ b/frontend/src/components/DirViewer/PreviewImage.vue @@ -1,5 +1,6 @@