[frontend/components] Fallback to detecting attachment type by filename extension

This commit is contained in:
pancakes 2025-02-26 18:14:29 +10:00 committed by Laura Hausmann
parent 0ea4122ec7
commit 5976735af2
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 15 additions and 3 deletions

View file

@ -1,4 +1,5 @@
@using Iceshrimp.Assets.PhosphorIcons
@using Iceshrimp.Frontend.Core.Miscellaneous
@using Iceshrimp.Frontend.Core.Services
@using Iceshrimp.Frontend.Localization
@using Iceshrimp.Shared.Schemas.Web
@ -7,7 +8,7 @@
@inject IStringLocalizer<Localization> Loc;
<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"
fetchpriority="low"/>
@ -24,11 +25,11 @@
// {
// 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>
}
else if (Attachment.ContentType.StartsWith("video"))
else if (Attachment.ContentType.StartsWith("video") || Constants.CommonVideoExtensions.Any(e => Attachment.FileName.EndsWith(e)))
{
<video controls class="attachment">
<source src="@Attachment.Url"/>

View 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"];
}