mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
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>
This commit is contained in:
parent
8d84dc33df
commit
52ceb40c05
4 changed files with 18 additions and 12 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
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