Skip to content

Commit

Permalink
refactor(files): migrate to @nextcloud/sharing
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <[email protected]>
  • Loading branch information
ShGKme committed Oct 17, 2024
1 parent 60cf5a2 commit 9779bd6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
6 changes: 3 additions & 3 deletions apps/files/src/components/TemplatePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<script>
import { encodePath } from '@nextcloud/paths'
import { generateUrl } from '@nextcloud/router'
import { getToken, isPublic } from '../utils/davUtils.ts'
import { isPublicShare, getSharingToken } from '@nextcloud/sharing/public'
// preview width generation
const previewWidth = 256
Expand Down Expand Up @@ -107,8 +107,8 @@ export default {
return this.previewUrl
}
// TODO: find a nicer standard way of doing this?
if (isPublic()) {
return generateUrl(`/apps/files_sharing/publicpreview/${getToken()}?fileId=${this.fileid}&file=${encodePath(this.filename)}&x=${previewWidth}&y=${previewWidth}&a=1`)
if (isPublicShare()) {
return generateUrl(`/apps/files_sharing/publicpreview/${getSharingToken()}?fileId=${this.fileid}&file=${encodePath(this.filename)}&x=${previewWidth}&y=${previewWidth}&a=1`)
}
return generateUrl(`/core/preview?fileId=${this.fileid}&x=${previewWidth}&y=${previewWidth}&a=1`)
},
Expand Down
18 changes: 0 additions & 18 deletions apps/files/src/utils/davUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { getCurrentUser } from '@nextcloud/auth'
import { t } from '@nextcloud/l10n'
import type { WebDAVClientError } from 'webdav'

/**
* Check whether this is a public share
* @return {boolean} Whether this is a public share
*/
export function isPublic() {
return !getCurrentUser()
}

/**
* Get the sharing token
* @return {string|null} The sharing token
*/
export function getToken() {
const tokenElement = document.getElementById('sharingToken') as (HTMLInputElement | null)
return tokenElement?.value
}

/**
* Whether error is a WebDAVClientError
* @param error - Any exception
Expand Down

0 comments on commit 9779bd6

Please sign in to comment.