import { IOdspUrlParts } from "@fluidframework/odsp-driver-definitions" ; param origin export function isOdcOrigin ( origin ) { return ( origin . includes ( "onedrive.com" ) || origin . includes ( "storage.live.com" ) || origin . includes ( "storage.live-int.com" ) || origin . includes ( "onedrive-tst.com" ) ) ; } param origin export function getApiRoot ( origin ) { let prefix = "_api/" ; if ( isOdcOrigin ( origin ) ) { prefix = "" ; } return `${ origin }/${ prefix }v2.1` ; } param url export function isSpoUrl ( url ) { const urlLower = url . toLowerCase ( ) ; const spoRegex = /(.*\.sharepoint(-df)*\.com)\/_api\/v2.1\/drives\/([^/]*)\/items\/([^/]*)/ ; return ! ! spoRegex . exec ( urlLower ) ; } param url export function isOdcUrl ( url ) { const urlObj = typeof url === "string" ? new URL ( url ) : url ; if ( ! isOdcOrigin ( urlObj . origin ) ) { return false ; } const path = urlObj . pathname . toLowerCase ( ) ; const odcRegex = /\/v2.1\/(drive|drives\/[^/]+)\/items\/([\da-z]+)!(\d+)/ ; const odcODataRegex = /\/v2.1\/drives\('[^/]+'\)\/items\('[\da-z]+!\d+'\)/ ; return ! ! ( odcRegex . exec ( path ) || odcODataRegex . exec ( path ) ) ; } param url export async function getOdspUrlParts ( url ) { const pathname = url . pathname ; let joinSessionMatch ; if ( isOdcOrigin ( url . origin ) ) { joinSessionMatch = /(.*)\/v2\.1\/drive(s\/([\dA-Za-z]+))?\/items\/(([\dA-Za-z]+)!\d+)/ . exec ( pathname ) ; if ( joinSessionMatch === null ) { joinSessionMatch = /(.*)\/v2\.1\/drives\('([\dA-Za-z]+)'\)\/items\('(([\dA-Za-z]+)!\d+)'\)/ . exec ( pathname ) ; if ( joinSessionMatch === null ) { return undefined ; } } const driveId = joinSessionMatch [ 3 ] || joinSessionMatch [ 5 ] ; const itemId = joinSessionMatch [ 4 ] ; return { siteUrl : `${ url . origin }${ url . pathname }` , driveId , itemId } ; } else { joinSessionMatch = /(.*)\/_api\/v2.1\/drives\/([^/]*)\/items\/([^/]*)(.*)/ . exec ( pathname ) ; if ( joinSessionMatch === null ) { return undefined ; } const driveId = joinSessionMatch [ 2 ] ; const itemId = joinSessionMatch [ 3 ] ; return { siteUrl : `${ url . origin }${ url . pathname }` , driveId , itemId } ; } }