Skip to content

Commit

Permalink
Add support for PSD to display in files && fix fileListCache issue
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 11, 2024
1 parent db82e17 commit f7133f7
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum ImageFormat
gif = 14,
png = 15,
webp = 16,
psd = 17,

// Sidecar files
xmp = 30,
Expand Down Expand Up @@ -115,6 +116,11 @@ private static readonly List<string>
/// </summary>
private static readonly List<string> ExtensionWebp = new() { "webp" };

/// <summary>
/// Psd imageFormat
/// </summary>
private static readonly List<string> ExtensionPsd = new() { "psd" };

private static readonly Dictionary<ImageFormat, List<string>>
MapFileTypesToExtensionDictionary =
new()
Expand All @@ -127,7 +133,8 @@ private static readonly Dictionary<ImageFormat, List<string>>
{ ImageFormat.gpx, ExtensionGpx },
{ ImageFormat.mp4, ExtensionMp4 },
{ ImageFormat.xmp, ExtensionXmp },
{ ImageFormat.webp, ExtensionWebp }
{ ImageFormat.webp, ExtensionWebp },
{ ImageFormat.psd, ExtensionPsd }
};

/// <summary>
Expand All @@ -149,6 +156,7 @@ public static List<string> ExtensionSyncSupportedList
extensionList.AddRange(ExtensionXmp);
extensionList.AddRange(ExtensionJsonSidecar);
extensionList.AddRange(ExtensionWebp);
extensionList.AddRange(ExtensionPsd);
return extensionList;
}
}
Expand All @@ -168,6 +176,7 @@ private static List<string> ExtensionExifToolSupportedList
extensionList.AddRange(ExtensionPng);
extensionList.AddRange(ExtensionMp4);
extensionList.AddRange(ExtensionWebp);
extensionList.AddRange(ExtensionPsd);
return extensionList;
}
}
Expand Down Expand Up @@ -540,9 +549,26 @@ public static ImageFormat GetImageFormat(byte[] bytes)
return ImageFormat.webp;
}

if ( GetImageFormatPsd(bytes) != null )
{
return ImageFormat.psd;
}

return ImageFormat.unknown;
}

private static ImageFormat? GetImageFormatPsd(byte[] bytes)
{
// HEX 38 42 50 53
var psd = new byte[] { 56, 66, 80, 83 };
if ( psd.SequenceEqual(bytes.Take(psd.Length)) )
{
return ImageFormat.psd;
}

return null;
}

private static ImageFormat? GetImageFormatMetaWebp(byte[] bytes)
{
var webpFirstPart = new byte[] { 82, 73, 70, 70 };
Expand Down
2 changes: 1 addition & 1 deletion starsky/starsky/clientapp/src/hooks/use-filelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const fetchUseFileListContentCache = async (
const content = new FileListCache().CacheGet(locationSearch);
if (content) {
console.log(
` -- Fetch Content ${new Date(content.dateCache).toLocaleTimeString()} ${locationSearch} -- `
` -- Cache Content ${new Date(content.dateCache).toLocaleTimeString()} ${locationSearch} -- `
);
setPageTypeHelper(content);
} else {
Expand Down
1 change: 1 addition & 0 deletions starsky/starsky/clientapp/src/interfaces/IFileIndexItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum ImageFormat {
gif = "gif",
png = "png",
webp = "webp",
psd = "psd",
xmp = "xmp",
meta_json = "meta_json",
gpx = "gpx",
Expand Down
2 changes: 1 addition & 1 deletion starsky/starsky/clientapp/src/shared/filelist-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class FileListCache {
}
}
if (urlObject.collections) {
if (item?.fileName.startsWith(detailview.fileIndexItem.fileCollectionName)) {
if (item?.fileCollectionName === detailview.fileIndexItem.fileCollectionName) {
parentItem.fileIndexItems[index] = detailview.fileIndexItem;
}
}
Expand Down
12 changes: 7 additions & 5 deletions starsky/starsky/clientapp/src/style/css/21-archive-folder.css
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,6 @@ between 1 and 2 items
background-image: url("../images/baseline-file-jpg-24px.svg");
}

.list-image-box > .box-content.isDirectory-false > .img-box--webp {
background-image: url("../images/baseline-file-outline.svg");
}

.list-image-box > .box-content.isDirectory-false > .img-box--xmp {
background-image: url("../images/baseline-file-xmp-24px.svg");
}
Expand All @@ -322,6 +318,11 @@ between 1 and 2 items
background-image: url("../images/baseline-file-png-24px.svg");
}

.list-image-box > .box-content.isDirectory-false > .img-box--psd,
.list-image-box > .box-content.isDirectory-false > .img-box--webp {
background-image: url("../images/baseline-file-outline.svg");
}

@media (prefers-color-scheme: dark) {
.list-image-box > .box-content.isDirectory-false > .img-box--error,
.list-image-box > .box-content.isDirectory-false > .img-box--gpx,
Expand All @@ -330,7 +331,8 @@ between 1 and 2 items
.list-image-box > .box-content.isDirectory-false > .img-box--jpg,
.list-image-box > .box-content.isDirectory-false > .img-box--bmp,
.list-image-box > .box-content.isDirectory-false > .img-box--png,
.list-image-box > .box-content.isDirectory-false > .img-box--webp {
.list-image-box > .box-content.isDirectory-false > .img-box--webp,
.list-image-box > .box-content.isDirectory-false > .img-box--psd {
filter: invert(100%);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Immutable;
using System.IO;
using System.Reflection;
using starsky.foundation.storage.Storage;
using starskytest.FakeMocks;

namespace starskytest.FakeCreateAn.CreateAnImagePsd;

public class CreateAnImagePsd
{
public readonly ImmutableArray<byte> Bytes = [..Array.Empty<byte>()];

public CreateAnImagePsd()
{
var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if ( string.IsNullOrEmpty(dirName) )
{
return;
}

var path = Path.Combine(dirName, "FakeCreateAn",
"CreateAnImagePsd", "test.psd");

Bytes = [..StreamToBytes(path)];
}

private static byte[] StreamToBytes(string path)
{
var input = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(path);
using var ms = new MemoryStream();
input.CopyTo(ms);
input.Dispose();
return ms.ToArray();
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using starsky.foundation.platform.Helpers;
using starskytest.FakeCreateAn;
using starskytest.FakeCreateAn.CreateAnImageCorrupt;
using starskytest.FakeCreateAn.CreateAnImagePsd;
using starskytest.FakeCreateAn.CreateAnImageWebP;

namespace starskytest.starsky.foundation.platform.Helpers;
Expand Down Expand Up @@ -511,7 +512,7 @@ public void Gpx_CreateAnGpx()
}

[TestMethod]
public void Gpx_CreateAnWebP()
public void WebP_CreateAnWebP()
{
var createAnImage = new CreateAnImageWebP().Bytes.ToArray();
var result = ExtensionRolesHelper.GetImageFormat(createAnImage);
Expand All @@ -538,6 +539,23 @@ public void UnknownFileFormat_Hex(string hexValue)
Assert.AreEqual(ExtensionRolesHelper.ImageFormat.unknown, fileType);
}

[TestMethod]
public void Psd_CreateAnPsd()
{
var createAnImage = new CreateAnImagePsd().Bytes.ToArray();
var result = ExtensionRolesHelper.GetImageFormat(createAnImage);
Assert.AreEqual(ExtensionRolesHelper.ImageFormat.psd, result);
}

[TestMethod]
public void Files_GetImageFormat_PsdHex()
{
var fileType = ExtensionRolesHelper.GetImageFormat(
ExtensionRolesHelper.HexStringToByteArray(
"38 42 50 53".Replace(" ", "")));
Assert.AreEqual(ExtensionRolesHelper.ImageFormat.psd, fileType);
}

[TestMethod]
public void StringToByteArrayTest()
{
Expand Down
12 changes: 8 additions & 4 deletions starsky/starskytest/starskytest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1"/>
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="MSTest.TestAdapter" Version="3.6.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.2"/>
<PackageReference Include="MSTest.TestFramework" Version="3.6.2"/>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down Expand Up @@ -143,9 +143,13 @@
<Content Include="FakeCreateAn\CreateAnImageLongDescriptionTitle\CreateAnImageLongDescriptionTitle.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="FakeCreateAn\CreateAnImageWebP\test.webp" />
<None Remove="FakeCreateAn\CreateAnImageWebP\test.webp"/>
<Content Include="FakeCreateAn\CreateAnImageWebP\test.webp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="FakeCreateAn\CreateAnImagePsd\test.psd"/>
<Content Include="FakeCreateAn\CreateAnImagePsd\test.psd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

Expand Down

0 comments on commit f7133f7

Please sign in to comment.