mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
Merge pull request #54720 from nextcloud/backport/51727/stable31
[stable31] fix(files_versions): retrieve all display names with one request
This commit is contained in:
commit
ddc9baf18f
4 changed files with 33 additions and 27 deletions
|
|
@ -125,12 +125,10 @@ 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'
|
||||
import moment from '@nextcloud/moment'
|
||||
import logger from '../utils/logger'
|
||||
|
||||
import BackupRestore from 'vue-material-design-icons/BackupRestore.vue'
|
||||
import Delete from 'vue-material-design-icons/Delete.vue'
|
||||
|
|
@ -207,7 +205,6 @@ export default defineComponent({
|
|||
previewLoaded: false,
|
||||
previewErrored: false,
|
||||
capabilities: loadState('core', 'capabilities', { files: { version_labeling: false, version_deletion: false } }),
|
||||
versionAuthor: '' as string | null,
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -234,6 +231,18 @@ export default defineComponent({
|
|||
return label
|
||||
},
|
||||
|
||||
versionAuthor() {
|
||||
if (!this.version.author || !this.version.authorName) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (this.version.author === getCurrentUser()?.uid) {
|
||||
return t('files_versions', 'You')
|
||||
}
|
||||
|
||||
return this.version.authorName ?? this.version.author
|
||||
},
|
||||
|
||||
versionHumanExplicitDate(): string {
|
||||
return moment(this.version.mtime).format('LLLL')
|
||||
},
|
||||
|
|
@ -302,24 +311,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
|
||||
|
|
|
|||
|
|
@ -11,6 +11,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'
|
||||
|
|
@ -20,6 +21,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
|
||||
|
|
@ -30,7 +32,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
|
||||
}
|
||||
|
||||
|
|
@ -43,10 +45,22 @@ export async function fetchVersions(fileInfo: any): Promise<Version[]> {
|
|||
details: true,
|
||||
}) as ResponseDataDetailed<FileStat[]>
|
||||
|
||||
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
|
||||
|
|
@ -93,6 +107,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,
|
||||
|
|
|
|||
4
dist/files_versions-files_versions.js
vendored
4
dist/files_versions-files_versions.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files_versions-files_versions.js.map
vendored
2
dist/files_versions-files_versions.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue