import { type ServiceScope } from '@microsoft/sp-core-library'; import type { _IPreloadedData } from '@microsoft/sp-loader'; import type { IThumbnailRequest } from './IThumbnailRequest'; import { _ThumbnailProviderType } from './ThumbnailProviderType'; import { UserPhotoSize as _UserPhotoSize } from '@msinternal/odsp-utilities/lib/alternativeUrls/SPAlternativeUrls'; /** * This class is the entry point for requesting thumbnail URL for given sharepoint resource * It's behavior depends on the timing of oauth token availability * -It needs oauth token to generate Media Service based thumbnail URL * -At SPPageApp load time, token is requested * -When request arrives for thumbnail, if token is resolved, Media Service url is returned * -If token is not available then getPreview.ashx based url is constructed * * NOTE: Caller of this API should not log thumbnail url in console or trace logger. * * @internal */ export declare class _ThumbnailUrlGenerator { private static _instance; private _logSource; private _serviceScope; private _pageContext; private _isDecodedKeyAdded; private _mediaTAForThumbnailEnabled; /** * Returns true if the file type is supported by media service for thumbnail * @param fileType - type (extension) of file to be tested */ private static _isFileTypeSupportedByMediaService; private static _getMediaSupportFileType; private static _isViewportNumberValid; private static _replaceQueryValue; private static _getSPResourceAuthority; constructor(); /** ------------------- PUBLIC ------------------- **/ static get instance(): _ThumbnailUrlGenerator; /** * Initialize thumbnail url generator service scope. */ initialize(serviceScope: ServiceScope, preloadedData?: _IPreloadedData): void; /** * Returns true if the file extension is supported for thumbnail */ isFileTypeSupported(fileType: string | undefined): boolean; /** * Generate user photo URL for specific size. * When private CDN is enabled, generated URL is mapped to CDN. * @param accountName - User's account name aka email address. e.g. foo\@contoso.com * @param size - Parameter may have value Small, Medium or Large, default to Small. */ getUserPhotoUrl(accountName: string, size?: _UserPhotoSize): string; /** * Get thumbnail Url for the given sharepoint resource. * * Ensure you first check file type is supported via * isFileTypeSupported or the code will attempt to fallback to spResource. */ getThumbnailUrl(request: IThumbnailRequest, defaultImage?: string): string | undefined; /** * Get base public CDN Url */ get publicCDNBaseUrl(): string; /** * Returns true if current environment is Air gap (aka AG) * Note AIRGAP_CLOUDS update is required if new AG environments are added in future. * * TODO: Potentially replace this with the existing helper located in EnvironmentHelper.ts. */ get isAirGap(): boolean; get mediaCDNBaseUrl(): string; /** * Always use getThumbnailUrl API except in advanced scenarios * * Generates VROOM thumbnail URL if applicable or undefined otherwise. * @param request - Requested info about thumbnail */ getVROOMThumbnailUrl(request: IThumbnailRequest, provider?: _ThumbnailProviderType): string | undefined; /** * Always use getThumbnailUrl API except in advanced scenarios. * * Generates public or private CDN URl if applicable or undefined otherwise. * @param request - Requested info about thumbnail */ getCDNUrl(request: IThumbnailRequest): string | undefined; /** * Always use getThumbnailUrl API except in advanced scenarios. * * Generates DocViz getPreivew.ashx URL if applicable or undefined otherwise. * @param request - Requested info about thumbnail * @param provider - Provider of the spResource path if available */ getDocVizUrl(request: IThumbnailRequest, provider?: _ThumbnailProviderType): string | undefined; /** * Update width of the thumbnail URL * @param thumbnailUrl - Thumbnail URL to be updated * @param newWidth - new width to be applied. Width will be mapped to closest cache breakpoint */ updateThumbnailWidth(thumbnailUrl: string, newWidth: number, provider?: _ThumbnailProviderType): string; /** * Provide requested width of the thumbnail URL * Returns 0 if full image URL with confidence or undefined if not sure. * @param thumbnailUrl - Thumbnail URL to inspect for width */ getThumbnailWidth(thumbnailUrl: string, provider?: _ThumbnailProviderType): number | undefined; /** * Get name of the thumbnail provider service for given thumbnail URL. * @param thumbnailUrl - Thumbnail URL * @param isStockImage - True if caller knows it was generated from DEFAULT_IMAGES_PATH_PREFIX path. */ getThumbnailProvider(thumbnailUrl?: string, isStockImage?: boolean): _ThumbnailProviderType; /** * Returns true if given URL is public or private CDN * @param thumbnailUrl - Thumbnail URL under test */ isCdnUrl(thumbnailUrl: string): boolean; /** * Converts given getPreviewUrl to optimal thumbnail service possible * @param getPreviewUrl - getPreview.aspx thumbnail Url * @param callerId - Identification of the caller * @param width - Requested width of the thumbnail */ fromGetPreview(getPreviewUrl: string | undefined, callerId: string, width?: number): string | undefined; isVROOMThumbnailEnabled(): boolean; /** ------------------- PRIVATE ------------------- **/ /** * Get the appropriate Air gap clouds list based on killswitch * @returns Array of Air gap cloud environment names */ private _getAirGapClouds; private _pruneShareUrl; private _initialize; /** * Converts unknown url to best possible thumbnail service * @param request - Requested info about thumbnail */ private _fromUnknownThumbnailUrl; private _isViewportParametersSpecified; /** * This method redirects request to GetPreview service as fallback in the event of any failure or delay */ private _fallbackToGetPreview; /** * Get preloaded preview Url of the image if already loaded */ private _getPreLoadedImage; private _shouldAddCacheBuster; private _addCacheBuster; private _shouldAddLQIP; private _addLQIP; private _getPreloadedDictionary; /** * Return downscaled URL for default Image. By default Default Images are downloaded as it is on all devices except * it is mapped correctly with different image for different device. * Now with integration with public CDN and downscale backed by MeTA, we should be able to download required size * default image for different screen sizes. * If MeTA/Public CND service is not available, it fallbacks to legacy behavior. * Note that MeTA response is cached on Akamai that CDN never going to MeTA again except once a year per file per meta Host. * Also if File is changed, it's URL is changes thus causing automatic refresh. * * @param publicImage - URL of public Image where host is onboarded with MeTa. See UrlProvider.cs for include list of hosts * https://onedrive.visualstudio.com/OneDrive%20Service/_git/MediaTransformAndAnalysis?path=%2FDataSourceProviders.Implementation%2FUrlProvider.cs&_a=contents&version=GBmaster * @param request - Incodming thumbnail request */ private _getPublicCDNMeTAUrl; /** * Ensure the preloaded image is close enough to the resolution requirement * @param preloadedUrl - Preloaded image Url * @param request - Thumbnail request containing resolution requirements */ private _validateResolution; private _validateImageProperty; private _readUrlFromDictionary; /** * Returns true if given path represents SPO _layouts/15 path including images * @param resourcePath - Absolute or relative path of the resource */ private _isLayoutsPath; /** * Rewrite /_layouts/15/images/.. image to media CDN * This will serve image from CDN path instead * e.g. https://media.akamai.odsp.cdn.office.net/microsoft.sharepoint.com/_layouts/15/images/sitepagethumbnail.png * @param request - Requested info about thumbnail */ private _rewriteOptimalLayoutsImageUrl; /** * Rewrite image Url to media CDN cache * This will serve image behind CDN cache * e.g. https://media.akamai.odsp.cdn.office.net/microsoft.sharepoint.com/_layouts/15/images/sitepagethumbnail.png * @param publicImageUrl - Canonical public image Url */ private _rewriteOptimalImageUrl; /** * Extract path from the give URL for given URL provider type * If not applicable returns original URL. * It is the caller's responsibility to specify the correct provider for given URL. * * @param provider - Provider type of given thumbnail url * @param url - Thumbnail URL from which original path to be extracted if any * @returns Extracted path or original URL */ private _getPathFromOptimalUrl; /** * Thumbnail URL: https://cdn.hubblecontent.osi.office.net/m365content/publish/01443b10-5551-4c18-8b4f-2c5f969d8ec6/thumbnails/large.jpg?file=gettyimages-543374530.jpg * Reconstructed Original URL:https://cdn.hubblecontent.osi.office.net/m365content/publish/01443b10-5551-4c18-8b4f-2c5f969d8ec6/gettyimages-543374530.jpg * We use only large.jpg version of thumbnail only. We DO NOT use small medium or xlarge possible variations. * If this is a Hubble thumbnail URL (Which is a preview version of original Hubble stock image, and requested width is higher than original URL * so optimal URL can be generated for required resolution) * Note: It is callers responsibility to ensure request.spResource is hubble thumbnail format. * Note: Hubble endpoint hostname may vary depending on the environment (e.g., AirGap's Hubble * endpoint is different from above). Please reference HubbleEndpointHelper.ts. * * @param request - Thumbnail Request * @returns Updated width Media Hubble Url */ private _updateHubbleThumbnailWidth; } /** * @internal */ declare const _default: _ThumbnailUrlGenerator; export default _default; //# sourceMappingURL=ThumbnailUrlGenerator.d.ts.map