import { IResolvedUrl , IUrlResolver } from "@fluidframework/driver-definitions" ; import { IRequest } from "@fluidframework/core-interfaces" ; import { LocalResolver } from "@fluidframework/local-driver" ; import { InsecureUrlResolver } from "@fluidframework/driver-utils" ; import { ITinyliciousRouteOptions , RouteOptions } from "./loader" ; import { OdspUrlResolver } from "./odspUrlResolver" ; export const dockerUrls = { hostUrl : "http://localhost:3000" , ordererUrl : "http://localhost:3003" , storageUrl : "http://localhost:3001" } ; const defaultTinyliciousPort = 7070 ; export const tinyliciousUrls = ( options ) => { const port = options . tinyliciousPort ?? defaultTinyliciousPort ; return { hostUrl : `http://localhost:${ port }` , ordererUrl : `http://localhost:${ port }` , storageUrl : `http://localhost:${ port }` } ; } ; function getUrlResolver ( options ) { switch ( options . mode ) { case "docker" : return new InsecureUrlResolver ( dockerUrls . hostUrl , dockerUrls . ordererUrl , dockerUrls . storageUrl , options . tenantId , options . bearerSecret ) ; case "r11s" : return new InsecureUrlResolver ( options . fluidHost , options . fluidHost . replace ( "www" , "alfred" ) , options . fluidHost . replace ( "www" , "historian" ) , options . tenantId , options . bearerSecret ) ; case "tinylicious" : { const urls = tinyliciousUrls ( options ) ; return new InsecureUrlResolver ( urls . hostUrl , urls . ordererUrl , urls . storageUrl , "tinylicious" , options . bearerSecret ) ; } case "spo" : case "spo-df" : return new OdspUrlResolver ( options . server , { accessToken : options . odspAccessToken } ) ; default : return new LocalResolver ( ) ; } } export class MultiUrlResolver implements IUrlResolver { private readonly urlResolver : IUrlResolver ; constructor ( private readonly documentId , private readonly rawUrl , private readonly options , private readonly useLocalResolver = false ) { if ( this . useLocalResolver ) { this . urlResolver = new LocalResolver ( ) ; } else { this . urlResolver = getUrlResolver ( options ) ; } } async getAbsoluteUrl ( resolvedUrl , relativeUrl ) { let url = relativeUrl ; if ( url . startsWith ( "/" ) ) { url = url . substr ( 1 ) ; } return `${ this . rawUrl }/${ this . documentId }/${ url }` ; } async resolve ( request ) { return this . urlResolver . resolve ( request ) ; } public async createRequestForCreateNew ( fileName ) { if ( this . useLocalResolver ) { return ( this . urlResolver as LocalResolver ) . createCreateNewRequest ( fileName ) ; } switch ( this . options . mode ) { case "r11s" : case "docker" : case "tinylicious" : return ( this . urlResolver as InsecureUrlResolver ) . createCreateNewRequest ( fileName ) ; case "spo" : case "spo-df" : return ( this . urlResolver as OdspUrlResolver ) . createCreateNewRequest ( fileName ) ; default : return ( this . urlResolver as LocalResolver ) . createCreateNewRequest ( fileName ) ; } } }