Class MediaService
The media repository: local uploads, and media of other servers fetched once through federation; files under the media directory, rows in the database.
Namespace: Uniform.Matrix.Server.Media
Assembly: Uniform.Matrix.Server.dll
public sealed class MediaService
Constructors
|
Edit this page
View Source
MediaService(IDbContextFactory<ServerDbContext>, IOptions<ServerOptions>, IOptionsMonitor<MediaOptions>, IOptions<ServerStorageOptions>, IHostEnvironment, TimeProvider, FederationClient, ILogger<MediaService>)
Create the service over the media directory under the data directory.
Declaration
public MediaService(IDbContextFactory<ServerDbContext> contexts, IOptions<ServerOptions> server, IOptionsMonitor<MediaOptions> media, IOptions<ServerStorageOptions> storage, IHostEnvironment environment, TimeProvider time, FederationClient federation, ILogger<MediaService> logger)
Parameters
Properties
|
Edit this page
View Source
Declaration
public bool AllowUnauthenticatedDownloads { get; }
Property Value
|
Edit this page
View Source
Declaration
public long MaxUploadSize { get; }
Property Value
Methods
|
Edit this page
View Source
Declaration
public Task<(string ContentUri, long ExpiresAt)> CreatePendingAsync(string userId, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Delete local media: its file, thumbnails and row; return false when there is no such media.
Declaration
public Task<bool> DeleteLocalAsync(string mediaId, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Return a stored file, fetching media of other servers first; throw M_NOT_FOUND for unknown media. Local media whose content is not uploaded yet is waited for up to timeout, then throws M_NOT_YET_UPLOADED.
Declaration
public Task<MediaService.StoredFile> GetAsync(string serverName, string mediaId, TimeSpan timeout, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Return a local file for another server, as /_matrix/federation/v1/media/download serves it; throw M_NOT_FOUND for unknown media. Media of other servers is not passed on.
Declaration
public Task<MediaService.StoredFile> GetLocalAsync(string mediaId, TimeSpan timeout, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Return a thumbnail, making it on first request; throw M_UNKNOWN (400) when the media is not an image that can be thumbnailed.
Declaration
public Task<MediaService.StoredFile> GetThumbnailAsync(string serverName, string mediaId, int width, int height, string method, TimeSpan timeout, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Return the local media uploaded by userId, newest first.
Declaration
public Task<IReadOnlyList<MediaRow>> GetUploadsAsync(string userId, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Return whether serverName is this server, whose media is local.
Declaration
public bool IsLocal(string serverName)
Parameters
| Type |
Name |
Description |
| string |
serverName |
|
Returns
|
Edit this page
View Source
Store an upload of userId; return its mxc:// URI. Throws M_TOO_LARGE past MaxUploadSize.
Declaration
public Task<string> UploadAsync(string userId, Stream content, string contentType, string? fileName, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task UploadPendingAsync(string userId, string serverName, string mediaId, Stream content, string contentType, string? fileName, CancellationToken cancellationToken)
Parameters
Returns