Fetches a link's preview through the provider that knows its site, and reuses it for a few minutes. dump-service.ts calls it when a link is posted, changed or refreshed, and GET /api/remote/preview when the create form previews one.

Functions

f
clearRichContentCache(): void

Forgets every cached preview. The tests' stubNetwork calls it, since previews fetched from the previous stubbed network no longer apply.

f
fetchRichContent(url: string): Promise<RichContent | undefined>

Returns the preview of url, or a stub holding its host name when the page can't be reached. createUrlDump and updateDump use it for a new link, which has no earlier preview to keep.

f
tryFetchRichContent(
url: string,
unnamed 1?: { fresh?: boolean; }
): Promise<FetchRichContentResult>

Fetches the preview of url, and says whether the page could be reached. A preview fetched in the last five minutes is reused unless fresh is set, as a metadata refresh does. It never rejects: a failure resolves to a stub.

Interfaces

I
FetchRichContentResult

Returned by tryFetchRichContent to GET /api/remote/preview, which reports ok as reached, and to refreshDumpMetadata, which gives up when it is false.

  • content: RichContent

    On failure, a stub holding the URL and its host name. Missing only when the URL doesn't parse.

  • ok: boolean

    False when the page couldn't be reached at all, as opposed to reached and found to carry no metadata. A caller that already holds metadata must not overwrite it with the failure stub.