From bb99704069fd4a1c8e6a3866b1c1e7b9d1b11e90 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Wed, 17 Aug 2022 16:03:44 +0200 Subject: [PATCH 01/12] Init --- config/config.json.dist | 11 ++++++++- config/config.json.sample-ocis | 11 ++++++++- packages/web-app-files/src/index.js | 11 +++------ .../web-app-files/src/services/thumbnail.ts | 23 +++++++------------ packages/web-app-files/src/store/actions.ts | 6 ++--- packages/web-runtime/src/store/config.js | 7 ------ 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/config/config.json.dist b/config/config.json.dist index 3c8094d1142..e96b1cb8ca5 100644 --- a/config/config.json.dist +++ b/config/config.json.dist @@ -14,5 +14,14 @@ "search", "text-editor" ], - "applications" : [] + "applications" : [], + "options" : { + "previewFileMimeTypes" : [ + "image/png", + "image/jpg", + "image/jpeg", + "image/gif", + "text/plain" + ] + } } diff --git a/config/config.json.sample-ocis b/config/config.json.sample-ocis index 4ec0934d259..de62b0704bb 100644 --- a/config/config.json.sample-ocis +++ b/config/config.json.sample-ocis @@ -23,5 +23,14 @@ "id": "settings", "path": "https://localhost:9200/settings.js" } - ] + ], + "options" : { + "previewFileMimeTypes" : [ + "image/png", + "image/jpg", + "image/jpeg", + "image/gif", + "text/plain" + ] + } } diff --git a/packages/web-app-files/src/index.js b/packages/web-app-files/src/index.js index aa4fba86f2b..bd516e168a4 100644 --- a/packages/web-app-files/src/index.js +++ b/packages/web-app-files/src/index.js @@ -136,13 +136,8 @@ export default { } ]) ) - // FIXME: Remove mock data - thumbnailService.initialize( - get(store, 'getters.capabilities.files.thumbnail', { - enabled: true, - version: 'v0.1', - supportedMimeTypes: ['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'text/plain'] - }) - ) + + console.log(store.getters) + thumbnailService.initialize(['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'text/plain']) } } diff --git a/packages/web-app-files/src/services/thumbnail.ts b/packages/web-app-files/src/services/thumbnail.ts index aa7b6dcab61..7a718d18d05 100644 --- a/packages/web-app-files/src/services/thumbnail.ts +++ b/packages/web-app-files/src/services/thumbnail.ts @@ -1,26 +1,19 @@ -interface ThumbnailCapability { - enabled: boolean - version: string // version is just a major version, e.g. `v2` - supportedMimeTypes: string[] -} - export class ThumbnailService { - serverUrl: string - capability?: ThumbnailCapability + supportedMimeTypes: string[] - public initialize(thumbnailCapability: ThumbnailCapability = null): void { - this.capability = thumbnailCapability + public initialize(supportedMimeTypes: string[]): void { + this.supportedMimeTypes = supportedMimeTypes.map((mimeType) => mimeType.toLowerCase()) } public get available(): boolean { - return !!this.capability?.version - } - - private get supportedMimeTypes() { - return this.capability?.supportedMimeTypes || [] + return true } public isMimetypeSupported(mimeType: string, onlyImages = false) { + if (!this.supportedMimeTypes.length) { + return true + } + const mimeTypes = this.getSupportedMimeTypes(onlyImages ? 'image/' : null) return mimeTypes.includes(mimeType) } diff --git a/packages/web-app-files/src/store/actions.ts b/packages/web-app-files/src/store/actions.ts index 7457b847106..b12c34236b9 100644 --- a/packages/web-app-files/src/store/actions.ts +++ b/packages/web-app-files/src/store/actions.ts @@ -19,6 +19,7 @@ import { ShareTypes } from 'web-client/src/helpers/share' import { sortSpaceMembers } from '../helpers/space' import get from 'lodash-es/get' import { ClipboardActions } from '../helpers/clipboardActions' +import { thumbnailService } from '../services' const allowSharePermissions = (getters) => { return get(getters, `capabilities.files_sharing.resharing`, true) @@ -738,10 +739,7 @@ export default { }, async loadPreview({ commit, rootGetters }, { resource, isPublic, dimensions, type }) { - if ( - rootGetters.previewFileExtensions.length && - !rootGetters.previewFileExtensions.includes(resource.extension.toLowerCase()) - ) { + if (!thumbnailService.isMimetypeSupported(resource.mimeType)) { return } diff --git a/packages/web-runtime/src/store/config.js b/packages/web-runtime/src/store/config.js index 10cb3e31210..dfad5e83370 100644 --- a/packages/web-runtime/src/store/config.js +++ b/packages/web-runtime/src/store/config.js @@ -52,7 +52,6 @@ const state = { showAllOnLoad: false } }, - previewFileExtensions: [], runningOnEos: false, cernFeatures: false, sharingRecipientsPerPage: 200 @@ -110,12 +109,6 @@ const getters = { configuration: (state) => { return state }, - previewFileExtensions: (state) => { - const extensions = state.options.previewFileExtensions - return (Array.isArray(extensions) ? extensions : []) - .filter(Boolean) - .map((ext) => ext.toLowerCase()) - }, homeFolder: (state, rootGetters) => { if (isEmpty(state.options.homeFolder)) { return '/' From 3d900bcd1c838d9e23e83d6d5902bbde585ff49f Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Wed, 17 Aug 2022 16:17:37 +0200 Subject: [PATCH 02/12] Improve --- packages/web-app-files/src/index.js | 4 +--- packages/web-app-files/src/services/thumbnail.ts | 2 +- packages/web-runtime/src/store/config.js | 7 +++++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/web-app-files/src/index.js b/packages/web-app-files/src/index.js index bd516e168a4..ada097903de 100644 --- a/packages/web-app-files/src/index.js +++ b/packages/web-app-files/src/index.js @@ -136,8 +136,6 @@ export default { } ]) ) - - console.log(store.getters) - thumbnailService.initialize(['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'text/plain']) + thumbnailService.initialize(store.getters.configuration?.options?.previewFileMimeTypes || []) } } diff --git a/packages/web-app-files/src/services/thumbnail.ts b/packages/web-app-files/src/services/thumbnail.ts index 7a718d18d05..f0b03d01635 100644 --- a/packages/web-app-files/src/services/thumbnail.ts +++ b/packages/web-app-files/src/services/thumbnail.ts @@ -2,7 +2,7 @@ export class ThumbnailService { supportedMimeTypes: string[] public initialize(supportedMimeTypes: string[]): void { - this.supportedMimeTypes = supportedMimeTypes.map((mimeType) => mimeType.toLowerCase()) + this.supportedMimeTypes = supportedMimeTypes } public get available(): boolean { diff --git a/packages/web-runtime/src/store/config.js b/packages/web-runtime/src/store/config.js index dfad5e83370..290f50c94d2 100644 --- a/packages/web-runtime/src/store/config.js +++ b/packages/web-runtime/src/store/config.js @@ -52,6 +52,7 @@ const state = { showAllOnLoad: false } }, + previewFileMimeTypes: [], runningOnEos: false, cernFeatures: false, sharingRecipientsPerPage: 200 @@ -109,6 +110,12 @@ const getters = { configuration: (state) => { return state }, + previewFileMimeTypes: (state) => { + const extensions = state.options.previewFileMimeTypes + return (Array.isArray(extensions) ? extensions : []) + .filter(Boolean) + .map((ext) => ext.toLowerCase()) + }, homeFolder: (state, rootGetters) => { if (isEmpty(state.options.homeFolder)) { return '/' From e1b7d7e2d315604e5f4dfc3c01067c507c9b80e5 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Wed, 17 Aug 2022 16:21:33 +0200 Subject: [PATCH 03/12] Update getting-started.md --- docs/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 09e7a840bb4..074651cdf72 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -47,7 +47,7 @@ variables of the user object to come up with a user specific home path. This use substring of a value of the authenticated user. Examples are `/Shares`, `/{{.Id}}` and `/{{substr 0 3 .Id}}/{{.Id}`. - `options.disablePreviews` Set this option to `true` to disable previews in all the different file listing views. The only list view that is not affected by this is the trash bin, as that doesn't allow showing previews at all. -- `options.previewFileExtensions` Specifies which filetypes will be previewed in the ui. For example to only preview jpg and txt files set this option to `["jpg", "txt"]`. +- `options.previewFileMimeTypes` Specifies which mimeTypes will be previewed in the ui. For example to only preview jpg and txt files set this option to `["image/jpg", "text/plain"]`. - `options.disableFeedbackLink` Set this option to `true` to disable the feedback link in the topbar. Keeping it enabled (value `false` or absence of the option) allows ownCloud to get feedback from your user base through a dedicated survey website. - `options.feedbackLink` This accepts an object with the following optional fields to customize the feedback link in the topbar: From fd6a06f49da76ff0873b9305a015e99208d0f5d7 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Wed, 17 Aug 2022 16:25:00 +0200 Subject: [PATCH 04/12] Ren --- packages/web-runtime/src/store/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web-runtime/src/store/config.js b/packages/web-runtime/src/store/config.js index 290f50c94d2..e5c7f29632b 100644 --- a/packages/web-runtime/src/store/config.js +++ b/packages/web-runtime/src/store/config.js @@ -111,8 +111,8 @@ const getters = { return state }, previewFileMimeTypes: (state) => { - const extensions = state.options.previewFileMimeTypes - return (Array.isArray(extensions) ? extensions : []) + const mimeTypes = state.options.previewFileMimeTypes + return (Array.isArray(mimeTypes) ? mimeTypes : []) .filter(Boolean) .map((ext) => ext.toLowerCase()) }, From 26fac6248746ad7d36f0106f4ba267f35475e4ea Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Wed, 17 Aug 2022 16:26:52 +0200 Subject: [PATCH 05/12] Ren --- docs/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 074651cdf72..3da44ab1d92 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -47,7 +47,7 @@ variables of the user object to come up with a user specific home path. This use substring of a value of the authenticated user. Examples are `/Shares`, `/{{.Id}}` and `/{{substr 0 3 .Id}}/{{.Id}`. - `options.disablePreviews` Set this option to `true` to disable previews in all the different file listing views. The only list view that is not affected by this is the trash bin, as that doesn't allow showing previews at all. -- `options.previewFileMimeTypes` Specifies which mimeTypes will be previewed in the ui. For example to only preview jpg and txt files set this option to `["image/jpg", "text/plain"]`. +- `options.previewFileMimeTypes` Specifies which mimeTypes will be previewed in the ui. For example to only preview jpg and text files set this option to `["image/jpg", "text/plain"]`. - `options.disableFeedbackLink` Set this option to `true` to disable the feedback link in the topbar. Keeping it enabled (value `false` or absence of the option) allows ownCloud to get feedback from your user base through a dedicated survey website. - `options.feedbackLink` This accepts an object with the following optional fields to customize the feedback link in the topbar: From 4383b807dd5f6bd73cc7fb50463e180902951053 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Wed, 17 Aug 2022 16:35:00 +0200 Subject: [PATCH 06/12] Fix init chain --- packages/web-app-files/src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/web-app-files/src/index.js b/packages/web-app-files/src/index.js index ada097903de..001f12c213d 100644 --- a/packages/web-app-files/src/index.js +++ b/packages/web-app-files/src/index.js @@ -136,6 +136,10 @@ export default { } ]) ) - thumbnailService.initialize(store.getters.configuration?.options?.previewFileMimeTypes || []) + thumbnailService.initialize( + store.getters.configuration?.options?.previewFileMimeTypes || + store.capabilities?.files?.thumbnail?.supportedMimeTypes || + [] + ) } } From 55ae405bbce7d073a37b9a57b2392d57f2e57413 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Wed, 17 Aug 2022 17:01:24 +0200 Subject: [PATCH 07/12] Improve --- packages/web-app-files/src/index.js | 4 +++- packages/web-app-files/src/services/thumbnail.ts | 10 ++++------ packages/web-app-files/src/store/actions.ts | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/web-app-files/src/index.js b/packages/web-app-files/src/index.js index 001f12c213d..d5e37413be2 100644 --- a/packages/web-app-files/src/index.js +++ b/packages/web-app-files/src/index.js @@ -139,7 +139,9 @@ export default { thumbnailService.initialize( store.getters.configuration?.options?.previewFileMimeTypes || store.capabilities?.files?.thumbnail?.supportedMimeTypes || - [] + [], + // FIXME: use enabled flag from capabilities if available + true ) } } diff --git a/packages/web-app-files/src/services/thumbnail.ts b/packages/web-app-files/src/services/thumbnail.ts index f0b03d01635..7ac7bc6bc8f 100644 --- a/packages/web-app-files/src/services/thumbnail.ts +++ b/packages/web-app-files/src/services/thumbnail.ts @@ -1,12 +1,10 @@ export class ThumbnailService { - supportedMimeTypes: string[] + supportedMimeTypes: string[] = [] + available = false - public initialize(supportedMimeTypes: string[]): void { + public initialize(supportedMimeTypes: string[], available: boolean): void { this.supportedMimeTypes = supportedMimeTypes - } - - public get available(): boolean { - return true + this.available = available } public isMimetypeSupported(mimeType: string, onlyImages = false) { diff --git a/packages/web-app-files/src/store/actions.ts b/packages/web-app-files/src/store/actions.ts index b12c34236b9..883539bd663 100644 --- a/packages/web-app-files/src/store/actions.ts +++ b/packages/web-app-files/src/store/actions.ts @@ -739,7 +739,10 @@ export default { }, async loadPreview({ commit, rootGetters }, { resource, isPublic, dimensions, type }) { - if (!thumbnailService.isMimetypeSupported(resource.mimeType)) { + if ( + !this.thumbnailService.available || + !thumbnailService.isMimetypeSupported(resource.mimeType) + ) { return } From 06bdbf15efd6249a954b94949b09cb10eaf4a64c Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Wed, 17 Aug 2022 17:23:09 +0200 Subject: [PATCH 08/12] restore --- packages/web-app-files/src/index.js | 11 +++++---- .../web-app-files/src/services/thumbnail.ts | 23 +++++++++++++++---- packages/web-app-files/src/store/actions.ts | 5 +--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/web-app-files/src/index.js b/packages/web-app-files/src/index.js index d5e37413be2..ae855b0f13a 100644 --- a/packages/web-app-files/src/index.js +++ b/packages/web-app-files/src/index.js @@ -136,12 +136,13 @@ export default { } ]) ) + // FIXME: Use capability data only as soon as available thumbnailService.initialize( - store.getters.configuration?.options?.previewFileMimeTypes || - store.capabilities?.files?.thumbnail?.supportedMimeTypes || - [], - // FIXME: use enabled flag from capabilities if available - true + get(store, 'getters.capabilities.files.thumbnail', { + enabled: true, + version: 'v0.1', + supportedMimeTypes: store.getters.configuration?.options?.previewFileMimeTypes || [] + }) ) } } diff --git a/packages/web-app-files/src/services/thumbnail.ts b/packages/web-app-files/src/services/thumbnail.ts index 7ac7bc6bc8f..ad495486ecd 100644 --- a/packages/web-app-files/src/services/thumbnail.ts +++ b/packages/web-app-files/src/services/thumbnail.ts @@ -1,10 +1,23 @@ +interface ThumbnailCapability { + enabled: boolean + version: string // version is just a major version, e.g. `v2` + supportedMimeTypes: string[] +} + export class ThumbnailService { - supportedMimeTypes: string[] = [] - available = false + serverUrl: string + capability?: ThumbnailCapability + + public initialize(thumbnailCapability: ThumbnailCapability = null): void { + this.capability = thumbnailCapability + } + + public get available(): boolean { + return !!this.capability?.version + } - public initialize(supportedMimeTypes: string[], available: boolean): void { - this.supportedMimeTypes = supportedMimeTypes - this.available = available + private get supportedMimeTypes() { + return this.capability?.supportedMimeTypes || [] } public isMimetypeSupported(mimeType: string, onlyImages = false) { diff --git a/packages/web-app-files/src/store/actions.ts b/packages/web-app-files/src/store/actions.ts index 883539bd663..66db6c33ac1 100644 --- a/packages/web-app-files/src/store/actions.ts +++ b/packages/web-app-files/src/store/actions.ts @@ -739,10 +739,7 @@ export default { }, async loadPreview({ commit, rootGetters }, { resource, isPublic, dimensions, type }) { - if ( - !this.thumbnailService.available || - !thumbnailService.isMimetypeSupported(resource.mimeType) - ) { + if (!thumbnailService.available || !thumbnailService.isMimetypeSupported(resource.mimeType)) { return } From 78e801655356f8f1da2d6996532ae0d98e5ee848 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Wed, 17 Aug 2022 17:33:46 +0200 Subject: [PATCH 09/12] Add changelog item --- .../unreleased/bugfix-ocis-load-only-supported-thumbnails | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/unreleased/bugfix-ocis-load-only-supported-thumbnails diff --git a/changelog/unreleased/bugfix-ocis-load-only-supported-thumbnails b/changelog/unreleased/bugfix-ocis-load-only-supported-thumbnails new file mode 100644 index 00000000000..679b2fbc034 --- /dev/null +++ b/changelog/unreleased/bugfix-ocis-load-only-supported-thumbnails @@ -0,0 +1,6 @@ +Bugfix: OCIS Load only supported thumbnails + +We've fixed a bug where web was trying to load thumbnails for files that are not supported by the OCIS backend. +Due to this change we avoid unnecessary requests. + +https://github.com/owncloud/web/pull/7474 From 2475f55c32ce328742ca908c3cc6fe7e520ef94d Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Thu, 18 Aug 2022 13:31:05 +0200 Subject: [PATCH 10/12] React on code review --- .../unreleased/bugfix-load-only-supported-thumbnails | 6 ++++++ .../bugfix-ocis-load-only-supported-thumbnails | 6 ------ config/config.json.dist | 11 +---------- docs/getting-started.md | 2 +- 4 files changed, 8 insertions(+), 17 deletions(-) create mode 100644 changelog/unreleased/bugfix-load-only-supported-thumbnails delete mode 100644 changelog/unreleased/bugfix-ocis-load-only-supported-thumbnails diff --git a/changelog/unreleased/bugfix-load-only-supported-thumbnails b/changelog/unreleased/bugfix-load-only-supported-thumbnails new file mode 100644 index 00000000000..f0903b6f5eb --- /dev/null +++ b/changelog/unreleased/bugfix-load-only-supported-thumbnails @@ -0,0 +1,6 @@ +Bugfix: Load only supported thumbnails (configurable) + +We've fixed a bug where web was trying to load thumbnails for files that are not supported. +Due to configurable values, we avoid unnecessary requests. + +https://github.com/owncloud/web/pull/7474 diff --git a/changelog/unreleased/bugfix-ocis-load-only-supported-thumbnails b/changelog/unreleased/bugfix-ocis-load-only-supported-thumbnails deleted file mode 100644 index 679b2fbc034..00000000000 --- a/changelog/unreleased/bugfix-ocis-load-only-supported-thumbnails +++ /dev/null @@ -1,6 +0,0 @@ -Bugfix: OCIS Load only supported thumbnails - -We've fixed a bug where web was trying to load thumbnails for files that are not supported by the OCIS backend. -Due to this change we avoid unnecessary requests. - -https://github.com/owncloud/web/pull/7474 diff --git a/config/config.json.dist b/config/config.json.dist index e96b1cb8ca5..3c8094d1142 100644 --- a/config/config.json.dist +++ b/config/config.json.dist @@ -14,14 +14,5 @@ "search", "text-editor" ], - "applications" : [], - "options" : { - "previewFileMimeTypes" : [ - "image/png", - "image/jpg", - "image/jpeg", - "image/gif", - "text/plain" - ] - } + "applications" : [] } diff --git a/docs/getting-started.md b/docs/getting-started.md index 3da44ab1d92..f5eb8c928f2 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -47,7 +47,7 @@ variables of the user object to come up with a user specific home path. This use substring of a value of the authenticated user. Examples are `/Shares`, `/{{.Id}}` and `/{{substr 0 3 .Id}}/{{.Id}`. - `options.disablePreviews` Set this option to `true` to disable previews in all the different file listing views. The only list view that is not affected by this is the trash bin, as that doesn't allow showing previews at all. -- `options.previewFileMimeTypes` Specifies which mimeTypes will be previewed in the ui. For example to only preview jpg and text files set this option to `["image/jpg", "text/plain"]`. +- `options.previewFileMimeTypes` Specifies which mimeTypes will be previewed in the ui. For example to only preview jpg and text files set this option to `["image/jpeg", "text/plain"]`. - `options.disableFeedbackLink` Set this option to `true` to disable the feedback link in the topbar. Keeping it enabled (value `false` or absence of the option) allows ownCloud to get feedback from your user base through a dedicated survey website. - `options.feedbackLink` This accepts an object with the following optional fields to customize the feedback link in the topbar: From b605ce94c64adb9653d7f3b994fe4e49d96a5b9d Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Thu, 18 Aug 2022 13:36:25 +0200 Subject: [PATCH 11/12] Remove image/jpg as not an offical mimeType --- config/config.json.sample-ocis | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/config.json.sample-ocis b/config/config.json.sample-ocis index de62b0704bb..f438ea946b1 100644 --- a/config/config.json.sample-ocis +++ b/config/config.json.sample-ocis @@ -26,10 +26,9 @@ ], "options" : { "previewFileMimeTypes" : [ + "image/gif", "image/png", - "image/jpg", "image/jpeg", - "image/gif", "text/plain" ] } From 7b42e9ad35f460e9b4533ebe6c2c60a6aefd3895 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Thu, 18 Aug 2022 13:50:49 +0200 Subject: [PATCH 12/12] Adjust docker config --- dev/docker/ocis.web.config.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dev/docker/ocis.web.config.json b/dev/docker/ocis.web.config.json index d564335f617..a1b3b0298c6 100644 --- a/dev/docker/ocis.web.config.json +++ b/dev/docker/ocis.web.config.json @@ -16,7 +16,13 @@ "shares": { "showAllOnLoad": true } - } + }, + "previewFileMimeTypes": [ + "image/gif", + "image/png", + "image/jpeg", + "text/plain" + ] }, "apps": [ "files",