From 820457690fa609b0e245d50fe9297f151fb33131 Mon Sep 17 00:00:00 2001 From: Jay Cammarano <67079013+jaycammarano@users.noreply.github.com> Date: Wed, 20 Jul 2022 15:52:38 -0400 Subject: [PATCH] Optimize media loading across app (#10592) * v-image and "lazy load" working * fixed vars * all the other img uses * No longer require access token in url for files * Add lazy loading and size limits * Rename map-component source prop * Fix lint warning * Update app/src/views/public/public-view.vue Co-authored-by: ian * Fix lint * Fix missing file type icon * Fix null imageInfo error * Use video.js for media playback * Fix .js file display * Update package-lock.json * Update package-lock.json * update package.json * Update pnpm-lock.yaml * Remove unrelated addition on VDatePicker * Remove folder abstraction * Use image data based aspect ratio on preview * Base app rate throttle on API rate limit config * Configure app rate limit throttle based on api config * Convert v-image to script[setup] * Convert v-media to script[setup] * Cleanup v-media * Remove unneeded addTokenToUrl usages * Remove video.js It doesn't do authorization headers for mp4/mp3, so it's pointless Co-authored-by: rijkvanzanten Co-authored-by: ian --- api/src/services/server.ts | 13 +++ app/src/api.ts | 9 +- app/src/components/register.ts | 2 + app/src/components/v-image.vue | 87 +++++++++++++++++++ app/src/displays/file/file.vue | 7 +- app/src/displays/image/image.vue | 10 +-- app/src/displays/user/user.vue | 10 +-- app/src/interfaces/file-image/file-image.vue | 7 +- app/src/interfaces/file/file.vue | 5 +- app/src/interfaces/files/files.vue | 6 ++ app/src/layouts/cards/components/card.vue | 46 +++++----- app/src/layouts/map/map.vue | 13 +-- app/src/modules/files/routes/item.vue | 6 +- app/src/modules/users/routes/item.vue | 43 +++++---- app/src/stores/server.ts | 19 +++- app/src/utils/readable-mime-type/types.json | 1 + .../comments-sidebar-detail/comment-input.vue | 27 +++--- .../comment-item-header.vue | 14 +-- .../components/drawer-item/drawer-item.vue | 16 ++-- .../file-lightbox/file-lightbox.vue | 8 +- .../components/file-preview/file-preview.vue | 9 +- .../components/image-editor/image-editor.vue | 17 ++-- .../module-bar-avatar/module-bar-avatar.vue | 11 ++- .../module-bar-logo/module-bar-logo.vue | 11 ++- .../components/user-popover/user-popover.vue | 11 ++- app/src/views/public/public-view.vue | 4 +- pnpm-lock.yaml | 2 +- 27 files changed, 259 insertions(+), 155 deletions(-) create mode 100644 app/src/components/v-image.vue diff --git a/api/src/services/server.ts b/api/src/services/server.ts index 5da4c87dcc..7afbeadb65 100644 --- a/api/src/services/server.ts +++ b/api/src/services/server.ts @@ -50,6 +50,17 @@ export class ServerService { info.project = projectInfo; + if (this.accountability?.user) { + if (env.RATE_LIMITER_ENABLED) { + info.rateLimit = { + points: env.RATE_LIMITER_POINTS, + duration: env.RATE_LIMITER_DURATION, + }; + } else { + info.rateLimit = false; + } + } + if (this.accountability?.admin === true) { const osType = os.type() === 'Darwin' ? 'macOS' : os.type(); @@ -58,10 +69,12 @@ export class ServerService { info.directus = { version, }; + info.node = { version: process.versions.node, uptime: Math.round(process.uptime()), }; + info.os = { type: osType, version: osVersion, diff --git a/app/src/api.ts b/app/src/api.ts index 7114e434c1..174e75ca1c 100644 --- a/app/src/api.ts +++ b/app/src/api.ts @@ -3,7 +3,7 @@ import { useRequestsStore } from '@/stores/'; import { getRootPath } from '@/utils/get-root-path'; import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; import { addQueryToPath } from './utils/add-query-to-path'; -import PQueue from 'p-queue'; +import PQueue, { Options, DefaultAddOptions } from 'p-queue'; const api = axios.create({ baseURL: getRootPath(), @@ -13,7 +13,7 @@ const api = axios.create({ }, }); -const queue = new PQueue({ concurrency: 5, intervalCap: 5, interval: 500, carryoverConcurrencyCount: true }); +let queue = new PQueue({ concurrency: 5, intervalCap: 5, interval: 500, carryoverConcurrencyCount: true }); interface RequestConfig extends AxiosRequestConfig { id: string; @@ -113,3 +113,8 @@ export function addTokenToURL(url: string, token?: string): string { return addQueryToPath(url, { access_token: accessToken }); } + +export async function replaceQueue(options?: Options) { + await queue.onIdle(); + queue = new PQueue(options); +} diff --git a/app/src/components/register.ts b/app/src/components/register.ts index f3ee2875b2..472436dfde 100644 --- a/app/src/components/register.ts +++ b/app/src/components/register.ts @@ -29,6 +29,7 @@ import VForm from './v-form'; import VHover from './v-hover/'; import VHighlight from './v-highlight.vue'; import VIcon from './v-icon/'; +import VImage from './v-image.vue'; import VIconFile from './v-icon-file.vue'; import VInfo from './v-info/'; import VInput from './v-input/'; @@ -81,6 +82,7 @@ export function registerComponents(app: App): void { app.component('VHover', VHover); app.component('VHighlight', VHighlight); app.component('VIcon', VIcon); + app.component('VImage', VImage); app.component('VIconFile', VIconFile); app.component('VInfo', VInfo); app.component('VInput', VInput); diff --git a/app/src/components/v-image.vue b/app/src/components/v-image.vue new file mode 100644 index 0000000000..9ddda3ec82 --- /dev/null +++ b/app/src/components/v-image.vue @@ -0,0 +1,87 @@ + + + + + diff --git a/app/src/displays/file/file.vue b/app/src/displays/file/file.vue index 54c8b3fa95..4a5dee0617 100644 --- a/app/src/displays/file/file.vue +++ b/app/src/displays/file/file.vue @@ -1,5 +1,5 @@