[frontend/components] Fallback to detecting attachment type by filename extension
This commit is contained in:
parent
0ea4122ec7
commit
5976735af2
2 changed files with 15 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
||||||
@using Iceshrimp.Assets.PhosphorIcons
|
@using Iceshrimp.Assets.PhosphorIcons
|
||||||
|
@using Iceshrimp.Frontend.Core.Miscellaneous
|
||||||
@using Iceshrimp.Frontend.Core.Services
|
@using Iceshrimp.Frontend.Core.Services
|
||||||
@using Iceshrimp.Frontend.Localization
|
@using Iceshrimp.Frontend.Localization
|
||||||
@using Iceshrimp.Shared.Schemas.Web
|
@using Iceshrimp.Shared.Schemas.Web
|
||||||
|
@ -7,7 +8,7 @@
|
||||||
@inject IStringLocalizer<Localization> Loc;
|
@inject IStringLocalizer<Localization> Loc;
|
||||||
|
|
||||||
<div class="wrapper" @onclick="Open" @onclick:stopPropagation="true">
|
<div class="wrapper" @onclick="Open" @onclick:stopPropagation="true">
|
||||||
@if (Attachment.ContentType.StartsWith("image"))
|
@if (Attachment.ContentType.StartsWith("image") || Constants.CommonImageExtensions.Any(e => Attachment.FileName.EndsWith(e)))
|
||||||
{
|
{
|
||||||
<img class="attachment @(BlurImage ? "blur-image" : "")" src="@Attachment.Url" alt="@Attachment.AltText"
|
<img class="attachment @(BlurImage ? "blur-image" : "")" src="@Attachment.Url" alt="@Attachment.AltText"
|
||||||
fetchpriority="low"/>
|
fetchpriority="low"/>
|
||||||
|
@ -24,11 +25,11 @@
|
||||||
// {
|
// {
|
||||||
// TODO: Module player
|
// TODO: Module player
|
||||||
// }
|
// }
|
||||||
else if (Attachment.ContentType.StartsWith("audio"))
|
else if (Attachment.ContentType.StartsWith("audio") || Constants.CommonAudioExtensions.Any(e => Attachment.FileName.EndsWith(e)))
|
||||||
{
|
{
|
||||||
<audio controls class="attachment" src="@Attachment.Url"></audio>
|
<audio controls class="attachment" src="@Attachment.Url"></audio>
|
||||||
}
|
}
|
||||||
else if (Attachment.ContentType.StartsWith("video"))
|
else if (Attachment.ContentType.StartsWith("video") || Constants.CommonVideoExtensions.Any(e => Attachment.FileName.EndsWith(e)))
|
||||||
{
|
{
|
||||||
<video controls class="attachment">
|
<video controls class="attachment">
|
||||||
<source src="@Attachment.Url"/>
|
<source src="@Attachment.Url"/>
|
||||||
|
|
11
Iceshrimp.Frontend/Core/Miscellaneous/Constants.cs
Normal file
11
Iceshrimp.Frontend/Core/Miscellaneous/Constants.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
namespace Iceshrimp.Frontend.Core.Miscellaneous;
|
||||||
|
|
||||||
|
public static class Constants
|
||||||
|
{
|
||||||
|
public static readonly string[]
|
||||||
|
CommonImageExtensions = [".png", ".gif", ".jpeg", ".jpg", ".apng", ".bmp", ".tiff", ".avif", ".webp", ".jxl"];
|
||||||
|
|
||||||
|
public static readonly string[] CommonAudioExtensions = [".opus", ".ogg", ".m4a", ".mp3", ".flac", ".wav"];
|
||||||
|
|
||||||
|
public static readonly string[] CommonVideoExtensions = [".mov", ".mp4", ".webm", ".mkv"];
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue