diff --git a/apps/files_versions/src/components/Version.vue b/apps/files_versions/src/components/Version.vue index c9edbe9dc5a91..648cdb68e86a4 100644 --- a/apps/files_versions/src/components/Version.vue +++ b/apps/files_versions/src/components/Version.vue @@ -135,7 +135,7 @@ import { Permission, formatFileSize } from '@nextcloud/files' import { loadState } from '@nextcloud/initial-state' import { t } from '@nextcloud/l10n' import { joinPaths } from '@nextcloud/paths' -import { getRootUrl, generateUrl } from '@nextcloud/router' +import { getRootUrl } from '@nextcloud/router' import { defineComponent } from 'vue' import axios from '@nextcloud/axios' @@ -216,7 +216,6 @@ export default defineComponent({ previewLoaded: false, previewErrored: false, capabilities: loadState('core', 'capabilities', { files: { version_labeling: false, version_deletion: false } }), - versionAuthor: '' as string | null, } }, @@ -307,24 +306,6 @@ export default defineComponent({ this.$emit('delete', this.version) }, - async fetchDisplayName() { - this.versionAuthor = null - if (!this.version.author) { - return - } - - if (this.version.author === getCurrentUser()?.uid) { - this.versionAuthor = t('files_versions', 'You') - } else { - try { - const { data } = await axios.post(generateUrl('/displaynames'), { users: [this.version.author] }) - this.versionAuthor = data.users[this.version.author] - } catch (error) { - logger.warn('Could not load user display name', { error }) - } - } - }, - click() { if (!this.canView) { window.location.href = this.downloadURL diff --git a/apps/files_versions/src/utils/versions.ts b/apps/files_versions/src/utils/versions.ts index 866bde87dac95..2a7168cfb7977 100644 --- a/apps/files_versions/src/utils/versions.ts +++ b/apps/files_versions/src/utils/versions.ts @@ -27,6 +27,7 @@ import { generateRemoteUrl, generateUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' import { joinPaths, encodePath } from '@nextcloud/paths' import moment from '@nextcloud/moment' +import axios from '@nextcloud/axios' import client from '../utils/davClient.js' import davRequest from '../utils/davRequest.js' @@ -36,6 +37,7 @@ export interface Version { fileId: string, // The id of the file associated to the version. label: string, // 'Current version' or '' author: string|null, // UID for the author of the version + authorName: string|null, // Display name of the author filename: string, // File name relative to the version DAV endpoint basename: string, // A base name generated from the mtime mime: string, // Empty for the current version, else the actual mime type of the version @@ -46,7 +48,7 @@ export interface Version { permissions: string, // Only readable: 'R' previewUrl: string, // Preview URL of the version url: string, // Download URL of the version - source: string, // The WebDAV endpoint of the ressource + source: string, // The WebDAV endpoint of the resource fileVersion: string|null, // The version id, null for the current version } @@ -59,10 +61,22 @@ export async function fetchVersions(fileInfo: any): Promise { details: true, }) as ResponseDataDetailed - return response.data + const versions = response.data // Filter out root .filter(({ mime }) => mime !== '') .map(version => formatVersion(version, fileInfo)) + + const authorIds = new Set(versions.map(version => version.author)) + const authors = await axios.post(generateUrl('/displaynames'), { users: [...authorIds] }) + + for (const version of versions) { + const author = authors.data.users[version.author] + if (author) { + version.authorName = author + } + } + + return versions } catch (exception) { logger.error('Could not fetch version', { exception }) throw exception @@ -109,6 +123,7 @@ function formatVersion(version: any, fileInfo: any): Version { // If version-label is defined make sure it is a string (prevent issue if the label is a number an PHP returns a number then) label: version.props['version-label'] && String(version.props['version-label']), author: version.props['version-author'] ?? null, + authorName: null, filename: version.filename, basename: moment(mtime).format('LLL'), mime: version.mime,