aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions/src
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2023-09-07 12:26:02 +0200
committerLouis Chemineau <louis@chmn.me>2023-09-07 15:47:59 +0200
commit52ceb40c053d0f424e8df56bd3bb0b736dda40d2 (patch)
tree4721e23e463812d8cfb2314739f03fa5a2605c3f /apps/files_versions/src
parent8d84dc33df0f1e0993fbc79cc52ac868bb73d7a1 (diff)
downloadnextcloud-server-52ceb40c053d0f424e8df56bd3bb0b736dda40d2.tar.gz
nextcloud-server-52ceb40c053d0f424e8df56bd3bb0b736dda40d2.zip
Fix: allow to name the current version
We only need to change the filename of the current version for the viewer Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'apps/files_versions/src')
-rw-r--r--apps/files_versions/src/utils/versions.js10
-rw-r--r--apps/files_versions/src/views/VersionTab.vue14
2 files changed, 15 insertions, 9 deletions
diff --git a/apps/files_versions/src/utils/versions.js b/apps/files_versions/src/utils/versions.js
index 7f5ccfc0e69..ee49a369d21 100644
--- a/apps/files_versions/src/utils/versions.js
+++ b/apps/files_versions/src/utils/versions.js
@@ -29,7 +29,6 @@ import { encodeFilePath } from '../../../files/src/utils/fileUtils.js'
import client from '../utils/davClient.js'
import davRequest from '../utils/davRequest.js'
import logger from '../utils/logger.js'
-import path from 'path'
/**
* @typedef {object} Version
@@ -101,16 +100,13 @@ export async function restoreVersion(version) {
function formatVersion(version, fileInfo) {
const mtime = moment(version.lastmod).unix() * 1000
let previewUrl = ''
- let filename = ''
if (mtime === fileInfo.mtime) { // Version is the current one
- filename = path.join('files', getCurrentUser()?.uid ?? '', fileInfo.path, fileInfo.name)
previewUrl = generateUrl('/core/preview?fileId={fileId}&c={fileEtag}&x=250&y=250&forceIcon=0&a=0', {
fileId: fileInfo.id,
fileEtag: fileInfo.etag,
})
} else {
- filename = version.filename
previewUrl = generateUrl('/apps/files_versions/preview?file={file}&version={fileVersion}', {
file: joinPaths(fileInfo.path, fileInfo.name),
fileVersion: version.basename,
@@ -120,7 +116,7 @@ function formatVersion(version, fileInfo) {
return {
fileId: fileInfo.id,
label: version.props['version-label'],
- filename,
+ filename: version.filename,
basename: moment(mtime).format('LLL'),
mime: version.mime,
etag: `${version.props.getetag}`,
@@ -130,8 +126,8 @@ function formatVersion(version, fileInfo) {
permissions: 'R',
hasPreview: version.props['has-preview'] === 1,
previewUrl,
- url: joinPaths('/remote.php/dav', filename),
- source: generateRemoteUrl('dav') + encodeFilePath(filename),
+ url: joinPaths('/remote.php/dav', version.filename),
+ source: generateRemoteUrl('dav') + encodeFilePath(version.filename),
fileVersion: version.basename,
}
}
diff --git a/apps/files_versions/src/views/VersionTab.vue b/apps/files_versions/src/views/VersionTab.vue
index 178cc3e931a..2f0a983744a 100644
--- a/apps/files_versions/src/views/VersionTab.vue
+++ b/apps/files_versions/src/views/VersionTab.vue
@@ -35,11 +35,15 @@
</template>
<script>
+import path from 'path'
+
import { showError, showSuccess } from '@nextcloud/dialogs'
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
+import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
+import { getCurrentUser } from '@nextcloud/auth'
+
import { fetchVersions, deleteVersion, restoreVersion, setVersionLabel } from '../utils/versions.js'
import Version from '../components/Version.vue'
-import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
export default {
name: 'VersionTab',
@@ -249,7 +253,13 @@ export default {
// Versions previews are too small for our use case, so we override hasPreview and previewUrl
// which makes the viewer render the original file.
- const versions = this.versions.map(version => ({ ...version, hasPreview: false, previewUrl: undefined }))
+ // We also point to the original filename if the version is the current one.
+ const versions = this.versions.map(version => ({
+ ...version,
+ filename: version.mtime === this.fileInfo.mtime ? path.join('files', getCurrentUser()?.uid ?? '', fileInfo.path, fileInfo.name) : version.filename,
+ hasPreview: false,
+ previewUrl: undefined,
+ }))
OCA.Viewer.open({
fileInfo: versions.find(v => v.source === version.source),