Skip to content

Commit

Permalink
Fix: allow to name the current version
Browse files Browse the repository at this point in the history
We only need to change the filename
of the current version for the viewer

Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Sep 7, 2023
1 parent 8d84dc3 commit 52ceb40
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
10 changes: 3 additions & 7 deletions apps/files_versions/src/utils/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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}`,
Expand All @@ -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,
}
}
Expand Down
14 changes: 12 additions & 2 deletions apps/files_versions/src/views/VersionTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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),
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.

0 comments on commit 52ceb40

Please sign in to comment.