Class UrlPreviewService
URL previews: fetch a page, read its OpenGraph title, description and image, and store the image in the media repository.
Inherited Members
Namespace: Uniform.Matrix.Server.Media
Assembly: Uniform.Matrix.Server.dll
Syntax
public sealed class UrlPreviewService
Remarks
Pages and images are fetched through PublicAddresses, so previews cannot reach machines inside the server's network unless AllowPrivateAddresses is on; size and time are limited. Results are kept for CacheDuration per address.
Constructors
| Edit this page View SourceUrlPreviewService(IHttpClientFactory, MediaService, IOptionsMonitor<UrlPreviewOptions>, TimeProvider, ILogger<UrlPreviewService>)
Create the service.
Declaration
public UrlPreviewService(IHttpClientFactory httpClients, MediaService media, IOptionsMonitor<UrlPreviewOptions> options, TimeProvider time, ILogger<UrlPreviewService> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| IHttpClientFactory | httpClients | |
| MediaService | media | |
| IOptionsMonitor<UrlPreviewOptions> | options | |
| TimeProvider | time | |
| ILogger<UrlPreviewService> | logger |
Fields
| Edit this page View SourceHttpClientName
Name of the HTTP client that fetches pages.
Declaration
public const string HttpClientName = "Uniform.Matrix.Server.UrlPreviews"
Field Value
| Type | Description |
|---|---|
| string |
Properties
| Edit this page View SourceEnabled
Get whether previews are on, see Enabled.
Declaration
public bool Enabled { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
| Edit this page View SourceGetPreviewAsync(string, string, CancellationToken)
Return the preview of url: og: keys of the page, and the image as an mxc:// URI with matrix:image:size; an image link previews as itself.
Declaration
public Task<JsonObject> GetPreviewAsync(string userId, string url, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | Who asks; owns the stored image. |
| string | url | Absolute http or https address. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<JsonObject> |