MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / makeBlobURL

Function makeBlobURL

src/pkg/utils/utils.ts:351–369  ·  view source on GitHub ↗
(
  params: T,
  fallbackFn?: (params: T) => string | Promise<string>
)

Source from the content-addressed store, hash-verified

349};
350
351export const makeBlobURL = <T extends { blob: Blob; persistence: boolean }>(
352 params: T,
353 fallbackFn?: (params: T) => string | Promise<string>
354): Promise<string> | string => {
355 if (typeof URL?.createObjectURL !== "function") {
356 // 在service worker中,透过 offscreen 取得 blob URL
357 if (!fallbackFn) throw new Error("URL.createObjectURL is not supported");
358 return fallbackFn(params);
359 } else {
360 const url = URL.createObjectURL(params.blob);
361 if (!params.persistence) {
362 // 如果不是持久化的,则在1分钟后释放
363 setTimeout(() => {
364 URL.revokeObjectURL(url);
365 }, 60_000);
366 }
367 return url;
368 }
369};
370
371export function blobToBase64(blob: Blob): Promise<string> {
372 return new Promise((resolve) => {

Callers 9

onDropFunction · 0.90
renderFunction · 0.90
CloudScriptPlanFunction · 0.90
openImportWindowFunction · 0.90
saveAsFunction · 0.90
requestExportMethod · 0.90
CAT_fileStorageMethod · 0.90
initManagerMethod · 0.90
initMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected