mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-05-20 23:02:33 -04:00
Custom keybinds, Default language per Library, and bugfixes (#4162)
Co-authored-by: Joseph Milazzo <josephmajora@gmail.com>
This commit is contained in:
@@ -1,13 +1,48 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl.Http;
|
||||
using Kavita.Common;
|
||||
using Kavita.Common.EnvironmentInfo;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
|
||||
namespace API.Extensions;
|
||||
#nullable enable
|
||||
|
||||
public static class FlurlExtensions
|
||||
{
|
||||
|
||||
private static readonly FileExtensionContentTypeProvider FileTypeProvider = new ();
|
||||
|
||||
/// <summary>
|
||||
/// Makes a head request to the url, and parses the first content type header to determine the content type
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<string?> GetFileFormatAsync(this string url)
|
||||
{
|
||||
var headResponse = await url.AllowHttpStatus("2xx").HeadAsync();
|
||||
|
||||
// TODO: Move to new Headers class after merge with progress branch
|
||||
var contentTypeHeader = headResponse.Headers.FirstOrDefault("Content-Type");
|
||||
if (string.IsNullOrEmpty(contentTypeHeader))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var contentType = contentTypeHeader.Split(";").FirstOrDefault();
|
||||
if (string.IsNullOrEmpty(contentType))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// The mappings have legacy mappings like .jpe => image/jpeg. We reverse to get the newer stuff first
|
||||
return FileTypeProvider.Mappings
|
||||
.Reverse()
|
||||
.FirstOrDefault(m => m.Value.Equals(contentType, StringComparison.OrdinalIgnoreCase))
|
||||
.Key?.TrimStart('.');
|
||||
}
|
||||
|
||||
public static IFlurlRequest WithKavitaPlusHeaders(this string request, string license, string? anilistToken = null)
|
||||
{
|
||||
return request
|
||||
|
||||
Reference in New Issue
Block a user