Skip to content

Commit

Permalink
#1813 add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 11, 2024
1 parent 2c50aea commit f1d78e7
Show file tree
Hide file tree
Showing 7 changed files with 626 additions and 520 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace starsky.foundation.platform.Helpers;
public static partial class ExtensionRolesHelper
{
/// <summary>
/// ImageFormat based on first bytes
/// ImageFormat based on first bytes, so read first bytes
/// </summary>
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum ImageFormat
Expand Down Expand Up @@ -111,11 +111,10 @@ private static readonly List<string>
private static readonly List<string> ExtensionMp4 = new() { "mp4", "mov" };

/// <summary>
/// WebP imageFormat
/// WebP imageFormat
/// </summary>
private static readonly List<string> ExtensionWebp = new() { "webp" };


private static readonly Dictionary<ImageFormat, List<string>>
MapFileTypesToExtensionDictionary =
new()
Expand Down Expand Up @@ -149,6 +148,7 @@ public static List<string> ExtensionSyncSupportedList
extensionList.AddRange(ExtensionMp4);
extensionList.AddRange(ExtensionXmp);
extensionList.AddRange(ExtensionJsonSidecar);
extensionList.AddRange(ExtensionWebp);
return extensionList;
}
}
Expand All @@ -167,6 +167,7 @@ private static List<string> ExtensionExifToolSupportedList
extensionList.AddRange(ExtensionGif);
extensionList.AddRange(ExtensionPng);
extensionList.AddRange(ExtensionMp4);
extensionList.AddRange(ExtensionWebp);
return extensionList;
}
}
Expand All @@ -188,6 +189,7 @@ public static List<string> ExtensionThumbSupportedList
extensionList.AddRange(ExtensionBmp);
extensionList.AddRange(ExtensionGif);
extensionList.AddRange(ExtensionPng);
extensionList.AddRange(ExtensionWebp);
return extensionList;
}
}
Expand Down Expand Up @@ -449,7 +451,7 @@ private static byte[] ReadBuffer(Stream stream, int size)

/// <summary>
/// Get the format of the image by looking the first bytes
/// Stream is Flushed / Disposed afterwards
/// Stream is Flushed / Disposed afterward
/// </summary>
/// <param name="stream">stream</param>
/// <returns>ImageFormat enum</returns>
Expand Down Expand Up @@ -533,9 +535,30 @@ public static ImageFormat GetImageFormat(byte[] bytes)
return ImageFormat.meta_json;
}

if ( GetImageFormatMetaWebp(bytes) != null )
{
return ImageFormat.webp;
}

return ImageFormat.unknown;
}

private static ImageFormat? GetImageFormatMetaWebp(byte[] bytes)
{
var webpFirstPart = new byte[] { 82, 73, 70, 70 };
var webpSecondPart = new byte[] { 87, 69, 66, 80 };

var isFirstPart = webpFirstPart.SequenceEqual(bytes.Take(webpFirstPart.Length));
var isSecondPart = webpSecondPart.SequenceEqual(bytes.Skip(8).Take(webpSecondPart.Length));

if ( isFirstPart && isSecondPart )
{
return ImageFormat.webp;
}

return null;
}

private static ImageFormat? GetImageFormatMetaJson(byte[] bytes)
{
var metaJsonUnix = new byte[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ private static ExtensionRolesHelper.ImageFormat GetFileSpecificTags(
return ExtensionRolesHelper.ImageFormat.gif;
}

if ( allExifItems.Exists(p => p.Name == "WebP") )
{
return ExtensionRolesHelper.ImageFormat.webp;
}

return ExtensionRolesHelper.ImageFormat.unknown;
}

Expand Down Expand Up @@ -565,13 +570,13 @@ private static string GetXmpData(Directory? exifItem, string propertyPath)
if ( !string.IsNullOrEmpty(xmpTitle) )
{
return xmpTitle;
}
}

var iptcDirectory = allExifItems.OfType<IptcDirectory>().FirstOrDefault();
var iptcObjectName = iptcDirectory?.Tags.FirstOrDefault(
p => p.Name == "Object Name")?.Description;
iptcObjectName ??= string.Empty;

return iptcObjectName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const ListImage: React.FunctionComponent<IListImageProps> = memo((props) => {
props.imageFormat !== ImageFormat.bmp &&
props.imageFormat !== ImageFormat.gif &&
props.imageFormat !== ImageFormat.jpg &&
props.imageFormat !== ImageFormat.webp &&
props.imageFormat !== ImageFormat.png
) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import FormControl from "../../atoms/form-control/form-control";
import SwitchButton from "../../atoms/switch-button/switch-button";

const defaultEditorApplication = {
imageFormats: [ImageFormat.jpg, ImageFormat.png, ImageFormat.bmp, ImageFormat.tiff]
imageFormats: [
ImageFormat.jpg,
ImageFormat.png,
ImageFormat.bmp,
ImageFormat.tiff,
ImageFormat.webp
]
} as IAppSettingsDefaultEditorApplication;

export async function UpdateDefaultEditorPhotos(
Expand Down
2 changes: 1 addition & 1 deletion starsky/starsky/clientapp/src/interfaces/IFileIndexItem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IExifStatus} from "./IExifStatus";
import { IExifStatus } from "./IExifStatus";

export interface IFileIndexItem {
lastEdited?: string;
Expand Down
Loading

0 comments on commit f1d78e7

Please sign in to comment.