import { Logger } from "polar-shared/src/logger/Logger" ; import { GroupMemberInvitation } from "../../../web/js/datastore/sharing/db/GroupMemberInvitations" ; import { PersistenceLayer } from "../../../web/js/datastore/PersistenceLayer" ; import { BrowserDocLoader } from "../../../web/js/apps/main/doc_loaders/browser/BrowserDocLoader" ; import { LoadDocRequest } from "../../../web/js/apps/main/doc_loaders/LoadDocRequest" ; import { BackendFileRefs } from "../../../web/js/datastore/BackendFileRefs" ; const log = Logger . create ( ) ; function createInvitation ( ) { const url = new URL ( document . location . href ) ; return JSON . parse ( url . searchParams . get ( 'invitation' ) ! ) ; } async function redirectToDocumentViewer ( persistenceLayer , invitation ) { const docLoader = new BrowserDocLoader ( ( ) => persistenceLayer ) ; const docRef = invitation . docs [ 0 ] ; const { fingerprint } = docRef ; const docMeta = await persistenceLayer . getDocMeta ( fingerprint ) ; if ( ! docMeta ) { throw new Error ( "No DocMeta for fingerprint: " + fingerprint ) ; } const backendFileRef = BackendFileRefs . toBackendFileRef ( docMeta ) ! ; const loadDocRequest = { fingerprint , title : docMeta . docInfo . title || 'Untitled' , backendFileRef , newWindow : false , url : undefined } ; const docLoadRequest = docLoader . create ( loadDocRequest ) ; await docLoadRequest . load ( ) ; } async function doHandle ( ) { } doHandle ( ) . catch ( err => log . error ( "Unable to handle document share: " , err ) ) ;