( cellValue: IAttachmentValue | undefined, options?: IImageSrcOption, )
| 158 | }; |
| 159 | |
| 160 | export function cellValueToImageSrc( |
| 161 | cellValue: IAttachmentValue | undefined, |
| 162 | options?: IImageSrcOption, |
| 163 | ): string { |
| 164 | if (!cellValue) return ''; |
| 165 | |
| 166 | const { bucket, token, preview: previewToken, mimeType, name } = cellValue; |
| 167 | |
| 168 | if (!bucket) return ''; |
| 169 | |
| 170 | const host = getHostOfAttachment(bucket); |
| 171 | |
| 172 | if (!host) return ''; |
| 173 | |
| 174 | const { formatToJPG, isPreview } = options || {}; |
| 175 | const fileArgument = { name, type: mimeType }; |
| 176 | const originSrc = integrateCdnHost(token); |
| 177 | const defaultSrc = getImageThumbSrc(originSrc, options); |
| 178 | |
| 179 | if (isPdf(fileArgument)) { |
| 180 | if (isPreview && options && Object.keys(options).length >= 1) { |
| 181 | return getImageThumbSrc(integrateCdnHost(previewToken!), options); |
| 182 | } |
| 183 | return originSrc; |
| 184 | } |
| 185 | |
| 186 | if (isGif(fileArgument) || isWebp(fileArgument)) { |
| 187 | // The caller is from Swiper and does not use slice parameters |
| 188 | if (options == null) { |
| 189 | return originSrc; |
| 190 | } |
| 191 | |
| 192 | return getImageThumbSrc(originSrc, { |
| 193 | ...options, |
| 194 | format: formatToJPG ? 'jpg' : undefined, |
| 195 | }); |
| 196 | } |
| 197 | |
| 198 | if (isSvg(fileArgument)) { |
| 199 | return originSrc; |
| 200 | } |
| 201 | |
| 202 | return defaultSrc; |
| 203 | } |
| 204 | |
| 205 | export const integrateCdnHost = ( |
| 206 | pathName: string, |
no test coverage detected