diff --git a/package-lock.json b/package-lock.json index 877fc3f..241fe31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,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", diff --git a/package.json b/package.json index 0177c60..7e8046d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/main.tsx b/src/main.tsx index 83a2959..1bb2436 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -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' @@ -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 } @@ -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') } } @@ -110,6 +112,7 @@ function createWhiteboardComponent() { fileId: this.fileid, isEmbedded: this.isEmbedded, fileName: this.basename, + publicSharingToken: getSharingToken(), }) })