Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions apps/files_versions/src/components/Version.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,9 @@ 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 logger from '../utils/logger'

import BackupRestore from 'vue-material-design-icons/BackupRestore.vue'
import Delete from 'vue-material-design-icons/Delete.vue'
import Download from 'vue-material-design-icons/Download.vue'
Expand Down Expand Up @@ -206,7 +203,6 @@ export default defineComponent({
previewLoaded: false,
previewErrored: false,
capabilities: loadState('core', 'capabilities', { files: { version_labeling: false, version_deletion: false } }),
versionAuthor: '' as string|null,
}
},

Expand All @@ -233,6 +229,16 @@ 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
},

downloadURL(): string {
if (this.isCurrent) {
return getRootUrl() + joinPaths('/remote.php/webdav', this.fileInfo.path, this.fileInfo.name)
Expand Down Expand Up @@ -297,24 +303,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
Expand Down
19 changes: 17 additions & 2 deletions apps/files_versions/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions dist/files_versions-files_versions.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_versions-files_versions.js.map

Large diffs are not rendered by default.

Loading