MCPcopy Create free account
hub / github.com/apitable/apitable / cellValueToImageSrc

Function cellValueToImageSrc

packages/core/src/utils/file.ts:160–203  ·  view source on GitHub ↗
(
  cellValue: IAttachmentValue | undefined,
  options?: IImageSrcOption,
)

Source from the content-addressed store, hash-verified

158};
159
160export 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
205export const integrateCdnHost = (
206 pathName: string,

Callers 11

cellValueToArrayMethod · 0.90
cellValueToOpenValueMethod · 0.90
uploadFileMethod · 0.90
uploadFunction · 0.90
getCellValueThumbSrcFunction · 0.90
PreviewPdfFunction · 0.90
PreviewImageFunction · 0.90
createVideoContainerFunction · 0.90
getImageSrcFunction · 0.90
getCellValueThumbSrcFunction · 0.90

Calls 8

getHostOfAttachmentFunction · 0.85
integrateCdnHostFunction · 0.85
getImageThumbSrcFunction · 0.85
isPdfFunction · 0.85
isGifFunction · 0.85
isWebpFunction · 0.85
isSvgFunction · 0.85
keysMethod · 0.65

Tested by

no test coverage detected