import { assert , fromBase64ToUtf8 } from "@fluidframework/common-utils" ; import { IRequest } from "@fluidframework/core-interfaces" ; import { IResolvedUrl , IUrlResolver } from "@fluidframework/driver-definitions" ; import { createOdspUrl , OdspDriverUrlResolver } from "@fluidframework/odsp-driver" ; import { IOdspUrlParts } from "@fluidframework/odsp-driver-definitions" ; const fluidOfficeAndOneNoteServers = [ "dev.fluidpreview.office.net" , "fluidpreview.office.net" , "www.onenote.com" , ] ; export class FluidAppOdspUrlResolver implements IUrlResolver { public async resolve ( request ) { const reqUrl = new URL ( request . url ) ; const server = reqUrl . hostname . toLowerCase ( ) ; let contents ; if ( fluidOfficeAndOneNoteServers . includes ( server ) ) { contents = await initializeFluidOfficeOrOneNote ( reqUrl ) ; } else if ( server === "www.office.com" ) { const getRequiredParam = ( name ) : string => { const value = reqUrl . searchParams . get ( name ) ; assert ( ! ! value , 0x097 ) ; return value ; } ; contents = { driveId : getRequiredParam ( "drive" ) , itemId : getRequiredParam ( "item" ) , siteUrl : getRequiredParam ( "siteUrl" ) } ; } else { return undefined ; } if ( ! contents ) { return undefined ; } const urlToBeResolved = createOdspUrl ( { ... contents , dataStorePath : "" } ) ; const odspDriverUrlResolver = new OdspDriverUrlResolver ( ) ; return odspDriverUrlResolver . resolve ( { url : urlToBeResolved } ) ; } public async getAbsoluteUrl ( resolvedUrl , relativeUrl ) { throw new Error ( "Not implemented" ) ; } } async function initializeFluidOfficeOrOneNote ( urlSource ) { const pathname = urlSource . pathname ; const siteDriveItemMatch = pathname . match ( /\/(p|preview|meetingnotes)\/([^/]*)\/([^/]*)\/([^/]*)/ ) ; if ( siteDriveItemMatch === null ) { return undefined ; } const site = decodeURIComponent ( siteDriveItemMatch [ 2 ] ) ; const decodedSite = fromBase64ToUtf8 ( site ) ; const storageType = decodedSite . split ( ":" ) [ 0 ] ; const expectedStorageType = "spo" ; if ( storageType !== expectedStorageType ) { return Promise . reject ( new Error ( `Unexpected storage type ${ storageType }, expected: ${ expectedStorageType }` ) ) ; } const siteUrl = decodedSite . substring ( storageType . length + 1 ) ; const driveId = decodeURIComponent ( siteDriveItemMatch [ 3 ] ) ; const itemId = decodeURIComponent ( siteDriveItemMatch [ 4 ] ) ; return { siteUrl , driveId , itemId } ; }