Skip to content

Commit

Permalink
fix: Load viewer on public folder shares
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Knorr <[email protected]>
  • Loading branch information
juliusknorr committed Sep 11, 2024
1 parent b8ed0de commit 50b5e00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@nextcloud/initial-state": "^2.2.0",
"@nextcloud/l10n": "^3.1.0",
"@nextcloud/router": "^3.0.1",
"@nextcloud/sharing": "^0.2.3",
"@nextcloud/vue": "^8.17.1",
"@socket.io/redis-streams-adapter": "^0.2.2",
"dotenv": "^16.4.5",
Expand Down
17 changes: 10 additions & 7 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { linkTo } from '@nextcloud/router'
import { StrictMode, lazy, Suspense } from 'react'
import { createRoot } from 'react-dom'
import { loadState } from '@nextcloud/initial-state'
import { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'

import './viewer.css'

Expand All @@ -33,20 +34,21 @@ const renderApp = (rootElement, props) => {

window.EXCALIDRAW_ASSET_PATH = EXCALIDRAW_ASSET_PATH

const publicSharingToken
= document.getElementById('sharingToken')?.value || null
const publicSharingToken = getSharingToken()

if (publicSharingToken) {
if (isPublicShare()) {
handlePublicSharing(publicSharingToken)
} else {
handleNonPublicSharing()
}

handleNonPublicSharing()

// Handler functions
function handlePublicSharing(token) {
const filesTable = document.querySelector('#preview table.files-filestable')
const filesTable = document.querySelector('.files-list__table') || document.querySelector('#preview table.files-filestable')

if (filesTable) {
const Component = createWhiteboardComponent()
registerViewerHandler(Component)
return
}

Expand Down Expand Up @@ -79,7 +81,7 @@ function handleNonPublicSharing() {
if (typeof OCA.Viewer !== 'undefined') {
registerViewerHandler(Component)
} else {
alert('UNDEFINED')
console.error('Could not register whiteboard handler for viewer')
}
}

Expand Down Expand Up @@ -110,6 +112,7 @@ function createWhiteboardComponent() {
fileId: this.fileid,
isEmbedded: this.isEmbedded,
fileName: this.basename,
publicSharingToken: getSharingToken(),
})
})

Expand Down

0 comments on commit 50b5e00

Please sign in to comment.