Remove committed media. Store and serve proper mime type.
parent
262e8cd468
commit
0fc8d756b3
|
@ -352,3 +352,5 @@ Upload/
|
||||||
LANCommander/Icon/
|
LANCommander/Icon/
|
||||||
LANCommander/Settings.yml
|
LANCommander/Settings.yml
|
||||||
LANCommander/Saves/
|
LANCommander/Saves/
|
||||||
|
LANCommander/Media/
|
||||||
|
LANCommander/Uploads/
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace LANCommander.Controllers.Api
|
||||||
|
|
||||||
var fs = System.IO.File.OpenRead(MediaService.GetImagePath(media));
|
var fs = System.IO.File.OpenRead(MediaService.GetImagePath(media));
|
||||||
|
|
||||||
return File(fs, "image/png");
|
return File(fs, media.MimeType);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,9 @@ namespace LANCommander.Data.Models
|
||||||
[MaxLength(2048)]
|
[MaxLength(2048)]
|
||||||
public string SourceUrl { get; set; }
|
public string SourceUrl { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(255)]
|
||||||
|
public string MimeType { get; set; }
|
||||||
|
|
||||||
public Guid GameId { get; set; }
|
public Guid GameId { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(GameId))]
|
[ForeignKey(nameof(GameId))]
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 405 KiB |
Binary file not shown.
Before Width: | Height: | Size: 876 KiB |
Binary file not shown.
Before Width: | Height: | Size: 6.4 MiB |
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,30 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LANCommander.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddMediaMimeType : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "MimeType",
|
||||||
|
table: "Media",
|
||||||
|
type: "TEXT",
|
||||||
|
maxLength: 255,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "MimeType",
|
||||||
|
table: "Media");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -492,6 +492,11 @@ namespace LANCommander.Migrations
|
||||||
b.Property<Guid>("GameId")
|
b.Property<Guid>("GameId")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("MimeType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("SourceUrl")
|
b.Property<string>("SourceUrl")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(2048)
|
.HasMaxLength(2048)
|
||||||
|
|
|
@ -9,5 +9,6 @@ namespace LANCommander.Models
|
||||||
public string SourceUrl { get; set; }
|
public string SourceUrl { get; set; }
|
||||||
public string ThumbnailUrl { get; set; }
|
public string ThumbnailUrl { get; set; }
|
||||||
public string Group { get; set; }
|
public string Group { get; set; }
|
||||||
|
public string MimeType { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
modalRef.Config.ConfirmLoading = true;
|
modalRef.Config.ConfirmLoading = true;
|
||||||
|
|
||||||
media.SourceUrl = result.SourceUrl;
|
media.SourceUrl = result.SourceUrl;
|
||||||
|
media.MimeType = result.MimeType;
|
||||||
|
|
||||||
if (media.Id == Guid.Empty)
|
if (media.Id == Guid.Empty)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,14 @@ namespace LANCommander.Services.MediaGrabbers
|
||||||
public class SteamGridDBMediaGrabber : IMediaGrabberService
|
public class SteamGridDBMediaGrabber : IMediaGrabberService
|
||||||
{
|
{
|
||||||
SteamGridDb SteamGridDb { get; set; }
|
SteamGridDb SteamGridDb { get; set; }
|
||||||
|
|
||||||
|
private SteamGridDbFormats[] SupportedFormats = new SteamGridDbFormats[]
|
||||||
|
{
|
||||||
|
SteamGridDbFormats.Png,
|
||||||
|
SteamGridDbFormats.Jpeg,
|
||||||
|
SteamGridDbFormats.Webp
|
||||||
|
};
|
||||||
|
|
||||||
public SteamGridDBMediaGrabber()
|
public SteamGridDBMediaGrabber()
|
||||||
{
|
{
|
||||||
var settings = SettingService.GetSettings();
|
var settings = SettingService.GetSettings();
|
||||||
|
@ -45,13 +53,14 @@ namespace LANCommander.Services.MediaGrabbers
|
||||||
{
|
{
|
||||||
var icons = await SteamGridDb.GetIconsByGameIdAsync(game.Id);
|
var icons = await SteamGridDb.GetIconsByGameIdAsync(game.Id);
|
||||||
|
|
||||||
return icons.Select(i => new MediaGrabberResult()
|
return icons.Where(i => SupportedFormats.Contains(i.Format)).Select(i => new MediaGrabberResult()
|
||||||
{
|
{
|
||||||
Id = i.Id.ToString(),
|
Id = i.Id.ToString(),
|
||||||
Type = MediaType.Icon,
|
Type = MediaType.Icon,
|
||||||
SourceUrl = i.FullImageUrl,
|
SourceUrl = i.FullImageUrl,
|
||||||
ThumbnailUrl = i.ThumbnailImageUrl,
|
ThumbnailUrl = i.ThumbnailImageUrl,
|
||||||
Group = game.Name
|
Group = game.Name,
|
||||||
|
MimeType = GetMimeType(i.Format)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,13 +68,14 @@ namespace LANCommander.Services.MediaGrabbers
|
||||||
{
|
{
|
||||||
var covers = await SteamGridDb.GetGridsByGameIdAsync(game.Id);
|
var covers = await SteamGridDb.GetGridsByGameIdAsync(game.Id);
|
||||||
|
|
||||||
return covers.Select(c => new MediaGrabberResult()
|
return covers.Where(c => SupportedFormats.Contains(c.Format)).Select(c => new MediaGrabberResult()
|
||||||
{
|
{
|
||||||
Id = c.Id.ToString(),
|
Id = c.Id.ToString(),
|
||||||
Type = MediaType.Cover,
|
Type = MediaType.Cover,
|
||||||
SourceUrl = c.FullImageUrl,
|
SourceUrl = c.FullImageUrl,
|
||||||
ThumbnailUrl = c.ThumbnailImageUrl,
|
ThumbnailUrl = c.ThumbnailImageUrl,
|
||||||
Group = game.Name
|
Group = game.Name,
|
||||||
|
MimeType = GetMimeType(c.Format)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,14 +83,30 @@ namespace LANCommander.Services.MediaGrabbers
|
||||||
{
|
{
|
||||||
var backgrounds = await SteamGridDb.GetHeroesByGameIdAsync(game.Id);
|
var backgrounds = await SteamGridDb.GetHeroesByGameIdAsync(game.Id);
|
||||||
|
|
||||||
return backgrounds.Select(b => new MediaGrabberResult()
|
return backgrounds.Where(b => SupportedFormats.Contains(b.Format)).Select(b => new MediaGrabberResult()
|
||||||
{
|
{
|
||||||
Id = b.Id.ToString(),
|
Id = b.Id.ToString(),
|
||||||
Type = MediaType.Background,
|
Type = MediaType.Background,
|
||||||
SourceUrl = b.FullImageUrl,
|
SourceUrl = b.FullImageUrl,
|
||||||
ThumbnailUrl = b.ThumbnailImageUrl,
|
ThumbnailUrl = b.ThumbnailImageUrl,
|
||||||
Group = game.Name
|
Group = game.Name,
|
||||||
|
MimeType = GetMimeType(b.Format)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetMimeType(SteamGridDbFormats format)
|
||||||
|
{
|
||||||
|
switch (format)
|
||||||
|
{
|
||||||
|
case SteamGridDbFormats.Png:
|
||||||
|
return "image/png";
|
||||||
|
case SteamGridDbFormats.Jpeg:
|
||||||
|
return "image/jpg";
|
||||||
|
case SteamGridDbFormats.Webp:
|
||||||
|
return "image/webp";
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException("The SteamGridDB grabber currently does not support this format");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue