import { IRequest } from "@fluidframework/core-interfaces" ; import { IUrlResolver , IResolvedUrl } from "@fluidframework/driver-definitions" ; import { IOdspAuthRequestInfo , getDriveItemByRootFileName , } from "@fluidframework/odsp-doclib-utils" ; import { OdspDriverUrlResolver , createOdspUrl , createOdspCreateContainerRequest } from "@fluidframework/odsp-driver" ; export class OdspUrlResolver implements IUrlResolver { private readonly driverUrlResolver = new OdspDriverUrlResolver ( ) ; constructor ( private readonly server , private readonly authRequestInfo ) { } public async resolve ( request ) { try { const resolvedUrl = await this . driverUrlResolver . resolve ( request ) ; return resolvedUrl ; } catch ( error ) { } const url = new URL ( request . url ) ; const fullPath = url . pathname . substr ( 1 ) ; const documentId = fullPath . split ( "/" ) [ 0 ] ; const dataStorePath = fullPath . slice ( documentId . length + 1 ) ; const filePath = this . formFilePath ( documentId ) ; const { driveId , itemId } = await getDriveItemByRootFileName ( this . server , "" , filePath , this . authRequestInfo , true ) ; const odspUrl = createOdspUrl ( { siteUrl : `https://${ this . server }` , driveId , itemId , dataStorePath } ) ; return this . driverUrlResolver . resolve ( { url : odspUrl , headers : request . headers } ) ; } private formFilePath ( documentId ) { const encoded = encodeURIComponent ( `${ documentId }.fluid` ) ; return `/r11s/${ encoded }` ; } public async getAbsoluteUrl ( resolvedUrl , relativeUrl ) { return this . driverUrlResolver . getAbsoluteUrl ( resolvedUrl , relativeUrl ) ; } public async createCreateNewRequest ( fileName ) { const filePath = "/r11s/" ; const driveItem = await getDriveItemByRootFileName ( this . server , "" , filePath , this . authRequestInfo , false ) ; return createOdspCreateContainerRequest ( `https://${ this . server }` , driveItem . driveId , filePath , `${ fileName }.fluid` ) ; } }