@@ -56,6 +56,10 @@ export interface ImageDimensionsSource {
5656 */
5757export interface FileContentSource {
5858 buildUrl : ( key : string , opts ?: FileContentUrlOptions ) => string
59+ buildImageUrl : (
60+ file : { key : string ; name : string ; type : string } ,
61+ opts ?: FileContentUrlOptions
62+ ) => string
5963 /**
6064 * Map an embedded image `src` to a display URL scoped to the current context: the in-app source
6165 * points at the workspace-scoped inline route, the public source at the token-scoped cascade route.
@@ -81,7 +85,7 @@ function buildServeUrl(key: string, opts?: FileContentUrlOptions): string {
8185function inlineImageSource (
8286 buildUrl : FileContentSource [ 'buildUrl' ] ,
8387 inlineBase : string
84- ) : FileContentSource {
88+ ) : Pick < FileContentSource , 'buildUrl' | 'resolveImageSrc' > {
8589 return {
8690 buildUrl,
8791 resolveImageSrc : ( src ) => {
@@ -103,6 +107,16 @@ export function createWorkspaceFileContentSource(
103107) : FileContentSource {
104108 return {
105109 ...inlineImageSource ( buildServeUrl , `/api/workspaces/${ workspaceId } /files/inline` ) ,
110+ buildImageUrl : ( file , opts ) => {
111+ const heic =
112+ file . type === 'image/heic' ||
113+ file . type === 'image/heif' ||
114+ / \. (?: h e i c | h e i f ) $ / i. test ( file . name )
115+ if ( heic ) return buildServeUrl ( file . key , { ...opts , preview : true } )
116+
117+ const params = new URLSearchParams ( { key : file . key } )
118+ return `/api/workspaces/${ encodeURIComponent ( workspaceId ) } /files/inline?${ params } `
119+ } ,
106120 ...imageDimensions ,
107121 }
108122}
@@ -116,11 +130,17 @@ export function createPublicFileContentSource(
116130 token : string ,
117131 contentUrl : string
118132) : FileContentSource {
119- return inlineImageSource (
120- ( _key , opts ) =>
133+ return {
134+ ...inlineImageSource (
135+ ( _key , opts ) =>
136+ opts ?. preview
137+ ? `${ contentUrl } ${ contentUrl . includes ( '?' ) ? '&' : '?' } preview=1`
138+ : contentUrl ,
139+ `/api/files/public/${ token } /inline`
140+ ) ,
141+ buildImageUrl : ( _file , opts ) =>
121142 opts ?. preview ? `${ contentUrl } ${ contentUrl . includes ( '?' ) ? '&' : '?' } preview=1` : contentUrl ,
122- `/api/files/public/${ token } /inline`
123- )
143+ }
124144}
125145
126146/**
@@ -130,6 +150,7 @@ export function createPublicFileContentSource(
130150 */
131151export const workspaceFileContentSource : FileContentSource = {
132152 buildUrl : buildServeUrl ,
153+ buildImageUrl : ( file , opts ) => buildServeUrl ( file . key , { ...opts , preview : true } ) ,
133154 resolveImageSrc : ( src ) => src ,
134155}
135156
0 commit comments