private async downloadAllPreviewUrls()

in packages/chat-stateful-client/src/ResourceDownloadQueue.ts [103:129]


  private async downloadAllPreviewUrls(
    message: ChatMessageWithStatus,
    operation: ImageRequest
  ): Promise<ChatMessageWithStatus> {
    const attachments = message.content?.attachments;
    if (message.type === 'html' && attachments) {
      if (message.resourceCache === undefined) {
        message.resourceCache = {};
      }
      for (const attachment of attachments) {
        if (attachment.previewUrl && attachment.attachmentType === 'image') {
          const response: ResourceFetchResult = { sourceUrl: '' };
          try {
            const abortController = new AbortController();
            const blobUrl = await this.downloadResource(operation, attachment.previewUrl, abortController);
            response.sourceUrl = blobUrl;
          } catch (error) {
            response.error = error as Error;
            delete this._requestsToCancel[attachment.previewUrl];
          }
          message.resourceCache[attachment.previewUrl] = response;
        }
      }
    }

    return message;
  }