Skip to content

Commit

Permalink
Thumbnail service redesign (#7474)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan authored Aug 18, 2022
1 parent f305c57 commit b8e5df4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-load-only-supported-thumbnails
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion config/config.json.sample-ocis
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
"id": "settings",
"path": "https://localhost:9200/settings.js"
}
]
],
"options" : {
"previewFileMimeTypes" : [
"image/gif",
"image/png",
"image/jpeg",
"text/plain"
]
}
}
8 changes: 7 additions & 1 deletion dev/docker/ocis.web.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
"shares": {
"showAllOnLoad": true
}
}
},
"previewFileMimeTypes": [
"image/gif",
"image/png",
"image/jpeg",
"text/plain"
]
},
"apps": [
"files",
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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:
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ export default {
}
])
)
// FIXME: Remove mock data
// FIXME: Use capability data only as soon as available
thumbnailService.initialize(
get(store, 'getters.capabilities.files.thumbnail', {
enabled: true,
version: 'v0.1',
supportedMimeTypes: ['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'text/plain']
supportedMimeTypes: store.getters.configuration?.options?.previewFileMimeTypes || []
})
)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/web-app-files/src/services/thumbnail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class ThumbnailService {
}

public isMimetypeSupported(mimeType: string, onlyImages = false) {
if (!this.supportedMimeTypes.length) {
return true
}

const mimeTypes = this.getSupportedMimeTypes(onlyImages ? 'image/' : null)
return mimeTypes.includes(mimeType)
}
Expand Down
6 changes: 2 additions & 4 deletions packages/web-app-files/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -749,10 +750,7 @@ export default {
},

async loadPreview({ commit, rootGetters }, { resource, isPublic, dimensions, type }) {
if (
rootGetters.previewFileExtensions.length &&
!rootGetters.previewFileExtensions.includes(resource.extension.toLowerCase())
) {
if (!thumbnailService.available || !thumbnailService.isMimetypeSupported(resource.mimeType)) {
return
}

Expand Down
8 changes: 4 additions & 4 deletions packages/web-runtime/src/store/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const state = {
showAllOnLoad: false
}
},
previewFileExtensions: [],
previewFileMimeTypes: [],
runningOnEos: false,
cernFeatures: false,
sharingRecipientsPerPage: 200
Expand Down Expand Up @@ -110,9 +110,9 @@ const getters = {
configuration: (state) => {
return state
},
previewFileExtensions: (state) => {
const extensions = state.options.previewFileExtensions
return (Array.isArray(extensions) ? extensions : [])
previewFileMimeTypes: (state) => {
const mimeTypes = state.options.previewFileMimeTypes
return (Array.isArray(mimeTypes) ? mimeTypes : [])
.filter(Boolean)
.map((ext) => ext.toLowerCase())
},
Expand Down

0 comments on commit b8e5df4

Please sign in to comment.